lhm_shared/
lib.rs

1use num_enum::{FromPrimitive, IntoPrimitive};
2use serde::{Deserialize, Serialize};
3
4pub const PIPE_NAME: &str = r"\\.\pipe\LHMLibreHardwareMonitorService";
5
6#[derive(Debug, Default, Clone, Deserialize, Serialize)]
7pub struct ComputerOptions {
8    pub battery_enabled: bool,
9    pub controller_enabled: bool,
10    pub cpu_enabled: bool,
11    pub gpu_enabled: bool,
12    pub memory_enabled: bool,
13    pub motherboard_enabled: bool,
14    pub network_enabled: bool,
15    pub psu_enabled: bool,
16    pub storage_enabled: bool,
17}
18
19#[derive(Deserialize, Serialize)]
20#[serde(tag = "type")]
21pub enum PipeRequest {
22    SetOptions { options: ComputerOptions },
23    Update,
24    GetHardware,
25}
26
27#[derive(Debug, Deserialize, Serialize)]
28#[serde(tag = "type")]
29pub enum PipeResponse {
30    Hardware { hardware: Vec<Hardware> },
31    Updated,
32    UpdatedOptions,
33    Error { error: String },
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct Hardware {
38    /// Name of the hardware
39    pub name: String,
40
41    /// Type of hardware
42    pub ty: HardwareType,
43
44    /// Children for the hardware
45    pub children: Vec<Hardware>,
46
47    /// Sensors attached to the hardware
48    pub sensors: Vec<Sensor>,
49}
50
51/// Instance of a sensor
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct Sensor {
54    /// Name of the sensor
55    pub name: String,
56
57    /// Type of the sensor
58    pub ty: SensorType,
59
60    /// Value of the sensor will be NaN when the sensor
61    /// has no value
62    pub value: f32,
63}
64
65/// Types of hardware
66#[derive(
67    Debug,
68    Clone,
69    Copy,
70    FromPrimitive,
71    IntoPrimitive,
72    Serialize,
73    Deserialize,
74    PartialEq,
75    Eq,
76    PartialOrd,
77    Ord,
78)]
79#[repr(u32)]
80pub enum HardwareType {
81    Motherboard,
82    SuperIO,
83    Cpu,
84    Memory,
85    GpuNvidia,
86    GpuAmd,
87    GpuIntel,
88    Storage,
89    Network,
90    Cooler,
91    EmbeddedController,
92    Psu,
93    Battery,
94    #[num_enum(catch_all)]
95    Unknown(u32),
96}
97
98/// Types of sensors
99#[derive(
100    Debug,
101    Clone,
102    Copy,
103    FromPrimitive,
104    IntoPrimitive,
105    Serialize,
106    Deserialize,
107    PartialEq,
108    Eq,
109    PartialOrd,
110    Ord,
111)]
112#[repr(u32)]
113pub enum SensorType {
114    Voltage,
115    Current,
116    Power,
117    Clock,
118    Temperature,
119    Load,
120    Frequency,
121    Fan,
122    Flow,
123    Control,
124    Level,
125    Factor,
126    Data,
127    SmallData,
128    Throughput,
129    TimeSpan,
130    Energy,
131    Noise,
132    Conductivity,
133    Humidity,
134    #[num_enum(catch_all)]
135    Unknown(u32),
136}