diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 2f95adb4..2f33845a 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -96,8 +96,15 @@ public static class AppConfig public static int Get(string name, int empty = -1) { if (config.ContainsKey(name)) + { + //Debug.WriteLine(name); return int.Parse(config[name].ToString()); - else return empty; + } + else + { + //Debug.WriteLine(name + "E"); + return empty; + } } public static bool Is(string name) diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 29539fd2..d1ce3155 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -1,6 +1,5 @@ using GHelper.Helpers; using HidLibrary; -using System.Drawing; using System.Text; namespace GHelper @@ -457,7 +456,7 @@ namespace GHelper } //Logger.WriteLine(BitConverter.ToString(msg)); - if (init) auraDevice.Write(new byte[] { AURA_HID_ID ,0xbc}); + if (init) auraDevice.Write(new byte[] { AURA_HID_ID, 0xbc }); auraDevice.Write(msg); } diff --git a/app/Fans.cs b/app/Fans.cs index 51ea7c30..b29c79f4 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -59,7 +59,7 @@ namespace GHelper InitTheme(true); MinRPM = 18; - MaxRPM = HardwareControl.GetFanMax(); + MaxRPM = HardwareControl.fanMax; labelTip.Visible = false; labelTip.BackColor = Color.Transparent; diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 4d25b365..27bbaf0c 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -9,6 +9,10 @@ using System.Management; public static class HardwareControl { + + const int DEFAULT_FAN_MAX = 58; + const int INADEQUATE_MAX = 80; + public static IGpuControl? GpuControl; public static float? cpuTemp = -1; @@ -26,21 +30,48 @@ public static class HardwareControl static long lastUpdate; - public static int GetFanMax() - { - int max = 58; - int configMax = AppConfig.Get("fan_max"); - if (configMax > 80) configMax = 0; // skipping inadvequate settings + static int _fanMax = DEFAULT_FAN_MAX; + static bool _fanRpm = false; - if (AppConfig.ContainsModel("401")) max = 72; - else if (AppConfig.ContainsModel("503")) max = 68; - return Math.Max(max, configMax); + public static int fanMax + { + get + { + return _fanMax; + } + set + { + AppConfig.Set("fan_max", value); + _fanMax = value; + } } - public static void SetFanMax(int fan) + public static bool fanRpm { - AppConfig.Set("fan_max", fan); + get + { + return _fanRpm; + } + set + { + AppConfig.Set("fan_rpm", value ? 1 : 0); + _fanRpm = value; + } } + + static HardwareControl() + { + _fanMax = AppConfig.Get("fan_max"); + if (_fanMax > INADEQUATE_MAX) _fanMax = -1; // skipping inadvequate settings + + if (_fanMax < 0 && AppConfig.ContainsModel("401")) _fanMax = 72; + if (_fanMax < 0 && AppConfig.ContainsModel("503")) _fanMax = 68; + if (_fanMax < 0) _fanMax = DEFAULT_FAN_MAX; + + _fanRpm = AppConfig.Is("fan_rpm"); + + } + public static string FormatFan(int fan) { // fix for old models @@ -50,10 +81,9 @@ public static class HardwareControl if (fan <= 0 || fan > 100) return null; //nothing reasonable } - int fanMax = GetFanMax(); - if (fan > fanMax && fan < 80) SetFanMax(fan); + if (fan > fanMax && fan <= INADEQUATE_MAX) fanMax = fan; - if (AppConfig.Is("fan_rpm")) + if (fanRpm) return GHelper.Properties.Strings.FanSpeed + ": " + (fan * 100).ToString() + "RPM"; else return GHelper.Properties.Strings.FanSpeed + ": " + Math.Min(Math.Round((float)fan / fanMax * 100), 100).ToString() + "%"; // relatively to 6000 rpm diff --git a/app/Settings.cs b/app/Settings.cs index f46d6999..d8fd0f0e 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -525,7 +525,7 @@ namespace GHelper private void LabelCPUFan_Click(object? sender, EventArgs e) { - AppConfig.Set("fan_rpm", (AppConfig.Get("fan_rpm") == 1) ? 0 : 1); + HardwareControl.fanRpm = !HardwareControl.fanRpm; RefreshSensors(true); }