current_abs_max_tec_i from all channels, not 0 & 1

Helps if a thermostat was made with more than 2 channels.
This commit is contained in:
atse 2023-08-25 12:24:50 +08:00
parent 504fca8757
commit e344c11562
1 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,3 @@
use core::cmp::max_by;
use heapless::{consts::U2, Vec}; use heapless::{consts::U2, Vec};
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use smoltcp::time::Instant; use smoltcp::time::Instant;
@ -525,9 +524,14 @@ impl Channels {
} }
pub fn current_abs_max_tec_i(&mut self) -> ElectricCurrent { pub fn current_abs_max_tec_i(&mut self) -> ElectricCurrent {
max_by(self.get_tec_i(0).abs(), let mut max_abs_current = ElectricCurrent::new::<ampere>(0.0);
self.get_tec_i(1).abs(), for channel in 0..CHANNELS {
|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)) let channel_abs_current = self.get_tec_i(channel).abs();
if channel_abs_current > max_abs_current {
max_abs_current = channel_abs_current;
}
}
max_abs_current
} }
} }