-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathOHWMPlugin.cs
96 lines (81 loc) · 2.7 KB
/
OHWMPlugin.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using OpenHardwareMonitor.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using ZenTimings.Common;
using ZenTimings.Plugin;
namespace OHWMPlugin
{
public class OHWMPlugin : IPlugin
{
internal Computer computer;
public string Name => "OpenHardwareMonitor Plugin";
public string Description => "A wrapper around OpenHardwareMonitor's DLL";
public string Author => "Ivan Rusanov";
public string Version => "1.0";
public List<Sensor> Sensors { get; internal set; }
public OHWMPlugin()
{
Assembly assembly = Assembly.LoadFrom("OpenHardwareMonitorLib.dll");
if (assembly == null)
{
throw new Exception("OpenHardwareMonitorLib.dll not found");
}
}
public void Close()
{
throw new NotImplementedException();
}
public void Open()
{
computer = new Computer()
{
//CPUEnabled = true,
//RAMEnabled = true,
MainboardEnabled = true,
//FanControllerEnabled = true,
};
computer.Open();
int index = 0;
foreach (var hardware in computer.Hardware)
{
if (hardware.HardwareType == HardwareType.Mainboard)
{
foreach (var subHardware in hardware.SubHardware)
{
foreach (var subsensor in subHardware.Sensors)
{
//if (subsensor.SensorType == SensorType.Voltage)
Console.WriteLine($"----{subsensor.SensorType}, Name: {subsensor.Name}, Value: {subsensor.Value}");
Sensors.Add(new Sensor(subsensor.Name, index));
index++;
}
}
}
}
}
public bool Update()
{
int index = 0;
foreach (var hardware in computer.Hardware)
{
if (hardware.HardwareType == HardwareType.Mainboard)
{
foreach (var subHardware in hardware.SubHardware)
{
subHardware.Update();
foreach (var subsensor in subHardware.Sensors)
{
Sensors[index].Value = subsensor.Value;
}
}
}
}
return true;
}
}
}