From a506876995a5db01e764bc028935bc5a0f1c6e23 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 | 29 ++--------------------------- src/main.rs | 1 + src/pwm_limits.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 src/pwm_limits.rs diff --git a/src/channel_state.rs b/src/channel_state.rs index 62a2648..e90285f 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -1,8 +1,8 @@ use crate::{ ad7172, b_parameter as bp, command_parser::{CenterPoint, Polarity}, - config::PwmLimits, pid, + pwm_limits::PwmLimits, }; use num_traits::Zero; use smoltcp::time::{Duration, Instant}; diff --git a/src/config.rs b/src/config.rs index 7c813f4..b58fb26 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,10 +4,11 @@ use crate::{ channels::Channels, command_parser::{CenterPoint, Polarity}, pid, + pwm_limits::PwmLimits, }; use num_traits::Zero; use serde::{Deserialize, Serialize}; -use uom::si::f64::{ElectricCurrent, ElectricPotential}; +use uom::si::f64::ElectricCurrent; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ChannelConfig { @@ -71,29 +72,3 @@ impl ChannelConfig { channels.set_polarity(channel, self.polarity.clone()); } } - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct PwmLimits { - pub max_v: ElectricPotential, - pub max_i_pos: ElectricCurrent, - pub max_i_neg: ElectricCurrent, -} - -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_i_pos, - max_i_neg, - } - } - - pub fn apply(&self, channels: &mut Channels, channel: usize) { - channels.set_max_v(channel, self.max_v); - channels.set_max_i_pos(channel, self.max_i_pos); - channels.set_max_i_neg(channel, self.max_i_neg); - } -} diff --git a/src/main.rs b/src/main.rs index aa07c0a..69542ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ use command_parser::Ipv4Config; mod b_parameter; mod channels; mod pid; +mod pwm_limits; mod timer; use channels::{Channels, CHANNELS}; mod channel; diff --git a/src/pwm_limits.rs b/src/pwm_limits.rs new file mode 100644 index 0000000..3830a3d --- /dev/null +++ b/src/pwm_limits.rs @@ -0,0 +1,26 @@ +use crate::channels::Channels; +use serde::{Deserialize, Serialize}; +use uom::si::f64::{ElectricCurrent, ElectricPotential}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct PwmLimits { + pub max_v: ElectricPotential, + pub max_i_pos: ElectricCurrent, + pub max_i_neg: ElectricCurrent, +} + +impl PwmLimits { + pub fn new(channels: &mut Channels, channel: usize) -> Self { + PwmLimits { + max_v: channels.get_max_v(channel), + max_i_pos: channels.get_max_i_pos(channel), + max_i_neg: channels.get_max_i_neg(channel), + } + } + + pub fn apply(&self, channels: &mut Channels, channel: usize) { + channels.set_max_v(channel, self.max_v); + channels.set_max_i_pos(channel, self.max_i_pos); + channels.set_max_i_neg(channel, self.max_i_neg); + } +}