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
|
//! Gets temperature data via sysinfo.
use anyhow::Result;
use super::{is_temp_filtered, TempHarvest, TemperatureType};
use crate::app::Filter;
pub fn get_temperature_data(
sys: &sysinfo::System, temp_type: &TemperatureType, filter: &Option<Filter>,
) -> Result<Option<Vec<TempHarvest>>> {
use sysinfo::{ComponentExt, SystemExt};
let mut temperature_vec: Vec<TempHarvest> = Vec::new();
let sensor_data = sys.components();
for component in sensor_data {
let name = component.label().to_string();
if is_temp_filtered(filter, &name) {
temperature_vec.push(TempHarvest {
name,
temperature: temp_type.convert_temp_unit(component.temperature()),
});
}
}
// For RockPro64 boards on FreeBSD, they apparently use "hw.temperature" for sensors.
#[cfg(target_os = "freebsd")]
{
use sysctl::Sysctl;
const KEY: &str = "hw.temperature";
if let Ok(root) = sysctl::Ctl::new(KEY) {
for ctl in sysctl::CtlIter::below(root).flatten() {
if let (Ok(name), Ok(temp)) = (ctl.name(), ctl.value()) {
if let Some(temp) = temp.as_temperature() {
temperature_vec.push(TempHarvest {
name,
temperature: match temp_type {
TemperatureType::Celsius => temp.celsius(),
TemperatureType::Kelvin => temp.kelvin(),
TemperatureType::Fahrenheit => temp.fahrenheit(),
},
});
}
}
}
}
}
// TODO: Should we instead use a hashmap -> vec to skip dupes?
Ok(Some(temperature_vec))
}
|