From 32eec97d6af09ff3758f619e58f75a2640aac649 Mon Sep 17 00:00:00 2001 From: midefos Date: Sat, 4 Jan 2025 21:11:51 +0100 Subject: [PATCH] adding cpu coretemp-isa, and more nvme-pci --- src/lm_sensors.rs | 36 +++++++++++++++++++++++------------- src/main.rs | 4 ++-- src/sensor_names.rs | 5 +++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/lm_sensors.rs b/src/lm_sensors.rs index a7885f1..b798f83 100644 --- a/src/lm_sensors.rs +++ b/src/lm_sensors.rs @@ -34,28 +34,30 @@ pub struct Sensor { #[serde(rename = "Adapter")] _adapter: String, - #[serde(rename = "Tctl")] + #[serde(rename = "Tctl", skip_serializing_if = "Option::is_none")] tctl: Option>, - #[serde(rename = "Tccd1")] + #[serde(rename = "Tccd1", skip_serializing_if = "Option::is_none")] tccd1: Option>, - temp1: Option>, - #[serde(rename = "Composite")] + #[serde(skip_serializing_if = "Option::is_none")] + temp1: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + temp2: Option>, + + #[serde(rename = "Package id 0", skip_serializing_if = "Option::is_none")] + package_id_0: Option>, + + #[serde(rename = "Composite", skip_serializing_if = "Option::is_none")] composite: Option>, } impl Sensor { pub fn temp(&self) -> Option { - let sensor = self.actual_sector(); - match sensor { - None => return None, - Some(temperatures) => { - for temp_name in TEMP_NAMES { - if let Some(temp) = temperatures.get(temp_name) { - return Some(*temp); - } - } + let temperatures = self.actual_sector()?; + for temp_name in TEMP_NAMES { + if let Some(temp) = temperatures.get(temp_name) { + return Some(*temp); } } None @@ -74,6 +76,14 @@ impl Sensor { return self.temp1.clone(); } + if self.temp2.is_some() { + return self.temp2.clone(); + } + + if self.package_id_0.is_some() { + return self.package_id_0.clone(); + } + if self.composite.is_some() { return self.composite.clone(); } diff --git a/src/main.rs b/src/main.rs index da2d287..f398b12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,6 @@ fn print_gpu_temp() { } fn debug() { - println!("lm-sensors: {:?}", sensors_data()); - println!("nvidia-smi: {:?}", temperature()); + println!("lm-sensors: {:#?}", sensors_data()); + println!("nvidia-smi: {:#?}", temperature()); } diff --git a/src/sensor_names.rs b/src/sensor_names.rs index f293d9b..0155bd4 100644 --- a/src/sensor_names.rs +++ b/src/sensor_names.rs @@ -1,3 +1,4 @@ pub const TEMP_NAMES: [&str; 1] = ["temp1_input"]; -pub const CPU_NAMES: [&str; 1] = ["k10temp-pci-00c3"]; -pub const DISK_NAMES: [&str; 1] = ["nvme-pci-0100"]; + +pub const CPU_NAMES: [&str; 2] = ["k10temp-pci-00c3", "coretemp-isa-0000"]; +pub const DISK_NAMES: [&str; 3] = ["nvme-pci-0100", "nvme-pci-0200", "nvme-pci-0300"];