From 16e91e8103c9f1eb3d2228a2d78661696c62ec98 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 8 Aug 2024 17:39:55 +0800 Subject: [PATCH] Move PwmLimits into its own file --- src/channel_state.rs | 2 +- src/config.rs | 33 ++------------------------------- src/main.rs | 1 + src/pwm_limits.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 src/pwm_limits.rs diff --git a/src/channel_state.rs b/src/channel_state.rs index d4c46a1..0f23399 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -16,7 +16,7 @@ use uom::si::{ use crate::{ ad7172, pid, - config::PwmLimits, + pwm_limits::PwmLimits, steinhart_hart as sh, command_parser::{CenterPoint, Polarity}, }; diff --git a/src/config.rs b/src/config.rs index 65b511d..3549255 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,15 +1,12 @@ use num_traits::Zero; use serde::{Serialize, Deserialize}; -use uom::si::{ - electric_potential::volt, - electric_current::ampere, - f64::{ElectricCurrent, ElectricPotential}, -}; +use uom::si::f64::ElectricCurrent; use crate::{ ad7172::PostFilter, channels::Channels, command_parser::{CenterPoint, Polarity}, pid, + pwm_limits::PwmLimits, steinhart_hart, }; @@ -73,29 +70,3 @@ impl ChannelConfig { channels.set_polarity(channel, self.polarity.clone()); } } - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct PwmLimits { - pub max_v: f64, - pub max_i_pos: f64, - pub max_i_neg: f64, -} - -impl PwmLimits { - pub fn new(channels: &mut Channels, channel: usize) -> Self { - let max_v = channels.get_max_v(channel); - let max_i_pos = channels.get_max_i_pos(channel); - let max_i_neg = channels.get_max_i_neg(channel); - PwmLimits { - max_v: max_v.get::(), - max_i_pos: max_i_pos.get::(), - max_i_neg: max_i_neg.get::(), - } - } - - pub fn apply(&self, channels: &mut Channels, channel: usize) { - channels.set_max_v(channel, ElectricPotential::new::(self.max_v)); - channels.set_max_i_pos(channel, ElectricCurrent::new::(self.max_i_pos)); - channels.set_max_i_neg(channel, ElectricCurrent::new::(self.max_i_neg)); - } -} diff --git a/src/main.rs b/src/main.rs index 7c874e9..fe2bb91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,7 @@ mod command_parser; use command_parser::Ipv4Config; mod timer; mod pid; +mod pwm_limits; mod steinhart_hart; mod channels; use channels::{CHANNELS, Channels}; diff --git a/src/pwm_limits.rs b/src/pwm_limits.rs new file mode 100644 index 0000000..4e3d717 --- /dev/null +++ b/src/pwm_limits.rs @@ -0,0 +1,33 @@ +use serde::{Serialize, Deserialize}; +use uom::si::{ + electric_potential::volt, + electric_current::ampere, + f64::{ElectricCurrent, ElectricPotential}, +}; +use crate::channels::Channels; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct PwmLimits { + pub max_v: f64, + pub max_i_pos: f64, + pub max_i_neg: f64, +} + +impl PwmLimits { + pub fn new(channels: &mut Channels, channel: usize) -> Self { + let max_v = channels.get_max_v(channel); + let max_i_pos = channels.get_max_i_pos(channel); + let max_i_neg = channels.get_max_i_neg(channel); + PwmLimits { + max_v: max_v.get::(), + max_i_pos: max_i_pos.get::(), + max_i_neg: max_i_neg.get::(), + } + } + + pub fn apply(&self, channels: &mut Channels, channel: usize) { + channels.set_max_v(channel, ElectricPotential::new::(self.max_v)); + channels.set_max_i_pos(channel, ElectricCurrent::new::(self.max_i_pos)); + channels.set_max_i_neg(channel, ElectricCurrent::new::(self.max_i_neg)); + } +} \ No newline at end of file