mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-10 02:15:16 +03:00
types: Test for negative powers
Disallow nontrivial negative power, but clamp down rounding error to avoid flickering signs in debug logs. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
21023ec426
commit
ac120b7be1
12
src/types.rs
12
src/types.rs
|
@ -358,6 +358,18 @@ impl Speaker {
|
|||
}
|
||||
|
||||
let pwr_avg: f32 = pwr_sum / ((buf.len() / self.g.channels) as f32);
|
||||
/*
|
||||
* This really shouldn't happen other than rounding error,
|
||||
* if it does there's probably something wrong with the ivsense
|
||||
* data.
|
||||
*/
|
||||
if pwr_avg < -0.01 {
|
||||
panic!(
|
||||
"{}: Negative power, bad ivsense data? ({})",
|
||||
self.name, pwr_avg
|
||||
);
|
||||
}
|
||||
let pwr_avg = pwr_avg.max(0.0);
|
||||
|
||||
s.t_coil_hyst = s
|
||||
.t_coil_hyst
|
||||
|
|
Loading…
Reference in a new issue