-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensorSource.cs
78 lines (59 loc) · 2.12 KB
/
SensorSource.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
76
77
78
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace LiquidCtlAfterburnerPlugin
{
internal class SensorSource
{
public readonly LiquidctlDevice _device;
private Task LiquidCtlPollTask;
public SensorSource(LiquidctlDevice device)
{
_device = device;
}
public void Reload()
{
if (LiquidCtlPollTask == null || LiquidCtlPollTask.IsCompleted)
LiquidCtlPollTask = Task.Run(() => _device.LoadJSON());
}
public int SensorCount => _device.status.Count;
public float SensorValue(int index)
{
return (float) _device.status[index].GetValueAsFloat();
}
public void FillDescription(int index, ref MonitoringSourceDesc desc)
{
LiquidctlStatusJSON.StatusRecord status = _device.status[index];
desc.szName = $"{Regex.Match(_device.name, @"\w+ \w+").Groups[0].Value} {status.key}";
desc.szUnits = status.unit;
desc.szGroup = _device.name;
desc.dwID = GetSensorPluginID();
desc.dwInstance = 0;
desc.fltMinLimit = 0f;
desc.fltMaxLimit = GetSensorMaxLimit(status.unit);
desc.szFormat = GetSensorFormat(status.unit);
}
private static uint GetSensorPluginID()
{
return 0x000000FF; //MONITORING_SOURCE_ID_PLUGIN_MISC
}
private static float GetSensorMaxLimit(string type)
{
switch(type) {
case "°C": return 100.0f;
case "rpm": return 8000.0f;
default: return 1000.0f;
}
}
private static string GetSensorFormat(string type)
{
switch(type) {
case "°C": return "%.1f";
case "rpm": return "%.0f";
default: return "%.3f";
}
}
}
}