From 136c7a0b5240c830ff06e8458dcec350cc3a61f6 Mon Sep 17 00:00:00 2001 From: atse Date: Fri, 25 Aug 2023 12:24:50 +0800 Subject: [PATCH] Calculate current_abs_max_tec_i from all channels Instead of picking channels 0 and 1. Helps to generalise for more than 2 channels. --- src/channels.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index 40c8af7..a428dd1 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -1,4 +1,4 @@ -use core::{cmp::max_by, marker::PhantomData}; +use core::marker::PhantomData; use heapless::{consts::U2, Vec}; use num_traits::Zero; use serde::{Serialize, Serializer}; @@ -561,9 +561,10 @@ impl Channels { } pub fn current_abs_max_tec_i(&mut self) -> ElectricCurrent { - max_by(self.get_tec_i(0).abs(), - self.get_tec_i(1).abs(), - |a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)) + (0..CHANNELS) + .map(|channel| self.get_tec_i(channel).abs()) + .max_by(|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)) + .unwrap() } }