From dedb2123f0e4f82aedddb590cd944d49df7c07cb Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:08:13 +0100 Subject: [PATCH] Battery Discharge reader --- app/AsusACPI.cs | 20 ++++++++++++++++++++ app/Gpu/NVidia/NvidiaGpuControl.cs | 8 ++++---- app/HardwareControl.cs | 19 +++++++++++++------ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index d281c7f4..b1b638b4 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -58,6 +58,8 @@ public class AsusACPI public const uint GPU_Fan = 0x00110014; public const uint Mid_Fan = 0x00110031; + public const uint BatteryDischarge = 0x0012005A; + public const uint PerformanceMode = 0x00120075; // Performance modes public const uint VivoBookMode = 0x00110019; // Vivobook performance modes @@ -372,6 +374,23 @@ public class AsusACPI return CallMethod(DSTS, args); } + + public decimal? GetBatteryDischarge() + { + var buffer = DeviceGetBuffer(BatteryDischarge); + + if (buffer[2] > 0) + { + buffer[2] = 0; + return (decimal)BitConverter.ToInt16(buffer, 0) / 100; + } + else + { + return null; + } + + + } public int SetGPUEco(int eco) { int ecoFlag = DeviceGet(GPUEco); @@ -412,6 +431,7 @@ public class AsusACPI return fan; } + public int SetFanRange(AsusFan device, byte[] curve) { diff --git a/app/Gpu/NVidia/NvidiaGpuControl.cs b/app/Gpu/NVidia/NvidiaGpuControl.cs index 08e3e88e..878d9a7a 100644 --- a/app/Gpu/NVidia/NvidiaGpuControl.cs +++ b/app/Gpu/NVidia/NvidiaGpuControl.cs @@ -180,10 +180,10 @@ public class NvidiaGpuControl : IGpuControl if (core < MinCoreOffset || core > MaxCoreOffset) return 0; if (memory < MinMemoryOffset || memory > MaxMemoryOffset) return 0; - if (GetClocks(out int currentCore, out int currentMemory)) - { - if (Math.Abs(core - currentCore) < 5 && Math.Abs(memory - currentMemory) < 5) return 0; - } + GetClocks(out int currentCore, out int currentMemory); + + // Nothing to set + if (Math.Abs(core - currentCore) < 5 && Math.Abs(memory - currentMemory) < 5) return 0; PhysicalGPU internalGpu = _internalGpu!; diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 86c1c462..e707e9cb 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -1,13 +1,12 @@ using GHelper; +using GHelper.Battery; using GHelper.Fan; using GHelper.Gpu; -using GHelper.Gpu.NVidia; using GHelper.Gpu.AMD; - +using GHelper.Gpu.NVidia; using GHelper.Helpers; using System.Diagnostics; using System.Management; -using GHelper.Battery; public static class HardwareControl { @@ -68,9 +67,16 @@ public static class HardwareControl chargeCapacity = Convert.ToDecimal(obj["RemainingCapacity"]); + decimal? discharge = Program.acpi.GetBatteryDischarge(); + if (discharge is not null) + { + batteryRate = discharge; + return; + } + decimal chargeRate = Convert.ToDecimal(obj["ChargeRate"]); decimal dischargeRate = Convert.ToDecimal(obj["DischargeRate"]); - + if (chargeRate > 0) batteryRate = chargeRate / 1000; else @@ -155,7 +161,8 @@ public static class HardwareControl return health; } - public static float? GetCPUTemp() { + public static float? GetCPUTemp() + { var last = DateTimeOffset.Now.ToUnixTimeSeconds(); if (Math.Abs(last - lastUpdate) < 2) return cpuTemp; @@ -255,7 +262,7 @@ public static class HardwareControl GpuControl?.Dispose(); IGpuControl _gpuControl = new NvidiaGpuControl(); - + if (_gpuControl.IsValid) { GpuControl = _gpuControl;