mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 22:54:21 +00:00
refactor: replace heim temp conversion code (#811)
This commit is contained in:
parent
10efe75fbd
commit
cc048de3b0
2 changed files with 12 additions and 21 deletions
|
@ -39,16 +39,12 @@ impl Default for TemperatureType {
|
|||
}
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(feature = "nvidia", target_os = "macos", target_os = "windows"))] {
|
||||
fn convert_celsius_to_kelvin(celsius: f32) -> f32 {
|
||||
celsius + 273.15
|
||||
}
|
||||
fn convert_celsius_to_kelvin(celsius: f32) -> f32 {
|
||||
celsius + 273.15
|
||||
}
|
||||
|
||||
fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 {
|
||||
(celsius * (9.0 / 5.0)) + 32.0
|
||||
}
|
||||
}
|
||||
fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 {
|
||||
(celsius * (9.0 / 5.0)) + 32.0
|
||||
}
|
||||
|
||||
fn is_temp_filtered(filter: &Option<Filter>, text: &str) -> bool {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
//! Gets temperature data via heim.
|
||||
|
||||
use super::{is_temp_filtered, temp_vec_sort, TempHarvest, TemperatureType};
|
||||
use crate::app::Filter;
|
||||
use crate::app::{
|
||||
data_harvester::temperature::{convert_celsius_to_fahrenheit, convert_celsius_to_kelvin},
|
||||
Filter,
|
||||
};
|
||||
|
||||
/// Get temperature sensors from the linux sysfs interface `/sys/class/hwmon`
|
||||
///
|
||||
|
@ -97,7 +100,6 @@ pub async fn get_temperature_data(
|
|||
};
|
||||
|
||||
if is_temp_filtered(filter, &name) {
|
||||
use heim::units::{thermodynamic_temperature, ThermodynamicTemperature};
|
||||
let temp = if should_read_temp {
|
||||
let temp = fs::read_to_string(temp)?;
|
||||
let temp = temp.trim_end().parse::<f32>().map_err(|e| {
|
||||
|
@ -107,20 +109,13 @@ pub async fn get_temperature_data(
|
|||
} else {
|
||||
0.0
|
||||
};
|
||||
let temp = ThermodynamicTemperature::new::<thermodynamic_temperature::degree_celsius>(
|
||||
temp,
|
||||
);
|
||||
|
||||
temperature_vec.push(TempHarvest {
|
||||
name,
|
||||
temperature: match temp_type {
|
||||
TemperatureType::Celsius => {
|
||||
temp.get::<thermodynamic_temperature::degree_celsius>()
|
||||
}
|
||||
TemperatureType::Kelvin => temp.get::<thermodynamic_temperature::kelvin>(),
|
||||
TemperatureType::Fahrenheit => {
|
||||
temp.get::<thermodynamic_temperature::degree_fahrenheit>()
|
||||
}
|
||||
TemperatureType::Celsius => temp,
|
||||
TemperatureType::Kelvin => convert_celsius_to_kelvin(temp),
|
||||
TemperatureType::Fahrenheit => convert_celsius_to_fahrenheit(temp),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue