Restrict fan curve points

This commit is contained in:
Serge
2024-10-06 12:03:42 +02:00
parent e28f51cce6
commit 04afbea26f
2 changed files with 15 additions and 44 deletions

View File

@@ -583,7 +583,7 @@ public class AsusACPI
} }
//Logger.WriteLine($"GetFan {device} :" + BitConverter.ToString(result)); //Logger.WriteLine($"GetFan {device} :" + BitConverter.ToString(result));
if (IsInvalidCurve(result)) result = AppConfig.GetDefaultCurve(device);
return result; return result;
} }
@@ -598,43 +598,20 @@ public class AsusACPI
return curve.All(singleByte => singleByte == 0); 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) public static byte[] FixFanCurve(byte[] curve)
{ {
if (curve.Length != 16) throw new Exception("Incorrect curve"); if (curve.Length != 16) throw new Exception("Incorrect curve");
var points = new Dictionary<byte, byte>();
byte old = 0;
for (int i = 0; i < 8; i++) 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 curve[i] = (byte)FixTemp(curve[i], i);
points[curve[i]] = curve[i + 8];
old = curve[i];
}
var pointsFixed = new Dictionary<byte, byte>();
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++;
} }
return curve; return curve;

View File

@@ -757,8 +757,8 @@ namespace GHelper
chart.Titles[0].Text = title; chart.Titles[0].Text = title;
chart.ChartAreas[0].AxisX.Minimum = 10; chart.ChartAreas[0].AxisX.Minimum = 20;
chart.ChartAreas[0].AxisX.Maximum = 100; chart.ChartAreas[0].AxisX.Maximum = 110;
chart.ChartAreas[0].AxisX.Interval = 10; chart.ChartAreas[0].AxisX.Interval = 10;
chart.ChartAreas[0].AxisY.Minimum = 0; chart.ChartAreas[0].AxisY.Minimum = 0;
@@ -1019,7 +1019,7 @@ namespace GHelper
int chartCount = 2; int chartCount = 2;
// Middle / system fan check // 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); AppConfig.Set("mid_fan", 1);
chartCount++; chartCount++;
@@ -1082,15 +1082,10 @@ namespace GHelper
if (reset || AsusACPI.IsInvalidCurve(curve)) if (reset || AsusACPI.IsInvalidCurve(curve))
{ {
curve = Program.acpi.GetFanCurve(device, Modes.GetCurrentBase()); curve = Program.acpi.GetFanCurve(device, Modes.GetCurrentBase());
Logger.WriteLine($"Default {device}:" + BitConverter.ToString(curve));
if (AsusACPI.IsInvalidCurve(curve))
curve = AppConfig.GetDefaultCurve(device);
curve = AsusACPI.FixFanCurve(curve);
} }
//Debug.WriteLine(BitConverter.ToString(curve)); curve = AsusACPI.FixFanCurve(curve);
byte old = 0; byte old = 0;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
@@ -1245,8 +1240,7 @@ namespace GHelper
dx = ax.PixelPositionToValue(e.X); dx = ax.PixelPositionToValue(e.X);
dy = ay.PixelPositionToValue(e.Y); dy = ay.PixelPositionToValue(e.Y);
if (dx < 20) dx = 20; dx = AsusACPI.FixTemp((int)dx, curIndex);
if (dx > 100) dx = 100;
if (dy < 0) dy = 0; if (dy < 0) dy = 0;
if (dy > fansMax) dy = fansMax; if (dy > fansMax) dy = fansMax;