From 03b45611425ca86d85811b7c5fb8d56117a47279 Mon Sep 17 00:00:00 2001 From: atse Date: Fri, 25 Aug 2023 10:15:51 +0800 Subject: [PATCH] Refactor current_abs_max_tec_i to use uom --- src/channels.rs | 6 +++--- src/fan_ctrl.rs | 9 ++++++--- src/main.rs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index a90d886..019c9ad 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -524,9 +524,9 @@ impl Channels { serde_json_core::to_vec(&summaries) } - pub fn current_abs_max_tec_i(&mut self) -> f64 { - max_by(self.get_tec_i(0).abs().get::(), - self.get_tec_i(1).abs().get::(), + 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)) } } diff --git a/src/fan_ctrl.rs b/src/fan_ctrl.rs index b95a723..30416f3 100644 --- a/src/fan_ctrl.rs +++ b/src/fan_ctrl.rs @@ -4,7 +4,10 @@ use stm32f4xx_hal::{ pwm::{self, PwmChannels}, pac::TIM8, }; - +use uom::si::{ + f64::ElectricCurrent, + electric_current::ampere, +}; use crate::{ hw_rev::HWSettings, command_handler::JsonBuffer, @@ -50,8 +53,8 @@ impl FanCtrl { fan_ctrl } - pub fn cycle(&mut self, abs_max_tec_i: f32) { - self.abs_max_tec_i = abs_max_tec_i; + pub fn cycle(&mut self, abs_max_tec_i: ElectricCurrent) { + self.abs_max_tec_i = abs_max_tec_i.get::() as f32; if self.fan_auto && self.hw_settings.fan_available { let scaled_current = self.abs_max_tec_i / MAX_TEC_I; // do not limit upper bound, as it will be limited in the set_pwm() diff --git a/src/main.rs b/src/main.rs index 3c01d74..353a161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -185,7 +185,7 @@ fn main() -> ! { server.for_each(|_, session| session.set_report_pending(channel.into())); } - fan_ctrl.cycle(channels.current_abs_max_tec_i() as f32); + fan_ctrl.cycle(channels.current_abs_max_tec_i()); if channels.pid_engaged() { leds.g3.on();