From c214e4182d1a0c07fc8681331a1f97730da04213 Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 7 Aug 2024 11:17:06 +0800 Subject: [PATCH] temp_mon: fix limits not effective at stable temp - previously, temp is stable, temp limits are not checked --- src/thermostat/temp_mon.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/thermostat/temp_mon.rs b/src/thermostat/temp_mon.rs index 8992e7e..7a335e8 100644 --- a/src/thermostat/temp_mon.rs +++ b/src/thermostat/temp_mon.rs @@ -32,6 +32,7 @@ pub struct TempMon { state: State, count: u32, is_set_point_changed: bool, + is_limit_changed: bool, } impl Default for TempMon { @@ -48,6 +49,7 @@ impl Default for TempMon { count: 0, // stable_temp_count: 0, is_set_point_changed: false, + is_limit_changed: false, } } } @@ -68,6 +70,7 @@ impl TempMon { pub fn set_upper_limit(&mut self, upper_limit: ThermodynamicTemperature) { self.upper_limit = upper_limit; + self.is_limit_changed = true; } pub fn get_upper_limit(&mut self) -> ThermodynamicTemperature { @@ -76,6 +79,7 @@ impl TempMon { pub fn set_lower_limit(&mut self, lower_limit: ThermodynamicTemperature) { self.lower_limit = lower_limit; + self.is_limit_changed = true; } pub fn get_lower_limit(&mut self) -> ThermodynamicTemperature { @@ -129,11 +133,9 @@ impl TempMon { } } State::PidStartUp | State::PidStable => { - let is_over_temp: bool; - if self.state == State::PidStartUp { - is_over_temp = temp > self.upper_limit || temp < self.lower_limit; - } else { - is_over_temp = (temp.value - self.set_point.value).abs() > 0.5; + let mut is_over_temp = temp > self.upper_limit || temp < self.lower_limit; + if self.state != State::PidStartUp { + is_over_temp = is_over_temp || (temp.value - self.set_point.value).abs() > 0.5; } let is_within_spec: bool = (temp.value - self.set_point.value).abs() < 0.001; @@ -163,6 +165,12 @@ impl TempMon { } else if self.is_set_point_changed { self.is_set_point_changed = false; self.state = State::PidStartUp; + } else if self.is_limit_changed { + self.is_limit_changed = false; + if is_over_temp { + self.state = State::PidStartUp; + self.count = 0; + } } else if self.status.status == TempStatusEnum::Stable { self.state = State::PidStable; } else if !pid_engaged {