Restore fan mode on resume

This commit is contained in:
Kamil Trzciński 2022-11-13 07:51:47 +01:00
parent 75f40c4167
commit def9012056
3 changed files with 22 additions and 0 deletions

View file

@ -50,6 +50,23 @@ namespace FanControl
}
notifyIcon.ShowBalloonTip(3000, Text, "Fan Control Started", ToolTipIcon.Info);
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
}
private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
{
// Restore fan mode on resume
if (e.Mode == Microsoft.Win32.PowerModes.Resume)
{
fanControl.SetMode(fanControl.Mode);
}
}
private void setFanMode(FanController.FanMode mode)

View file

@ -22,6 +22,7 @@ namespace FanControl
SensorType = SensorType.Power,
ValueDeadZone = 0.1f,
AvgSamples = 20,
MaxValue = 25, // TODO: On resume a bogus value is returned
Profiles = new Dictionary<FanMode, FanSensor.Profile>()
{
{

View file

@ -18,6 +18,7 @@ namespace FanControl
public float ValueDeadZone { get; set; }
public int AvgSamples { get; set; } = 5;
public float? MaxValue { get; set; }
internal string HardwareName { get; set; } = "";
internal HardwareType HardwareType { get; set; }
@ -153,6 +154,9 @@ namespace FanControl
if (!newValue.HasValue || newValue <= 0.0)
return false;
if (MaxValue.HasValue)
newValue = Math.Min(newValue.Value, MaxValue.Value);
if (AllSamples.Count == 0 || Math.Abs(AllSamples.Last() - newValue.Value) >= ValueDeadZone)
{
AllSamples.Add(newValue.Value);