From aa74730e127d2edd821934982884bb972b966cbc Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:06:15 +0200 Subject: [PATCH] Toggle between % and Wh for battery charge https://github.com/seerge/g-helper/issues/3246 --- app/HardwareControl.cs | 23 ++++++++++++++++++++++- app/Settings.cs | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index f0d450b7..c5640711 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -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 @@ -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) + "%"; + } } diff --git a/app/Settings.cs b/app/Settings.cs index 229fe529..2a93d067 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -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; @@ -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);