1use num_enum::{FromPrimitive, IntoPrimitive};
2use serde::{Deserialize, Serialize};
3
4pub mod codec;
5
6pub const PIPE_NAME: &str = r"\\.\pipe\LHMLibreHardwareMonitorService";
7
8#[derive(Debug, Default, Clone, Deserialize, Serialize)]
9pub struct ComputerOptions {
10 pub battery_enabled: bool,
11 pub controller_enabled: bool,
12 pub cpu_enabled: bool,
13 pub gpu_enabled: bool,
14 pub memory_enabled: bool,
15 pub motherboard_enabled: bool,
16 pub network_enabled: bool,
17 pub psu_enabled: bool,
18 pub storage_enabled: bool,
19}
20
21#[derive(Deserialize, Serialize)]
22#[serde(tag = "type")]
23pub enum PipeRequest {
24 SetOptions {
25 options: ComputerOptions,
26 },
27 UpdateAll,
28 GetHardwareById {
29 id: String,
30 },
31 QueryHardware {
32 parent_id: Option<String>,
33 ty: Option<HardwareType>,
34 },
35 UpdateHardwareById {
36 id: String,
37 },
38 UpdateHardwareByIndex {
39 idx: usize,
40 },
41 GetSensorById {
42 id: String,
43 },
44 GetSensorValueById {
45 id: String,
46 update: bool,
47 },
48 GetSensorValueByIndex {
49 idx: usize,
50 update: bool,
51 },
52 QuerySensors {
53 parent_id: Option<String>,
54 ty: Option<SensorType>,
55 },
56 UpdateSensorById {
57 id: String,
58 },
59 UpdateSensorByIndex {
60 idx: usize,
61 },
62}
63
64#[derive(Debug, Deserialize, Serialize)]
65#[serde(tag = "type")]
66pub enum PipeResponse {
67 Hardware { hardware: Option<Hardware> },
68 Hardwares { hardware: Vec<Hardware> },
69
70 Sensor { sensor: Option<Sensor> },
71 SensorValue { value: Option<f32> },
72 Sensors { sensors: Vec<Sensor> },
73
74 Success,
75 Error { error: String },
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct Hardware {
80 pub index: usize,
82
83 pub identifier: String,
85
86 pub name: String,
88
89 pub ty: HardwareType,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct Sensor {
96 pub index: usize,
98
99 pub identifier: String,
101
102 pub name: String,
104
105 pub ty: SensorType,
107
108 pub value: f32,
111}
112
113#[derive(
115 Debug,
116 Clone,
117 Copy,
118 FromPrimitive,
119 IntoPrimitive,
120 Serialize,
121 Deserialize,
122 PartialEq,
123 Eq,
124 PartialOrd,
125 Ord,
126)]
127#[repr(i32)]
128pub enum HardwareType {
129 Motherboard,
130 SuperIO,
131 Cpu,
132 Memory,
133 GpuNvidia,
134 GpuAmd,
135 GpuIntel,
136 Storage,
137 Network,
138 Cooler,
139 EmbeddedController,
140 Psu,
141 Battery,
142 #[num_enum(catch_all)]
143 Unknown(i32),
144}
145
146#[derive(
148 Debug,
149 Clone,
150 Copy,
151 FromPrimitive,
152 IntoPrimitive,
153 Serialize,
154 Deserialize,
155 PartialEq,
156 Eq,
157 PartialOrd,
158 Ord,
159)]
160#[repr(i32)]
161pub enum SensorType {
162 Voltage,
163 Current,
164 Power,
165 Clock,
166 Temperature,
167 Load,
168 Frequency,
169 Fan,
170 Flow,
171 Control,
172 Level,
173 Factor,
174 Data,
175 SmallData,
176 Throughput,
177 TimeSpan,
178 Energy,
179 Noise,
180 Conductivity,
181 Humidity,
182 #[num_enum(catch_all)]
183 Unknown(i32),
184}