Skip to content

Commit 8f1b120

Browse files
committed
Aura Battery level mode #4827
1 parent 218b5f5 commit 8f1b120

File tree

3 files changed

+71
-20
lines changed

3 files changed

+71
-20
lines changed

app/AnimeMatrix/SlashDevice.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,6 @@ public void SetMode(SlashMode mode)
154154
Set(CreatePacket([0xD3, 0x04, 0x00, 0x0C, 0x01, modeByte, 0x02, 0x42, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13]), "SlashMode");
155155
}
156156

157-
public static double GetBatteryChargePercentage()
158-
{
159-
double batteryCharge = 0;
160-
try
161-
{
162-
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");
163-
foreach (ManagementObject battery in searcher.Get())
164-
{
165-
batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]);
166-
break; // Assuming only one battery
167-
}
168-
}
169-
catch (ManagementException e)
170-
{
171-
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
172-
}
173-
return batteryCharge;
174-
}
175-
176157
private byte[] GetPercentagePattern(int brightness, double percentage)
177158
{
178159
// because 7 segments, within each led segment represents a percentage bracket of (100/7 = 14.2857%)
@@ -195,7 +176,7 @@ private byte[] GetPercentagePattern(int brightness, double percentage)
195176

196177
public void SetBatteryPattern(int brightness)
197178
{
198-
SetCustom(GetPercentagePattern(brightness, 100 * (GetBatteryChargePercentage() / AppConfig.Get("charge_limit", 100))), null);
179+
SetCustom(GetPercentagePattern(brightness, 100 * (HardwareControl.GetBatteryChargePercentage() / AppConfig.Get("charge_limit", 100))), null);
199180
}
200181

201182
public void SetEmpty()

app/HardwareControl.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,25 @@ public static void ReadSensors(bool log = false)
278278
}
279279
}
280280

281+
public static double GetBatteryChargePercentage()
282+
{
283+
double batteryCharge = 0;
284+
try
285+
{
286+
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");
287+
foreach (ManagementObject battery in searcher.Get())
288+
{
289+
batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]);
290+
break; // Assuming only one battery
291+
}
292+
}
293+
catch (ManagementException e)
294+
{
295+
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
296+
}
297+
return batteryCharge;
298+
}
299+
281300
public static bool IsUsedGPU(int threshold = 10)
282301
{
283302
if (GetGpuUse() > threshold)

app/USB/Aura.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum AuraMode : int
5353
HEATMAP = 20,
5454
GPUMODE = 21,
5555
AMBIENT = 22,
56+
BATTERY = 23,
5657
}
5758

5859
public enum AuraSpeed : int
@@ -107,6 +108,7 @@ public static class Aura
107108
{ AuraMode.HEATMAP, "Heatmap"},
108109
{ AuraMode.GPUMODE, "GPU Mode" },
109110
{ AuraMode.AMBIENT, "Ambient"},
111+
{ AuraMode.BATTERY, "Battery"},
110112
};
111113

112114
private static Dictionary<AuraMode, string> _modesDynamicLighting = new Dictionary<AuraMode, string>
@@ -124,6 +126,7 @@ public static class Aura
124126
{ AuraMode.AuraColorCycle, Properties.Strings.AuraColorCycle },
125127
{ AuraMode.AuraRainbow, Properties.Strings.AuraRainbow },
126128
{ AuraMode.AuraStrobe, Properties.Strings.AuraStrobe },
129+
{ AuraMode.BATTERY, "Battery"},
127130
};
128131

129132
private static Dictionary<AuraMode, string> _modesStrix = new Dictionary<AuraMode, string>
@@ -142,6 +145,7 @@ public static class Aura
142145
{ AuraMode.Flash, "Flash" },
143146
{ AuraMode.HEATMAP, "Heatmap"},
144147
{ AuraMode.AMBIENT, "Ambient"},
148+
{ AuraMode.BATTERY, "Battery"},
145149
};
146150

147151
static Aura()
@@ -248,6 +252,10 @@ private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs
248252
{
249253
CustomRGB.ApplyHeatmap();
250254
}
255+
else if (Mode == AuraMode.BATTERY)
256+
{
257+
CustomRGB.ApplyBattery();
258+
}
251259
else if (Mode == AuraMode.AMBIENT)
252260
{
253261
CustomRGB.ApplyAmbient();
@@ -697,6 +705,14 @@ public static void ApplyAura(double colorDim = 1)
697705
return;
698706
}
699707

708+
if (Mode == AuraMode.BATTERY)
709+
{
710+
CustomRGB.ApplyBattery(true);
711+
timer.Enabled = true;
712+
timer.Interval = 30000;
713+
return;
714+
}
715+
700716
if (Mode == AuraMode.AMBIENT)
701717
{
702718
CustomRGB.ApplyAmbient(true);
@@ -770,6 +786,14 @@ public static class CustomRGB
770786
static Color colorWarm = ColorTranslator.FromHtml(AppConfig.GetString("color_warm", "#FFFF00"));
771787
static Color colorHot = ColorTranslator.FromHtml(AppConfig.GetString("color_hot", "#FF0000"));
772788

789+
static float battLow = 20f;
790+
static float battMid = 60f;
791+
static float battHigh = 100f;
792+
793+
static Color colorLow = Color.Red;
794+
static Color colorMid = Color.Yellow;
795+
static Color colorHigh = Color.Lime;
796+
773797
static Color colorUltimate = ColorTranslator.FromHtml(AppConfig.GetString("color_ultimate", "#FF0000"));
774798
static Color colorStandard = ColorTranslator.FromHtml(AppConfig.GetString("color_standard", "#FFFF00"));
775799
static Color colorEco = ColorTranslator.FromHtml(AppConfig.GetString("color_eco", "#008000"));
@@ -812,7 +836,34 @@ public static void ApplyHeatmap(bool init = false)
812836
ApplyDirect(color, init);
813837
}
814838

839+
public static void ApplyBattery(bool init = false)
840+
{
841+
float battery = (float)HardwareControl.GetBatteryChargePercentage();
842+
Color color = colorLow;
843+
844+
if (battery < battLow)
845+
{
846+
color = colorLow;
847+
}
848+
else if (battery < battMid)
849+
{
850+
// Low → Mid
851+
float t = (battery - battLow) / (battMid - battLow);
852+
color = ColorUtils.GetWeightedAverage(colorLow, colorMid, t);
853+
}
854+
else if (battery < battHigh)
855+
{
856+
// Mid → High
857+
float t = (battery - battMid) / (battHigh - battMid);
858+
color = ColorUtils.GetWeightedAverage(colorMid, colorHigh, t);
859+
}
860+
else
861+
{
862+
color = colorHigh;
863+
}
815864

865+
ApplyDirect(color, init);
866+
}
816867

817868
public static void ApplyAmbient(bool init = false)
818869
{

0 commit comments

Comments
 (0)