mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 13:45:12 +02:00
refactor: replace heim temp conversion code (#811)
This commit is contained in:
parent
10efe75fbd
commit
cc048de3b0
@ -39,16 +39,12 @@ impl Default for TemperatureType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
fn convert_celsius_to_kelvin(celsius: f32) -> f32 {
|
||||||
if #[cfg(any(feature = "nvidia", target_os = "macos", target_os = "windows"))] {
|
celsius + 273.15
|
||||||
fn convert_celsius_to_kelvin(celsius: f32) -> f32 {
|
}
|
||||||
celsius + 273.15
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 {
|
fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 {
|
||||||
(celsius * (9.0 / 5.0)) + 32.0
|
(celsius * (9.0 / 5.0)) + 32.0
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_temp_filtered(filter: &Option<Filter>, text: &str) -> bool {
|
fn is_temp_filtered(filter: &Option<Filter>, text: &str) -> bool {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
//! Gets temperature data via heim.
|
//! Gets temperature data via heim.
|
||||||
|
|
||||||
use super::{is_temp_filtered, temp_vec_sort, TempHarvest, TemperatureType};
|
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`
|
/// 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) {
|
if is_temp_filtered(filter, &name) {
|
||||||
use heim::units::{thermodynamic_temperature, ThermodynamicTemperature};
|
|
||||||
let temp = if should_read_temp {
|
let temp = if should_read_temp {
|
||||||
let temp = fs::read_to_string(temp)?;
|
let temp = fs::read_to_string(temp)?;
|
||||||
let temp = temp.trim_end().parse::<f32>().map_err(|e| {
|
let temp = temp.trim_end().parse::<f32>().map_err(|e| {
|
||||||
@ -107,20 +109,13 @@ pub async fn get_temperature_data(
|
|||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
let temp = ThermodynamicTemperature::new::<thermodynamic_temperature::degree_celsius>(
|
|
||||||
temp,
|
|
||||||
);
|
|
||||||
|
|
||||||
temperature_vec.push(TempHarvest {
|
temperature_vec.push(TempHarvest {
|
||||||
name,
|
name,
|
||||||
temperature: match temp_type {
|
temperature: match temp_type {
|
||||||
TemperatureType::Celsius => {
|
TemperatureType::Celsius => temp,
|
||||||
temp.get::<thermodynamic_temperature::degree_celsius>()
|
TemperatureType::Kelvin => convert_celsius_to_kelvin(temp),
|
||||||
}
|
TemperatureType::Fahrenheit => convert_celsius_to_fahrenheit(temp),
|
||||||
TemperatureType::Kelvin => temp.get::<thermodynamic_temperature::kelvin>(),
|
|
||||||
TemperatureType::Fahrenheit => {
|
|
||||||
temp.get::<thermodynamic_temperature::degree_fahrenheit>()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user