Refactor current_abs_max_tec_i to use uom

This commit is contained in:
atse 2023-08-25 10:15:51 +08:00
parent 631a10938d
commit 03b4561142
3 changed files with 10 additions and 7 deletions

View File

@ -524,9 +524,9 @@ impl Channels {
serde_json_core::to_vec(&summaries) serde_json_core::to_vec(&summaries)
} }
pub fn current_abs_max_tec_i(&mut self) -> f64 { pub fn current_abs_max_tec_i(&mut self) -> ElectricCurrent {
max_by(self.get_tec_i(0).abs().get::<ampere>(), max_by(self.get_tec_i(0).abs(),
self.get_tec_i(1).abs().get::<ampere>(), self.get_tec_i(1).abs(),
|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)) |a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal))
} }
} }

View File

@ -4,7 +4,10 @@ use stm32f4xx_hal::{
pwm::{self, PwmChannels}, pwm::{self, PwmChannels},
pac::TIM8, pac::TIM8,
}; };
use uom::si::{
f64::ElectricCurrent,
electric_current::ampere,
};
use crate::{ use crate::{
hw_rev::HWSettings, hw_rev::HWSettings,
command_handler::JsonBuffer, command_handler::JsonBuffer,
@ -50,8 +53,8 @@ impl FanCtrl {
fan_ctrl fan_ctrl
} }
pub fn cycle(&mut self, abs_max_tec_i: f32) { pub fn cycle(&mut self, abs_max_tec_i: ElectricCurrent) {
self.abs_max_tec_i = abs_max_tec_i; self.abs_max_tec_i = abs_max_tec_i.get::<ampere>() as f32;
if self.fan_auto && self.hw_settings.fan_available { if self.fan_auto && self.hw_settings.fan_available {
let scaled_current = self.abs_max_tec_i / MAX_TEC_I; 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() // do not limit upper bound, as it will be limited in the set_pwm()

View File

@ -185,7 +185,7 @@ fn main() -> ! {
server.for_each(|_, session| session.set_report_pending(channel.into())); 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() { if channels.pid_engaged() {
leds.g3.on(); leds.g3.on();