1
0
Fork 0

temp_mon: Add support for constant current mode

This commit is contained in:
linuswck 2024-03-19 13:10:23 +08:00
parent 048245f674
commit 99cf17f7e4
2 changed files with 43 additions and 12 deletions

View File

@ -11,6 +11,7 @@ pub enum TempStatusEnum {
OverTemp,
Unstable,
Stable,
ConstantCurrentMode,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
@ -56,7 +57,8 @@ impl Default for TempMon {
#[derive(Default, PartialEq, Debug)]
enum State {
#[default]
PidOff,
PwrOff,
ConstantCurrentMode,
PidStartUp,
PidStable,
OverTempAlarm,
@ -95,16 +97,38 @@ impl TempMon {
self.state = State::default();
}
pub fn update_status(&mut self, pid_engaged: bool, temp: ThermodynamicTemperature) {
pub fn update_status(&mut self, pid_engaged: bool, pwr_on: bool, temp: ThermodynamicTemperature) {
match self.state {
State::PidOff => {
State::PwrOff => {
self.is_set_point_changed = false;
self.status.status = TempStatusEnum::Off;
self.count = 0;
// State Transition
if pid_engaged {
if pwr_on {
if pid_engaged {
self.state = State::PidStartUp;
} else {
self.state = State::ConstantCurrentMode
}
}
}
State::ConstantCurrentMode => {
let is_over_temp = temp > self.upper_limit || temp < self.lower_limit;
self.status.status = TempStatusEnum::ConstantCurrentMode;
if is_over_temp {
self.state = State::OverTempAlarm;
self.status.status = TempStatusEnum::OverTemp;
}
else if !pwr_on {
self.state = State::PwrOff;
self.status.status = TempStatusEnum::Off;
} else if pid_engaged {
self.state = State::PidStartUp;
self.status.status = TempStatusEnum::Unstable;
self.is_set_point_changed = false;
}
}
State::PidStartUp | State::PidStable => {
@ -134,13 +158,20 @@ impl TempMon {
}
// State Transition
if self.status.status == TempStatusEnum::OverTemp {
self.state = State::OverTempAlarm;
} else if self.is_set_point_changed {
self.is_set_point_changed = false;
self.state = State::PidStartUp;
} else if self.status.status == TempStatusEnum::Stable {
self.state = State::PidStable;
if !pwr_on {
self.state = State::PwrOff;
}
else {
if self.status.status == TempStatusEnum::OverTemp {
self.state = State::OverTempAlarm;
} else if self.is_set_point_changed {
self.is_set_point_changed = false;
self.state = State::PidStartUp;
} else if self.status.status == TempStatusEnum::Stable {
self.state = State::PidStable;
} else if !pid_engaged {
self.state = State::ConstantCurrentMode
}
}
}
State::OverTempAlarm => {

View File

@ -186,7 +186,7 @@ impl Thermostat{
state.update(data);
let pid_engaged = state.get_pid_engaged();
let temp = self.get_temperature();
self.temp_mon.update_status(pid_engaged, temp);
self.temp_mon.update_status(pid_engaged, self.max1968.is_powered_on(), temp);
debug!("state.get_pid_engaged(): {:?}", pid_engaged);
debug!("Temperature: {:?} degree", temp.get::<degree_celsius>());
data_rdy = true;