28 lines
1.0 KiB
Diff
28 lines
1.0 KiB
Diff
--- a/src/main.rs
|
|
+++ b/src/main.rs
|
|
@@ -174,19 +174,20 @@ fn start_temp_loop(
|
|
}
|
|
}
|
|
|
|
- let sum_temp: u16 = temps.iter().map(|t| *t as u16).sum();
|
|
- let mean_temp = sum_temp / (temps.len() as u16);
|
|
- if mean_temp == last_temp {
|
|
+ // Max over the rolling window tracks spikes; the upstream mean can lag several
|
|
+ // seconds behind bursty GPU/CPU load.
|
|
+ let control_temp = temps.iter().copied().max().expect("non-empty after push_back");
|
|
+ if control_temp == last_temp {
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
was_long_sleep = true;
|
|
} else {
|
|
- last_temp = mean_temp;
|
|
+ last_temp = control_temp;
|
|
for fan in fans {
|
|
- fan.set_speed(fan.calc_speed(mean_temp as u8))?;
|
|
+ fan.set_speed(fan.calc_speed(control_temp))?;
|
|
}
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
was_long_sleep = false;
|
|
}
|
|
}
|