mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Cleanup
This commit is contained in:
@@ -4,30 +4,82 @@ namespace GHelper.Fan
|
|||||||
{
|
{
|
||||||
public class FanSensorControl
|
public class FanSensorControl
|
||||||
{
|
{
|
||||||
|
public const int DEFAULT_FAN_MIN = 18;
|
||||||
|
public const int DEFAULT_FAN_MAX = 58;
|
||||||
|
|
||||||
|
public const int INADEQUATE_MAX = 90;
|
||||||
|
|
||||||
Fans fansForm;
|
Fans fansForm;
|
||||||
ModeControl modeControl = Program.modeControl;
|
ModeControl modeControl = Program.modeControl;
|
||||||
|
|
||||||
|
static int[] measuredMax;
|
||||||
const int FAN_COUNT = 3;
|
const int FAN_COUNT = 3;
|
||||||
static int[] fanMax;
|
|
||||||
static int sameCount = 0;
|
static int sameCount = 0;
|
||||||
|
|
||||||
static System.Timers.Timer timer = default!;
|
static System.Timers.Timer timer = default!;
|
||||||
|
|
||||||
public FanSensorControl(Fans fansForm) {
|
static int[] _fanMax = new int[3] {
|
||||||
|
AppConfig.Get("fan_max_" + (int)AsusFan.CPU, DEFAULT_FAN_MAX),
|
||||||
|
AppConfig.Get("fan_max_" + (int)AsusFan.GPU, DEFAULT_FAN_MAX),
|
||||||
|
AppConfig.Get("fan_max_" + (int)AsusFan.Mid, DEFAULT_FAN_MAX)
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool _fanRpm = AppConfig.IsNotFalse("fan_rpm");
|
||||||
|
|
||||||
|
public FanSensorControl(Fans fansForm)
|
||||||
|
{
|
||||||
this.fansForm = fansForm;
|
this.fansForm = fansForm;
|
||||||
|
|
||||||
timer = new System.Timers.Timer(1000);
|
timer = new System.Timers.Timer(1000);
|
||||||
timer.Elapsed += Timer_Elapsed;
|
timer.Elapsed += Timer_Elapsed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartCalibration() {
|
|
||||||
|
|
||||||
fanMax = new int[] { 0, 0, 0 };
|
public static int GetFanMax(AsusFan device)
|
||||||
|
{
|
||||||
|
if (_fanMax[(int)device] < 0 || _fanMax[(int)device] > INADEQUATE_MAX)
|
||||||
|
SetFanMax(device, DEFAULT_FAN_MAX);
|
||||||
|
|
||||||
|
return _fanMax[(int)device];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetFanMax(AsusFan device, int value)
|
||||||
|
{
|
||||||
|
_fanMax[(int)device] = value;
|
||||||
|
AppConfig.Set("fan_max_" + (int)device, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool fanRpm
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _fanRpm;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
AppConfig.Set("fan_rpm", value ? 1 : 0);
|
||||||
|
_fanRpm = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FormatFan(AsusFan device, int value)
|
||||||
|
{
|
||||||
|
if (value < 0) return null;
|
||||||
|
|
||||||
|
if (value > GetFanMax(device) && value <= INADEQUATE_MAX) SetFanMax(device, value);
|
||||||
|
|
||||||
|
if (fanRpm)
|
||||||
|
return Properties.Strings.FanSpeed + ": " + (value * 100).ToString() + "RPM";
|
||||||
|
else
|
||||||
|
return Properties.Strings.FanSpeed + ": " + Math.Min(Math.Round((float)value / GetFanMax(device) * 100), 100).ToString() + "%"; // relatively to max RPM
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartCalibration()
|
||||||
|
{
|
||||||
|
|
||||||
|
measuredMax = new int[] { 0, 0, 0 };
|
||||||
timer.Enabled = true;
|
timer.Enabled = true;
|
||||||
|
|
||||||
for (int i = 0; i < FAN_COUNT; i++)
|
for (int i = 0; i < FAN_COUNT; i++)
|
||||||
AppConfig.Remove("fan_max_" + i);
|
AppConfig.Remove("fan_max_" + i);
|
||||||
|
|
||||||
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, AsusACPI.PerformanceTurbo, "ModeCalibration");
|
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, AsusACPI.PerformanceTurbo, "ModeCalibration");
|
||||||
@@ -45,9 +97,9 @@ namespace GHelper.Fan
|
|||||||
for (int i = 0; i < FAN_COUNT; i++)
|
for (int i = 0; i < FAN_COUNT; i++)
|
||||||
{
|
{
|
||||||
fan = Program.acpi.GetFan((AsusFan)i);
|
fan = Program.acpi.GetFan((AsusFan)i);
|
||||||
if (fan > fanMax[i])
|
if (fan > measuredMax[i])
|
||||||
{
|
{
|
||||||
fanMax[i] = fan;
|
measuredMax[i] = fan;
|
||||||
same = false;
|
same = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,8 +107,8 @@ namespace GHelper.Fan
|
|||||||
if (same) sameCount++;
|
if (same) sameCount++;
|
||||||
else sameCount = 0;
|
else sameCount = 0;
|
||||||
|
|
||||||
string label = "Measuring Max Speed - CPU: " + fanMax[(int)AsusFan.CPU] * 100 + ", GPU: " + fanMax[(int)AsusFan.GPU] * 100;
|
string label = "Measuring Max Speed - CPU: " + measuredMax[(int)AsusFan.CPU] * 100 + ", GPU: " + measuredMax[(int)AsusFan.GPU] * 100;
|
||||||
if (fanMax[(int)AsusFan.Mid] > 10) label = label + ", Mid: " + fanMax[(int)AsusFan.Mid] * 100;
|
if (measuredMax[(int)AsusFan.Mid] > 10) label = label + ", Mid: " + measuredMax[(int)AsusFan.Mid] * 100;
|
||||||
label = label + " (" + sameCount + "s)";
|
label = label + " (" + sameCount + "s)";
|
||||||
|
|
||||||
fansForm.LabelFansResult(label);
|
fansForm.LabelFansResult(label);
|
||||||
@@ -65,16 +117,16 @@ namespace GHelper.Fan
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < FAN_COUNT; i++)
|
for (int i = 0; i < FAN_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (fanMax[i] > 30 && fanMax[i] < HardwareControl.INADEQUATE_MAX) AppConfig.Set("fan_max_" + i, fanMax[i]);
|
if (measuredMax[i] > 30 && measuredMax[i] < INADEQUATE_MAX) SetFanMax((AsusFan)i, measuredMax[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sameCount = 0;
|
sameCount = 0;
|
||||||
CalibrateNext();
|
FinishCalibration();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalibrateNext()
|
private void FinishCalibration()
|
||||||
{
|
{
|
||||||
|
|
||||||
timer.Enabled = false;
|
timer.Enabled = false;
|
||||||
|
|||||||
@@ -587,8 +587,8 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
if (percentage == 0) return "OFF";
|
if (percentage == 0) return "OFF";
|
||||||
|
|
||||||
int Min = HardwareControl.DEFAULT_FAN_MIN;
|
int Min = FanSensorControl.DEFAULT_FAN_MIN;
|
||||||
int Max = AppConfig.Get("fan_max_" + (int)device, HardwareControl.DEFAULT_FAN_MAX);
|
int Max = FanSensorControl.GetFanMax(device);
|
||||||
|
|
||||||
if (device == AsusFan.XGM) Max = 72;
|
if (device == AsusFan.XGM) Max = 72;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using GHelper;
|
using GHelper;
|
||||||
|
using GHelper.Fan;
|
||||||
using GHelper.Gpu;
|
using GHelper.Gpu;
|
||||||
using GHelper.Gpu.NVidia;
|
using GHelper.Gpu.NVidia;
|
||||||
using GHelper.Gpu.AMD;
|
using GHelper.Gpu.AMD;
|
||||||
@@ -10,11 +11,6 @@ using System.Management;
|
|||||||
public static class HardwareControl
|
public static class HardwareControl
|
||||||
{
|
{
|
||||||
|
|
||||||
public const int DEFAULT_FAN_MIN = 18;
|
|
||||||
public const int DEFAULT_FAN_MAX = 58;
|
|
||||||
|
|
||||||
public const int INADEQUATE_MAX = 85;
|
|
||||||
|
|
||||||
public static IGpuControl? GpuControl;
|
public static IGpuControl? GpuControl;
|
||||||
|
|
||||||
public static float? cpuTemp = -1;
|
public static float? cpuTemp = -1;
|
||||||
@@ -37,57 +33,6 @@ public static class HardwareControl
|
|||||||
|
|
||||||
static long lastUpdate;
|
static long lastUpdate;
|
||||||
|
|
||||||
static int[] _fanMax = new int[3] { DEFAULT_FAN_MAX, DEFAULT_FAN_MAX, DEFAULT_FAN_MAX };
|
|
||||||
static bool _fanRpm = false;
|
|
||||||
|
|
||||||
public static int GetFanMax(AsusFan device)
|
|
||||||
{
|
|
||||||
return _fanMax[(int)device];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetFanMax(AsusFan device, int value)
|
|
||||||
{
|
|
||||||
AppConfig.Set("fan_max_" + (int)device, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool fanRpm
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _fanRpm;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
AppConfig.Set("fan_rpm", value ? 1 : 0);
|
|
||||||
_fanRpm = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static HardwareControl()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
_fanMax[i] = AppConfig.Get("fan_max_" + i);
|
|
||||||
if (_fanMax[i] > INADEQUATE_MAX) _fanMax[i] = -1;
|
|
||||||
if (_fanMax[i] < 0) _fanMax[i] = DEFAULT_FAN_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
_fanRpm = AppConfig.IsNotFalse("fan_rpm");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string FormatFan(AsusFan device, int value)
|
|
||||||
{
|
|
||||||
if (value < 0) return null;
|
|
||||||
|
|
||||||
if (value > GetFanMax(device) && value <= INADEQUATE_MAX) SetFanMax(device, value);
|
|
||||||
|
|
||||||
if (fanRpm)
|
|
||||||
return GHelper.Properties.Strings.FanSpeed + ": " + (value * 100).ToString() + "RPM";
|
|
||||||
else
|
|
||||||
return GHelper.Properties.Strings.FanSpeed + ": " + Math.Min(Math.Round((float)value / GetFanMax(device) * 100), 100).ToString() + "%"; // relatively to 6000 rpm
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int GetGpuUse()
|
private static int GetGpuUse()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -240,9 +185,9 @@ public static class HardwareControl
|
|||||||
gpuTemp = -1;
|
gpuTemp = -1;
|
||||||
gpuUse = -1;
|
gpuUse = -1;
|
||||||
|
|
||||||
cpuFan = FormatFan(AsusFan.CPU, Program.acpi.GetFan(AsusFan.CPU));
|
cpuFan = FanSensorControl.FormatFan(AsusFan.CPU, Program.acpi.GetFan(AsusFan.CPU));
|
||||||
gpuFan = FormatFan(AsusFan.GPU, Program.acpi.GetFan(AsusFan.GPU));
|
gpuFan = FanSensorControl.FormatFan(AsusFan.GPU, Program.acpi.GetFan(AsusFan.GPU));
|
||||||
midFan = FormatFan(AsusFan.Mid, Program.acpi.GetFan(AsusFan.Mid));
|
midFan = FanSensorControl.FormatFan(AsusFan.Mid, Program.acpi.GetFan(AsusFan.Mid));
|
||||||
|
|
||||||
cpuTemp = GetCPUTemp();
|
cpuTemp = GetCPUTemp();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using GHelper.AutoUpdate;
|
using GHelper.AutoUpdate;
|
||||||
using GHelper.Battery;
|
using GHelper.Battery;
|
||||||
using GHelper.Display;
|
using GHelper.Display;
|
||||||
|
using GHelper.Fan;
|
||||||
using GHelper.Gpu;
|
using GHelper.Gpu;
|
||||||
using GHelper.Helpers;
|
using GHelper.Helpers;
|
||||||
using GHelper.Input;
|
using GHelper.Input;
|
||||||
@@ -563,7 +564,7 @@ namespace GHelper
|
|||||||
|
|
||||||
private void LabelCPUFan_Click(object? sender, EventArgs e)
|
private void LabelCPUFan_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
HardwareControl.fanRpm = !HardwareControl.fanRpm;
|
FanSensorControl.fanRpm = !FanSensorControl.fanRpm;
|
||||||
RefreshSensors(true);
|
RefreshSensors(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user