forked from M-Labs/kirdy
rename channel_state -> pid_state
This commit is contained in:
parent
ca110962f7
commit
bc7bf9a6e7
|
@ -3,4 +3,4 @@ pub mod max1968;
|
||||||
pub mod thermostat;
|
pub mod thermostat;
|
||||||
pub mod ad7172;
|
pub mod ad7172;
|
||||||
pub mod steinhart_hart;
|
pub mod steinhart_hart;
|
||||||
pub mod channel_state;
|
pub mod pid_state;
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::pid::pid;
|
||||||
const R_INNER: f64 = 2.0 * 5100.0;
|
const R_INNER: f64 = 2.0 * 5100.0;
|
||||||
const VREF_SENS: f64 = 3.3 / 2.0;
|
const VREF_SENS: f64 = 3.3 / 2.0;
|
||||||
|
|
||||||
pub struct ChannelState {
|
pub struct PidState {
|
||||||
pub adc_data: Option<u32>,
|
pub adc_data: Option<u32>,
|
||||||
pub adc_calibration: ad7172::ChannelCalibration,
|
pub adc_calibration: ad7172::ChannelCalibration,
|
||||||
pub adc_time: Instant,
|
pub adc_time: Instant,
|
||||||
|
@ -33,16 +33,16 @@ pub struct ChannelState {
|
||||||
pub sh: sh::Parameters,
|
pub sh: sh::Parameters,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelState {
|
impl PidState {
|
||||||
fn adc_calibration(mut self, adc_calibration: ad7172::ChannelCalibration) -> Self {
|
fn adc_calibration(mut self, adc_calibration: ad7172::ChannelCalibration) -> Self {
|
||||||
self.adc_calibration = adc_calibration;
|
self.adc_calibration = adc_calibration;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ChannelState {
|
impl Default for PidState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ChannelState {
|
PidState {
|
||||||
adc_data: None,
|
adc_data: None,
|
||||||
adc_calibration: ad7172::ChannelCalibration::default(),
|
adc_calibration: ad7172::ChannelCalibration::default(),
|
||||||
adc_time: Instant::from_secs(0),
|
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 {
|
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) {
|
pub fn update(&mut self, now: Instant, adc_data: u32) {
|
|
@ -4,7 +4,8 @@ use crate::sys_timer;
|
||||||
use crate::thermostat::ad5680;
|
use crate::thermostat::ad5680;
|
||||||
use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum};
|
use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum};
|
||||||
use crate::thermostat::ad7172;
|
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 log::info;
|
||||||
use uom::si::{
|
use uom::si::{
|
||||||
electric_current::ampere,
|
electric_current::ampere,
|
||||||
|
@ -93,7 +94,7 @@ pub struct Thermostat {
|
||||||
max1968: MAX1968,
|
max1968: MAX1968,
|
||||||
ad7172: ad7172::AdcPhy,
|
ad7172: ad7172::AdcPhy,
|
||||||
pub tec_setting: Settings,
|
pub tec_setting: Settings,
|
||||||
pid_ctrl_ch0: ChannelState,
|
pid_ctrl_ch0: PidState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Thermostat{
|
impl Thermostat{
|
||||||
|
@ -102,7 +103,7 @@ impl Thermostat{
|
||||||
max1968: max1968,
|
max1968: max1968,
|
||||||
ad7172: ad7172,
|
ad7172: ad7172,
|
||||||
tec_setting: Settings::default(),
|
tec_setting: Settings::default(),
|
||||||
pid_ctrl_ch0: ChannelState::default(),
|
pid_ctrl_ch0: PidState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn setup(&mut self){
|
pub fn setup(&mut self){
|
||||||
|
@ -135,7 +136,7 @@ impl Thermostat{
|
||||||
pub fn poll_adc(&mut self, instant: Instant) -> Option<u8> {
|
pub fn poll_adc(&mut self, instant: Instant) -> Option<u8> {
|
||||||
self.ad7172.data_ready().unwrap().map(|channel| {
|
self.ad7172.data_ready().unwrap().map(|channel| {
|
||||||
let data = self.ad7172.read_data().unwrap();
|
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);
|
state.update(instant, data);
|
||||||
match state.update_pid() {
|
match state.update_pid() {
|
||||||
Some(pid_output) if state.pid_engaged => {
|
Some(pid_output) if state.pid_engaged => {
|
||||||
|
|
Loading…
Reference in New Issue