-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeviceFan.cs
More file actions
87 lines (73 loc) · 2.91 KB
/
DeviceFan.cs
File metadata and controls
87 lines (73 loc) · 2.91 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
using CtlLibraryBindings;
using System;
namespace FanControl.IntelCtlLibraryPlugin
{
public enum DeviceFanControlMode
{
NoControl,
Fixed,
Table,
}
public class DeviceFan : IDisposable
{
private readonly SWIGTYPE_p__ctl_fan_handle_t _fanHandle;
private readonly SWIGTYPE_p_int _speedRequestPtr;
private readonly ctl_fan_speed_t _speed;
private readonly ctl_fan_properties_t _properties;
private readonly ctl_fan_speed_table_t _table;
public DeviceFan(SWIGTYPE_p__ctl_fan_handle_t fanHandle, int index)
{
_fanHandle = fanHandle;
Index = index;
_speedRequestPtr = CtlLibrary.new_int_Ptr();
_speed = new ctl_fan_speed_t
{
units = ctl_fan_speed_units_t.CTL_FAN_SPEED_UNITS_PERCENT,
// version?
};
_properties = new ctl_fan_properties_t();
CtlLibrary.ctlFanGetProperties(fanHandle, _properties);
ControlMode = HasFlag(_properties, ctl_fan_speed_mode_t.CTL_FAN_SPEED_MODE_TABLE) ? DeviceFanControlMode.Table :
HasFlag(_properties, ctl_fan_speed_mode_t.CTL_FAN_SPEED_MODE_FIXED) ? DeviceFanControlMode.Fixed :
DeviceFanControlMode.NoControl;
_table = new ctl_fan_speed_table_t();
}
private static bool HasFlag(ctl_fan_properties_t properties, ctl_fan_speed_mode_t mode)
{
return (properties.supportedModes & (uint)mode) != 0;
}
public int Index { get; }
public DeviceFanControlMode ControlMode { get; }
public void Dispose()
{
Reset();
CtlLibrary.delete_int_Ptr(_speedRequestPtr);
_table.Dispose();
_speed.Dispose();
_properties.Dispose();
}
public void Reset()
{
CtlLibrary.ctlFanSetDefaultMode(_fanHandle);
}
public int GetSpeedPercent()
{
CtlLibrary.ctlFanGetState(_fanHandle, ctl_fan_speed_units_t.CTL_FAN_SPEED_UNITS_PERCENT, _speedRequestPtr).ThrowIfError("Get fan % speed");
return CtlLibrary.int_Ptr_value(_speedRequestPtr);
}
public int GetSpeedRpm()
{
CtlLibrary.ctlFanGetState(_fanHandle, ctl_fan_speed_units_t.CTL_FAN_SPEED_UNITS_RPM, _speedRequestPtr).ThrowIfError("Get fan RPM speed");
return CtlLibrary.int_Ptr_value(_speedRequestPtr);
}
public void SetFanSpeedPercent(int percent)
{
_speed.speed = percent;
CtlLibrary.ctlFanSetFixedSpeedMode(_fanHandle, _speed).ThrowIfError($"Setting fan speed to {percent}");
}
public void SetFlatFanSpeedTable(int percent)
{
CtlLibrary.SetFlatFanSpeedTable(_fanHandle, _table, percent).ThrowIfError($"Setting flat table fan speed to {percent}");
}
}
}