Skip to content

Commit

Permalink
other: support hw.temperature-based temps for FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Feb 19, 2023
1 parent f89b243 commit 0aef56d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
23 changes: 21 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ unicode-width = "0.1.10"
libc = "0.2.124"

[target.'cfg(target_os = "linux")'.dependencies]
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory", "net", "sensors"] }
heim = { version = "0.1.0-rc.1", features = [
"cpu",
"disk",
"memory",
"net",
"sensors",
] }
procfs = { version = "0.14.2", default-features = false }
smol = "1.2.5"

Expand All @@ -119,13 +125,16 @@ mach2 = "0.4.1"

[target.'cfg(target_os = "windows")'.dependencies]
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory"] }
windows = { version = "0.44.0", features = ["Win32_System_Threading", "Win32_Foundation"] }
windows = { version = "0.44.0", features = [
"Win32_System_Threading",
"Win32_Foundation",
] }

winapi = "0.3.9"

[target.'cfg(target_os = "freebsd")'.dependencies]
serde_json = { version = "1.0.82" }
sysctl = { version = "0.5.2", optional = true }
sysctl = { version = "0.5.4", optional = true }
filedescriptor = "0.8.2"

[dev-dependencies]
Expand Down
25 changes: 25 additions & 0 deletions src/app/data_harvester/temperature/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,30 @@ pub fn get_temperature_data(
super::nvidia::add_nvidia_data(&mut temperature_vec, temp_type, filter)?;
}

// 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))
}

0 comments on commit 0aef56d

Please sign in to comment.