From 1fadc6c31e2cae42f8674b78335c8a20feb13f9b Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 13 May 2023 09:43:26 +0200 Subject: [PATCH] Hotfix for possible crash --- app/ASUSWmi.cs | 6 ++---- app/Fans.cs | 10 ++++++---- app/Settings.cs | 8 +++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/ASUSWmi.cs b/app/ASUSWmi.cs index b1a9bc61..ddb6e883 100644 --- a/app/ASUSWmi.cs +++ b/app/ASUSWmi.cs @@ -242,10 +242,8 @@ public class ASUSWmi int result; - for (int i = 8; i < curve.Length; i++) - { - curve[i] = Math.Max((byte)0, Math.Min((byte)99, curve[i])); // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100% - } + //for (int i = 8; i < curve.Length; i++) + // curve[i] = Math.Max((byte)0, Math.Min((byte)99, curve[i])); // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100% switch (device) { diff --git a/app/Fans.cs b/app/Fans.cs index 8a0be594..dc55fefc 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -15,6 +15,8 @@ namespace GHelper static int MinRPM, MaxRPM; + const int fansMax = 100; + NvidiaGpuControl? nvControl = null; public Fans() @@ -241,7 +243,7 @@ namespace GHelper chart.ChartAreas[0].AxisX.Interval = 10; chart.ChartAreas[0].AxisY.Minimum = 0; - chart.ChartAreas[0].AxisY.Maximum = 100; + chart.ChartAreas[0].AxisY.Maximum = fansMax; chart.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 7F); @@ -250,10 +252,10 @@ namespace GHelper chart.ChartAreas[0].AxisX.LineColor = chartGrid; chart.ChartAreas[0].AxisY.LineColor = chartGrid; - for (int i = 0; i <= 90; i += 10) + for (int i = 0; i <= fansMax-10; i += 10) chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartPercToRPM(i)); - chart.ChartAreas[0].AxisY.CustomLabels.Add(98, 102, Properties.Strings.RPM); + chart.ChartAreas[0].AxisY.CustomLabels.Add(fansMax-2, fansMax+2, Properties.Strings.RPM); chart.ChartAreas[0].AxisY.Interval = 10; @@ -577,7 +579,7 @@ namespace GHelper if (dx > 100) dx = 100; if (dy < 0) dy = 0; - if (dy > 100) dy = 100; + if (dy > fansMax) dy = fansMax; dymin = (dx - 65) * 1.2; diff --git a/app/Settings.cs b/app/Settings.cs index 07bf3f31..1b0a0653 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1692,7 +1692,13 @@ namespace GHelper sliderBattery.Value = limit; Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit, "BatteryLimit"); - OptimizationService.SetChargeLimit(limit); + try + { + OptimizationService.SetChargeLimit(limit); + } catch (Exception ex) + { + Debug.WriteLine(ex); + } Program.config.setConfig("charge_limit", limit);