From 63092d8415970e04773aafddfefc420efe26c11d Mon Sep 17 00:00:00 2001 From: seerge Date: Wed, 29 Mar 2023 23:32:12 +0200 Subject: [PATCH] Removed unsupported aura modes for some models --- app/Aura.cs | 20 ++++++++++++++++--- app/GHelper.csproj | 2 +- app/HardwareMonitor.cs | 45 ++++++++++++++++++++---------------------- app/Program.cs | 5 +---- app/Settings.cs | 4 ++-- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/app/Aura.cs b/app/Aura.cs index b24d5c10..69e46c7b 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -71,9 +71,8 @@ namespace GHelper { 2, "Fast" } }; } - public static Dictionary GetModes() - { - return new Dictionary + + static Dictionary _modes = new Dictionary { { 0, "Static" }, { 1, "Breathe" }, @@ -81,6 +80,21 @@ namespace GHelper { 3, "Rainbow" }, { 10, "Strobe" }, }; + + public static Dictionary GetModes() + { + if (Program.config.ContainsModel("TUF")) + { + _modes.Remove(3); + } + + if (Program.config.ContainsModel("401")) + { + _modes.Remove(2); + _modes.Remove(3); + } + + return _modes; } diff --git a/app/GHelper.csproj b/app/GHelper.csproj index a4a29d1a..509b9e1b 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -16,7 +16,7 @@ x64 False True - 0.42 + 0.43 diff --git a/app/HardwareMonitor.cs b/app/HardwareMonitor.cs index 8576ce8e..8726ad23 100644 --- a/app/HardwareMonitor.cs +++ b/app/HardwareMonitor.cs @@ -31,43 +31,29 @@ public static class HardwareMonitor public static void ReadSensors() { - cpuTemp = -1; batteryDischarge = -1; cpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan)); gpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan)); midFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.Mid_Fan)); - try + cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU); + gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU); + + if (cpuTemp < 0) try { - cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU); - if (cpuTemp < 0) - { - var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true); - cpuTemp = ct.NextValue() - 273; - ct.Dispose(); - } + var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true); + cpuTemp = ct.NextValue() - 273; + ct.Dispose(); } catch { Logger.WriteLine("Failed reading CPU temp"); } - try + if (gpuTemp < 0) try { - var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true); - batteryDischarge = cb.NextValue() / 1000; - cb.Dispose(); - - } catch - { - Logger.WriteLine("Failed reading Battery discharge"); - } - - try - { - gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU); - if (gpuTemp < 0) - gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature(); + if (GpuTemperatureProvider is null) RecreateGpuTemperatureProvider(); + gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature(); } catch (Exception ex) { @@ -76,6 +62,17 @@ public static class HardwareMonitor Logger.WriteLine(ex.ToString()); } + try + { + var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true); + batteryDischarge = cb.NextValue() / 1000; + cb.Dispose(); + + } + catch + { + Logger.WriteLine("Failed reading Battery discharge"); + } } public static void RecreateGpuTemperatureProviderWithDelay() { diff --git a/app/Program.cs b/app/Program.cs index 11a1f362..9faece96 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -59,13 +59,10 @@ namespace GHelper Application.EnableVisualStyles(); - SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); - var ds = settingsForm.Handle; trayIcon.MouseClick += TrayIcon_MouseClick; - wmi.SubscribeToEvents(WatcherEventArrived); settingsForm.InitGPUMode(); @@ -75,10 +72,10 @@ namespace GHelper settingsForm.SetStartupCheck(Startup.IsScheduled()); SetAutoModes(); - HardwareMonitor.RecreateGpuTemperatureProvider(); // Subscribing for system power change events SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; + SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged; if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\')) diff --git a/app/Settings.cs b/app/Settings.cs index afa9d982..6a3aec5b 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -118,7 +118,7 @@ namespace GHelper sliderBattery.ValueChanged += SliderBattery_ValueChanged; Program.trayIcon.MouseMove += TrayIcon_MouseMove; - aTimer = new System.Timers.Timer(500); + aTimer = new System.Timers.Timer(1000); aTimer.Elapsed += OnTimedEvent; // Subscribing for monitor power on events @@ -878,7 +878,7 @@ namespace GHelper this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height; this.Activate(); - aTimer.Interval = 300; + //aTimer.Interval = 300; aTimer.Enabled = true; //RefreshSensors();