From d0b4f8cee5d829fa5877184f789b340564278749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 2 Feb 2024 10:57:18 +0100 Subject: [PATCH] just use 0 weight, no need for option --- src/main.rs | 5 +++-- src/output_channel.rs | 16 +++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 26a953f..0b2c85a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,10 +164,11 @@ mod app { if thermostat.adc_channels[phy_i][ch_i] { telemetry.alarm[phy_i][ch_i] = Some(false); telemetry.statistics[phy_i][ch_i] = Some(Default::default()); - settings.alarm.temperature_limits[phy_i][ch_i] = Some([f32::MIN, f32::MAX]); + settings.alarm.temperature_limits[phy_i][ch_i] = + Some([f32::NEG_INFINITY, f32::INFINITY]); // Initialize the output weights. for ch in settings.output_channel.iter_mut() { - ch.weights[phy_i][ch_i] = Some(0.); + ch.weights[phy_i][ch_i] = 0.; } } } diff --git a/src/output_channel.rs b/src/output_channel.rs index 35fa7ad..64cf217 100644 --- a/src/output_channel.rs +++ b/src/output_channel.rs @@ -46,7 +46,7 @@ pub struct OutputChannel { /// # Value /// f32 #[tree(depth(2))] - pub weights: [[Option; 4]; 4], + pub weights: [[f32; 4]; 4], } impl Default for OutputChannel { @@ -56,7 +56,7 @@ impl Default for OutputChannel { hold: false, voltage_limit: 0.0, iir: iir::Biquad::default(), - weights: [[None; 4]; 4], + weights: [[0.0; 4]; 4], } } } @@ -73,7 +73,7 @@ impl OutputChannel { .flatten() .zip(self.weights.iter().flatten()) // weight is `None` if temperature is invalid (phy cfg absent) - .map(|(t, w)| t * w.unwrap_or(0.) as f64) + .map(|(t, w)| t * *w as f64) .sum(); if self.shutdown || self.hold { iir::Biquad::HOLD.update(iir_state, weighted_temperature) as f32 @@ -101,15 +101,13 @@ impl OutputChannel { let divisor: f32 = self .weights .iter() - .map(|w| w.iter().map(|w| w.unwrap_or(0.).abs()).sum::()) + .map(|w| w.iter().map(|w| w.abs()).sum::()) .sum(); // Note: The weights which are not 'None' should always affect an enabled channel and therefore count for normalization. if divisor != 0.0 { - self.weights.iter_mut().flatten().for_each(|w| { - if let Some(w) = w { - *w /= divisor - } - }); + for w in self.weights.iter_mut().flatten() { + *w /= divisor; + } } [ // [Pwm::MAX_CURRENT_LIMIT] + 5% is still below 100% duty cycle for the PWM limits and therefore OK.