mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Fix possible exception in battery fully charged https://github.com/seerge/g-helper/issues/3317
This commit is contained in:
@@ -5,28 +5,43 @@ namespace GHelper.Battery
|
|||||||
internal class BatteryControl
|
internal class BatteryControl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static bool _chargeFull = AppConfig.Is("charge_full");
|
||||||
|
public static bool chargeFull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _chargeFull;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AppConfig.Set("charge_full", value ? 1 : 0);
|
||||||
|
_chargeFull = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ToggleBatteryLimitFull()
|
public static void ToggleBatteryLimitFull()
|
||||||
{
|
{
|
||||||
if (AppConfig.Is("charge_full")) SetBatteryChargeLimit();
|
if (chargeFull) SetBatteryChargeLimit();
|
||||||
else SetBatteryLimitFull();
|
else SetBatteryLimitFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetBatteryLimitFull()
|
public static void SetBatteryLimitFull()
|
||||||
{
|
{
|
||||||
AppConfig.Set("charge_full", 1);
|
chargeFull = true;
|
||||||
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, 100, "BatteryLimit");
|
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, 100, "BatteryLimit");
|
||||||
Program.settingsForm.VisualiseBatteryFull();
|
Program.settingsForm.VisualiseBatteryFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnSetBatteryLimitFull()
|
public static void UnSetBatteryLimitFull()
|
||||||
{
|
{
|
||||||
AppConfig.Set("charge_full", 0);
|
chargeFull = false;
|
||||||
|
Logger.WriteLine("Battery fully charged");
|
||||||
Program.settingsForm.Invoke(Program.settingsForm.VisualiseBatteryFull);
|
Program.settingsForm.Invoke(Program.settingsForm.VisualiseBatteryFull);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AutoBattery(bool init = false)
|
public static void AutoBattery(bool init = false)
|
||||||
{
|
{
|
||||||
if (AppConfig.Is("charge_full") && !init) SetBatteryLimitFull();
|
if (chargeFull && !init) SetBatteryLimitFull();
|
||||||
else SetBatteryChargeLimit();
|
else SetBatteryChargeLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +61,7 @@ namespace GHelper.Battery
|
|||||||
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "BatteryLimit");
|
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "BatteryLimit");
|
||||||
|
|
||||||
AppConfig.Set("charge_limit", limit);
|
AppConfig.Set("charge_limit", limit);
|
||||||
AppConfig.Set("charge_full", 0);
|
chargeFull = false;
|
||||||
|
|
||||||
Program.settingsForm.VisualiseBattery(limit);
|
Program.settingsForm.VisualiseBattery(limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ public static class HardwareControl
|
|||||||
if (fullCapacity > 0 && chargeCapacity > 0)
|
if (fullCapacity > 0 && chargeCapacity > 0)
|
||||||
{
|
{
|
||||||
batteryCapacity = Math.Min(100, (decimal)chargeCapacity / (decimal)fullCapacity * 100);
|
batteryCapacity = Math.Min(100, (decimal)chargeCapacity / (decimal)fullCapacity * 100);
|
||||||
if (batteryCapacity > 99) BatteryControl.UnSetBatteryLimitFull();
|
if (batteryCapacity > 99 && BatteryControl.chargeFull) BatteryControl.UnSetBatteryLimitFull();
|
||||||
if (chargeWatt)
|
if (chargeWatt)
|
||||||
{
|
{
|
||||||
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh";
|
batteryCharge = Math.Round((decimal)chargeCapacity / 1000, 1).ToString() + "Wh";
|
||||||
@@ -251,8 +251,6 @@ public static class HardwareControl
|
|||||||
batteryCharge = Math.Round(batteryCapacity, 1) + "%";
|
batteryCharge = Math.Round(batteryCapacity, 1) + "%";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsUsedGPU(int threshold = 10)
|
public static bool IsUsedGPU(int threshold = 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user