Simplifications and fixes for edge cases
monitor.rs: Removed hardcoded pwm-range of 0 to 255 and instead correctly interpolate between pwm_min() and pwm_max() main.rs: Simpler comparison to check whether temperature changed since last time hw_mon.rs: Removed unnecessary conversions between u32 and u64
This commit is contained in:
parent
c5f968fcf9
commit
35532b1eb7
@ -121,17 +121,17 @@ impl HwMon {
|
||||
self.write("pwm1_enable", 2)
|
||||
}
|
||||
|
||||
pub fn set_pwm(&self, value: u32) -> std::io::Result<()> {
|
||||
pub fn set_pwm(&self, value: u64) -> std::io::Result<()> {
|
||||
if self.is_fan_automatic() {
|
||||
self.set_manual()?;
|
||||
}
|
||||
self.write("pwm1", value as u64)
|
||||
self.write("pwm1", value)
|
||||
}
|
||||
|
||||
pub fn set_speed(&mut self, speed: f64) -> std::io::Result<()> {
|
||||
let min = self.pwm_min() as f64;
|
||||
let max = self.pwm_max() as f64;
|
||||
let pwm = linear_map(speed, 0f64, 100f64, min, max).round() as u32;
|
||||
let pwm = linear_map(speed, 0f64, 100f64, min, max).round() as u64;
|
||||
self.set_pwm(pwm)
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ fn service(config: Config) -> std::io::Result<()> {
|
||||
log::debug!("Current {} temperature: {}", hw_mon.card, gpu_temp);
|
||||
let last = *cache.entry(*hw_mon.card).or_insert(1_000f64);
|
||||
|
||||
if ((last - 0.001f64)..(last + 0.001f64)).contains(&gpu_temp) {
|
||||
if (last - gpu_temp).abs() < 0.001f64 {
|
||||
log::debug!("Temperature didn't change");
|
||||
continue;
|
||||
};
|
||||
|
@ -48,14 +48,16 @@ pub fn verbose(config: Config) -> std::io::Result<()> {
|
||||
for hw_mon in controllers.iter_mut() {
|
||||
println!("Card {:3}", hw_mon.card.to_string().replace("card", ""));
|
||||
println!(" MIN | MAX | PWM | %");
|
||||
let min = hw_mon.pwm_min();
|
||||
let max = hw_mon.pwm_max();
|
||||
println!(
|
||||
" {:>4} | {:>4} | {:>6} | {:>3}",
|
||||
hw_mon.pwm_min(),
|
||||
hw_mon.pwm_max(),
|
||||
min,
|
||||
max,
|
||||
hw_mon
|
||||
.pwm()
|
||||
.map_or_else(|_e| String::from("FAILED"), |f| f.to_string()),
|
||||
(hw_mon.pwm().unwrap_or_default() as f32 / 2.55).round(),
|
||||
(crate::linear_map(hw_mon.pwm().unwrap_or_default() as f64, min as f64, max as f64, 0f64, 100f64)).round(),
|
||||
);
|
||||
|
||||
println!();
|
||||
@ -83,13 +85,15 @@ pub fn short(config: Config) -> std::io::Result<()> {
|
||||
"Card {:3} | Temp | MIN | MAX | PWM | %",
|
||||
hw_mon.card.to_string().replace("card", "")
|
||||
);
|
||||
let min = hw_mon.pwm_min();
|
||||
let max = hw_mon.pwm_max();
|
||||
println!(
|
||||
" | {:>5.2} | {:>4} | {:>4} | {:>4} | {:>3}",
|
||||
hw_mon.max_gpu_temp().unwrap_or_default(),
|
||||
hw_mon.pwm_min(),
|
||||
hw_mon.pwm_max(),
|
||||
min,
|
||||
max,
|
||||
hw_mon.pwm().unwrap_or_default(),
|
||||
(hw_mon.pwm().unwrap_or_default() as f32 / 2.55).round(),
|
||||
crate::linear_map(hw_mon.pwm().unwrap_or_default() as f64, min as f64, max as f64, 0f64, 100f64).round(),
|
||||
);
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_secs(4));
|
||||
|
Loading…
Reference in New Issue
Block a user