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:
Hector Martin 2023-10-29 00:34:22 +09:00
parent 21023ec426
commit ac120b7be1

View file

@ -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