From bc7bf9a6e75d8adf0370196a2476f3410623b351 Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 17 Jan 2024 17:01:25 +0800 Subject: [PATCH] rename channel_state -> pid_state --- src/thermostat/mod.rs | 2 +- src/thermostat/{channel_state.rs => pid_state.rs} | 12 ++++++------ src/thermostat/thermostat.rs | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) rename src/thermostat/{channel_state.rs => pid_state.rs} (94%) diff --git a/src/thermostat/mod.rs b/src/thermostat/mod.rs index 6ae79b4..fc8e3b4 100644 --- a/src/thermostat/mod.rs +++ b/src/thermostat/mod.rs @@ -3,4 +3,4 @@ pub mod max1968; pub mod thermostat; pub mod ad7172; pub mod steinhart_hart; -pub mod channel_state; +pub mod pid_state; diff --git a/src/thermostat/channel_state.rs b/src/thermostat/pid_state.rs similarity index 94% rename from src/thermostat/channel_state.rs rename to src/thermostat/pid_state.rs index 3972ef9..8f2add9 100644 --- a/src/thermostat/channel_state.rs +++ b/src/thermostat/pid_state.rs @@ -20,7 +20,7 @@ use crate::pid::pid; const R_INNER: f64 = 2.0 * 5100.0; const VREF_SENS: f64 = 3.3 / 2.0; -pub struct ChannelState { +pub struct PidState { pub adc_data: Option, pub adc_calibration: ad7172::ChannelCalibration, pub adc_time: Instant, @@ -33,16 +33,16 @@ pub struct ChannelState { pub sh: sh::Parameters, } -impl ChannelState { +impl PidState { fn adc_calibration(mut self, adc_calibration: ad7172::ChannelCalibration) -> Self { self.adc_calibration = adc_calibration; self } } -impl Default for ChannelState { +impl Default for PidState { fn default() -> Self { - ChannelState { + PidState { adc_data: None, adc_calibration: ad7172::ChannelCalibration::default(), adc_time: Instant::from_secs(0), @@ -57,9 +57,9 @@ impl Default for ChannelState { } } -impl ChannelState { +impl PidState { pub fn new(adc_calibration: ad7172::ChannelCalibration) -> Self { - ChannelState::default().adc_calibration(adc_calibration) + PidState::default().adc_calibration(adc_calibration) } pub fn update(&mut self, now: Instant, adc_data: u32) { diff --git a/src/thermostat/thermostat.rs b/src/thermostat/thermostat.rs index 4e886dd..d96068d 100644 --- a/src/thermostat/thermostat.rs +++ b/src/thermostat/thermostat.rs @@ -4,7 +4,8 @@ use crate::sys_timer; use crate::thermostat::ad5680; use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum}; use crate::thermostat::ad7172; -use crate::thermostat::channel_state::ChannelState; +use crate::thermostat::pid_state::PidState; +use crate::thermostat::steinhart_hart; use log::info; use uom::si::{ electric_current::ampere, @@ -93,7 +94,7 @@ pub struct Thermostat { max1968: MAX1968, ad7172: ad7172::AdcPhy, pub tec_setting: Settings, - pid_ctrl_ch0: ChannelState, + pid_ctrl_ch0: PidState, } impl Thermostat{ @@ -102,7 +103,7 @@ impl Thermostat{ max1968: max1968, ad7172: ad7172, tec_setting: Settings::default(), - pid_ctrl_ch0: ChannelState::default(), + pid_ctrl_ch0: PidState::default(), } } pub fn setup(&mut self){ @@ -135,7 +136,7 @@ impl Thermostat{ pub fn poll_adc(&mut self, instant: Instant) -> Option { self.ad7172.data_ready().unwrap().map(|channel| { let data = self.ad7172.read_data().unwrap(); - let state: &mut ChannelState = &mut self.pid_ctrl_ch0; + let state: &mut PidState = &mut self.pid_ctrl_ch0; state.update(instant, data); match state.update_pid() { Some(pid_output) if state.pid_engaged => {