Move PwmLimits into its own file #123

Open
atse wants to merge 1 commits from atse/thermostat:refactor-pwm_limits into master
4 changed files with 37 additions and 32 deletions

View File

@ -16,7 +16,7 @@ use uom::si::{
use crate::{ use crate::{
ad7172, ad7172,
pid, pid,
config::PwmLimits, pwm_limits::PwmLimits,
steinhart_hart as sh, steinhart_hart as sh,
command_parser::{CenterPoint, Polarity}, command_parser::{CenterPoint, Polarity},
}; };

View File

@ -1,15 +1,12 @@
use num_traits::Zero; use num_traits::Zero;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use uom::si::{ use uom::si::f64::ElectricCurrent;
electric_potential::volt,
electric_current::ampere,
f64::{ElectricCurrent, ElectricPotential},
};
use crate::{ use crate::{
ad7172::PostFilter, ad7172::PostFilter,
channels::Channels, channels::Channels,
command_parser::{CenterPoint, Polarity}, command_parser::{CenterPoint, Polarity},
pid, pid,
pwm_limits::PwmLimits,
steinhart_hart, steinhart_hart,
}; };
@ -73,29 +70,3 @@ impl ChannelConfig {
channels.set_polarity(channel, self.polarity.clone()); 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::<volt>(),
max_i_pos: max_i_pos.get::<ampere>(),
max_i_neg: max_i_neg.get::<ampere>(),
}
}
pub fn apply(&self, channels: &mut Channels, channel: usize) {
channels.set_max_v(channel, ElectricPotential::new::<volt>(self.max_v));
channels.set_max_i_pos(channel, ElectricCurrent::new::<ampere>(self.max_i_pos));
channels.set_max_i_neg(channel, ElectricCurrent::new::<ampere>(self.max_i_neg));
}
}

View File

@ -41,6 +41,7 @@ mod command_parser;
use command_parser::Ipv4Config; use command_parser::Ipv4Config;
mod timer; mod timer;
mod pid; mod pid;
mod pwm_limits;
mod steinhart_hart; mod steinhart_hart;
mod channels; mod channels;
use channels::{CHANNELS, Channels}; use channels::{CHANNELS, Channels};

33
src/pwm_limits.rs Normal file
View File

@ -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::<volt>(),
max_i_pos: max_i_pos.get::<ampere>(),
max_i_neg: max_i_neg.get::<ampere>(),
}
}
pub fn apply(&self, channels: &mut Channels, channel: usize) {
channels.set_max_v(channel, ElectricPotential::new::<volt>(self.max_v));
channels.set_max_i_pos(channel, ElectricCurrent::new::<ampere>(self.max_i_pos));
channels.set_max_i_neg(channel, ElectricCurrent::new::<ampere>(self.max_i_neg));
}
}