Skip to content

Commit

Permalink
Toggle between % and Wh for battery charge #3246
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Oct 11, 2024
1 parent 9b5e2ac commit aa74730
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/HardwareControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public static class HardwareControl

static long lastUpdate;

static bool _chargeWatt = AppConfig.Is("charge_watt");
public static bool chargeWatt
{
get
{
return _chargeWatt;
}
set
{
AppConfig.Set("charge_watt", value ? 1 : 0);
_chargeWatt = value;
}
}

private static int GetGpuUse()
{
try
Expand Down Expand Up @@ -227,8 +241,15 @@ public static void ReadSensors()
if (fullCapacity > 0 && chargeCapacity > 0)
{
batteryCapacity = Math.Min(100, (decimal)chargeCapacity / (decimal)fullCapacity * 100);
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh" + " " + Math.Round(batteryCapacity, 1) + "%";
if (batteryCapacity > 99) BatteryControl.UnSetBatteryLimitFull();
if (chargeWatt)
{
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh";
}
else
{
batteryCharge = Math.Round(batteryCapacity, 1) + "%";
}
}


Expand Down
7 changes: 7 additions & 0 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public SettingsForm()

labelCharge.MouseEnter += PanelBattery_MouseEnter;
labelCharge.MouseLeave += PanelBattery_MouseLeave;
labelBattery.Click += LabelBattery_Click;

buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
Expand Down Expand Up @@ -284,6 +285,12 @@ public SettingsForm()
InitVisual();
}

private void LabelBattery_Click(object? sender, EventArgs e)
{
HardwareControl.chargeWatt = !HardwareControl.chargeWatt;
RefreshSensors(true);
}

private void ButtonDonate_Click(object? sender, EventArgs e)
{
AppConfig.Set("donate_click", 1);
Expand Down

0 comments on commit aa74730

Please sign in to comment.