From 04afbea26ff119fe56595f658631f49754f542fd Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 6 Oct 2024 12:03:42 +0200 Subject: [PATCH] Restrict fan curve points --- app/AsusACPI.cs | 41 +++++++++-------------------------------- app/Fans.cs | 18 ++++++------------ 2 files changed, 15 insertions(+), 44 deletions(-) diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index 8a52e686..a62f8f43 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -583,7 +583,7 @@ public class AsusACPI } //Logger.WriteLine($"GetFan {device} :" + BitConverter.ToString(result)); - + if (IsInvalidCurve(result)) result = AppConfig.GetDefaultCurve(device); return result; } @@ -598,43 +598,20 @@ public class AsusACPI return curve.All(singleByte => singleByte == 0); } + public static int FixTemp(int temp, int index) + { + var dxMin = 30 + 10 * index; + var dxMax = dxMin + 9; + return Math.Min(dxMax, Math.Max(dxMin, temp)); + } + public static byte[] FixFanCurve(byte[] curve) { if (curve.Length != 16) throw new Exception("Incorrect curve"); - var points = new Dictionary(); - byte old = 0; - for (int i = 0; i < 8; i++) { - if (curve[i] <= old) curve[i] = (byte)Math.Min(100, old + 6); // preventing 2 points in same spot from default asus profiles - points[curve[i]] = curve[i + 8]; - old = curve[i]; - } - - var pointsFixed = new Dictionary(); - bool fix = false; - - int count = 0; - foreach (var pair in points.OrderBy(x => x.Key)) - { - if (count == 0 && pair.Key >= 40) - { - fix = true; - pointsFixed.Add(30, 0); - } - - if (count != 3 || !fix) - pointsFixed.Add(pair.Key, pair.Value); - count++; - } - - count = 0; - foreach (var pair in pointsFixed.OrderBy(x => x.Key)) - { - curve[count] = pair.Key; - curve[count + 8] = pair.Value; - count++; + curve[i] = (byte)FixTemp(curve[i], i); } return curve; diff --git a/app/Fans.cs b/app/Fans.cs index caf1bb5a..12bd5d2f 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -757,8 +757,8 @@ namespace GHelper chart.Titles[0].Text = title; - chart.ChartAreas[0].AxisX.Minimum = 10; - chart.ChartAreas[0].AxisX.Maximum = 100; + chart.ChartAreas[0].AxisX.Minimum = 20; + chart.ChartAreas[0].AxisX.Maximum = 110; chart.ChartAreas[0].AxisX.Interval = 10; chart.ChartAreas[0].AxisY.Minimum = 0; @@ -1019,7 +1019,7 @@ namespace GHelper int chartCount = 2; // Middle / system fan check - if (!AsusACPI.IsEmptyCurve(Program.acpi.GetFanCurve(AsusFan.Mid)) || Program.acpi.GetFan(AsusFan.Mid) >= 0) + if (Program.acpi.GetFan(AsusFan.Mid) >= 0) { AppConfig.Set("mid_fan", 1); chartCount++; @@ -1082,15 +1082,10 @@ namespace GHelper if (reset || AsusACPI.IsInvalidCurve(curve)) { curve = Program.acpi.GetFanCurve(device, Modes.GetCurrentBase()); - - if (AsusACPI.IsInvalidCurve(curve)) - curve = AppConfig.GetDefaultCurve(device); - - curve = AsusACPI.FixFanCurve(curve); - + Logger.WriteLine($"Default {device}:" + BitConverter.ToString(curve)); } - //Debug.WriteLine(BitConverter.ToString(curve)); + curve = AsusACPI.FixFanCurve(curve); byte old = 0; for (int i = 0; i < 8; i++) @@ -1245,8 +1240,7 @@ namespace GHelper dx = ax.PixelPositionToValue(e.X); dy = ay.PixelPositionToValue(e.Y); - if (dx < 20) dx = 20; - if (dx > 100) dx = 100; + dx = AsusACPI.FixTemp((int)dx, curIndex); if (dy < 0) dy = 0; if (dy > fansMax) dy = fansMax;