Calibration

This commit is contained in:
Serge
2023-09-08 19:12:57 +02:00
parent 4ae3fb4e3d
commit 0e3efcf547
5 changed files with 319 additions and 146 deletions

View File

@@ -18,8 +18,6 @@ namespace GHelper
Series seriesMid;
Series seriesXGM;
static int MinRPM, MaxRPM;
static bool gpuVisible = true;
static bool fanRpm = true;
@@ -28,6 +26,8 @@ namespace GHelper
NvidiaGpuControl? nvControl = null;
ModeControl modeControl = Program.modeControl;
public static System.Timers.Timer timer = default!;
public Fans()
{
@@ -59,8 +59,6 @@ namespace GHelper
InitTheme(true);
MinRPM = 18;
MaxRPM = HardwareControl.fanMax;
labelTip.Visible = false;
labelTip.BackColor = Color.Transparent;
@@ -200,13 +198,139 @@ namespace GHelper
checkApplyUV.Click += CheckApplyUV_Click;
timer = new System.Timers.Timer(1000);
timer.Elapsed += Timer_Elapsed;
buttonCalibrate.Click += ButtonCalibrate_Click;
ToggleNavigation(0);
FormClosed += Fans_FormClosed;
}
const int FAN_COUNT = 3;
static int[] fanMin, fanMax;
static int sameCount = 0;
static int calibrationStep = 0;
private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
int fan;
bool same = true;
for (int i = 0; i < FAN_COUNT; i++)
{
fan = Program.acpi.GetFan((AsusFan)i);
if (calibrationStep == 1)
{
if (fan < fanMin[i])
{
fanMin[i] = fan;
same = false;
}
}
if (calibrationStep == 2)
{
if (fan > fanMax[i])
{
fanMax[i] = fan;
same = false;
}
}
}
if (same) sameCount++;
else sameCount = 0;
if (calibrationStep == 1)
{
LabelFansResult("Measuring Min Speed - CPU: " + fanMin[(int)AsusFan.CPU]*100 + ", GPU: " + fanMin[(int)AsusFan.GPU] * 100 + " (" + sameCount + "s)");
}
if (calibrationStep == 2)
{
LabelFansResult("Measuring Max Speed - CPU: " + fanMax[(int)AsusFan.CPU] * 100 + ", GPU: " + fanMax[(int)AsusFan.GPU] * 100 + " (" + sameCount + "s)");
}
if (sameCount >= 15)
{
for (int i = 0; i < FAN_COUNT; i++)
{
if (fanMin[i] > 0 && fanMin[i] < 30) AppConfig.Set("fan_min_" + i, fanMin[i]);
if (fanMax[i] > 30 && fanMax[i] < 80) AppConfig.Set("fan_max_" + i, fanMax[i]);
}
sameCount = 0;
CalibrateNext();
}
}
private void CalibrateNext()
{
calibrationStep++;
if (calibrationStep == 1)
{
for (int i = 0; i < FAN_COUNT; i++)
Program.acpi.SetFanCurve((AsusFan)i, new byte[] { 20, 30, 40, 50, 60, 70, 80, 90, 1, 1, 1, 1, 1, 1, 1, 1 });
return;
}
if (calibrationStep == 2)
{
for (int i = 0; i < FAN_COUNT; i++)
Program.acpi.SetFanCurve((AsusFan)i, new byte[] { 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 100, 100, 100, 100, 100, 100 });
return;
}
timer.Enabled = false;
modeControl.SetPerformanceMode();
string label = "Measured - CPU: " + AppConfig.Get("fan_min_" + (int)AsusFan.CPU) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.CPU) * 100;
if (AppConfig.Get("fan_max_" + (int)AsusFan.GPU) > 0)
label = label + ", GPU: " + AppConfig.Get("fan_min_" + (int)AsusFan.GPU) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.GPU) * 100;
if (AppConfig.Get("fan_max_" + (int)AsusFan.Mid) > 0)
label = label + ", Mid: " + AppConfig.Get("fan_min_" + (int)AsusFan.Mid) * 100 + ".." + AppConfig.Get("fan_max_" + (int)AsusFan.Mid) * 100;
LabelFansResult(label);
Invoke(delegate
{
buttonCalibrate.Enabled = true;
SetAxis(chartCPU, AsusFan.CPU);
SetAxis(chartGPU, AsusFan.GPU);
if (chartMid.Visible) SetAxis(chartMid, AsusFan.Mid);
});
}
private void ButtonCalibrate_Click(object? sender, EventArgs e)
{
fanMin = new int[] { 100, 100, 100 };
fanMax = new int[] { 0, 0, 0 };
calibrationStep = 0;
buttonCalibrate.Enabled = false;
timer.Enabled = true;
for (int i = 0; i < FAN_COUNT; i++)
{
AppConfig.Remove("fan_min_" + i);
AppConfig.Remove("fan_max_" + i);
}
CalibrateNext();
}
private void ChartCPU_MouseClick(object? sender, MouseEventArgs e)
{
if (sender is null) return;
@@ -571,15 +695,17 @@ namespace GHelper
VisualiseGPUSettings();
}
static string ChartPercToRPM(int percentage, AsusFan device, string unit = "")
static string ChartYLabel(int percentage, AsusFan device, string unit = "")
{
if (percentage == 0) return "OFF";
int Max = MaxRPM;
int Min = AppConfig.Get("fan_min_" + (int)device, HardwareControl.DEFAULT_FAN_MIN);
int Max = AppConfig.Get("fan_max_" + (int)device, HardwareControl.DEFAULT_FAN_MAX);
if (device == AsusFan.XGM) Max = 72;
if (fanRpm)
return (200 * Math.Round((float)(MinRPM * 100 + (Max - MinRPM) * percentage) / 200)).ToString() + unit;
return (200 * Math.Round((float)(Min * 100 + (Max - Min) * percentage) / 200)).ToString() + unit;
else
return percentage + "%";
}
@@ -591,7 +717,7 @@ namespace GHelper
for (int i = 0; i <= fansMax - 10; i += 10)
{
chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartPercToRPM(i, device));
chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartYLabel(i, device));
}
chart.ChartAreas[0].AxisY.CustomLabels.Add(fansMax - 2, fansMax + 2, Properties.Strings.RPM);
@@ -724,8 +850,11 @@ namespace GHelper
public void LabelFansResult(string text)
{
labelFansResult.Text = text;
labelFansResult.Visible = (text.Length > 0);
Invoke(delegate
{
labelFansResult.Text = text;
labelFansResult.Visible = (text.Length > 0);
});
}
private void Fans_FormClosing(object? sender, FormClosingEventArgs e)
@@ -994,7 +1123,6 @@ namespace GHelper
{
curPoint = null;
curIndex = -1;
labelTip.Visible = false;
SaveProfile(seriesCPU, AsusFan.CPU);
@@ -1017,7 +1145,9 @@ namespace GHelper
private void ChartCPU_MouseLeave(object? sender, EventArgs e)
{
Chart_Save();
curPoint = null;
curIndex = -1;
labelTip.Visible = false;
}
private void ChartCPU_MouseMove(object? sender, MouseEventArgs e, AsusFan device)
@@ -1081,7 +1211,7 @@ namespace GHelper
tip = true;
}
labelTip.Text = Math.Round(curPoint.XValue) + "C, " + ChartPercToRPM((int)curPoint.YValues[0], device, " " + Properties.Strings.RPM);
labelTip.Text = Math.Round(curPoint.XValue) + "C, " + ChartYLabel((int)curPoint.YValues[0], device, " " + Properties.Strings.RPM);
labelTip.Top = e.Y + ((Control)sender).Top;
labelTip.Left = e.X - 50;