-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeviceTemp.cs
More file actions
54 lines (46 loc) · 1.76 KB
/
DeviceTemp.cs
File metadata and controls
54 lines (46 loc) · 1.76 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
using CtlLibraryBindings;
using System;
namespace FanControl.IntelCtlLibraryPlugin
{
public class DeviceTemp : IDisposable
{
private readonly SWIGTYPE_p__ctl_temp_handle_t _handle;
private readonly SWIGTYPE_p_double doublePtr;
public DeviceTemp(SWIGTYPE_p__ctl_temp_handle_t handle)
{
using (var properties = new ctl_temp_properties_t())
{
CtlLibrary.ctlTemperatureGetProperties(handle, properties);
Id = properties.type.ToString();
Name = TypeToString(properties.type);
}
_handle = handle;
doublePtr = CtlLibrary.new_double_Ptr();
}
public string Id { get; }
public string Name { get; }
public double GetValue()
{
CtlLibrary.ctlTemperatureGetState(_handle, doublePtr);
return CtlLibrary.double_Ptr_value(doublePtr);
}
public void Dispose()
{
CtlLibrary.delete_double_Ptr(doublePtr);
}
private static string TypeToString(ctl_temp_sensors_t type)
{
return type switch
{
ctl_temp_sensors_t.CTL_TEMP_SENSORS_GLOBAL => "Global",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_GPU => "GPU",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_MEMORY => "Memory",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_GLOBAL_MIN => "Global Min",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_GPU_MIN => "GPU Min",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_MEMORY_MIN => "Memory Min",
ctl_temp_sensors_t.CTL_TEMP_SENSORS_MAX => "Max",
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
}
}