-
Notifications
You must be signed in to change notification settings - Fork 11
/
ADLXControl.cs
75 lines (58 loc) · 1.96 KB
/
ADLXControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ADLXWrapper;
using FanControl.Plugins;
using System;
namespace FanControl.ADLX
{
public class ADLXControl : IPluginControlSensor
{
private readonly ManualFanTuning _fanTuning;
private bool _zeroRPMState;
private bool _supportTargetFanSpeed;
public ADLXControl(GPU gpu, ManualFanTuning fanTuning)
{
Name = gpu.Name;
Id = $"ADLX/{gpu.Name}/{gpu.UniqueId}/Control";
_fanTuning = fanTuning;
if (fanTuning.SupportsTargetFanSpeed && fanTuning.SpeedRange.Max > 0)
_supportTargetFanSpeed = true;
if (fanTuning.SupportsZeroRPM)
_zeroRPMState = fanTuning.GetZeroRPMState();
}
public string Id { get; }
public string Name { get; }
public float? Value { get; private set; } = null;
private void SetZeroRPM(bool enable)
{
if (!_fanTuning.SupportsZeroRPM)
return;
if (enable == _zeroRPMState)
return;
_fanTuning.SetZeroRPM(enable);
_zeroRPMState = enable;
}
public void Reset()
{
_fanTuning.Reset();
if (_fanTuning.SupportsZeroRPM)
_zeroRPMState = _fanTuning.GetZeroRPMState();
Value = null;
}
public void Set(float val)
{
var roundedVal = (int)Math.Round(val);
if (roundedVal == 0)
SetZeroRPM(true);
else
SetZeroRPM(false);
if (roundedVal == Value)
return;
if (_supportTargetFanSpeed)
_fanTuning.SetTargetFanSpeed(GetRPM(val));
else
_fanTuning.SetFanTuningStates2(roundedVal);
Value = roundedVal;
}
private int GetRPM(float val) => (int)(_fanTuning.SpeedRange.Max * (val / 100f));
public void Update() { /* nothing to update */ }
}
}