Turn off LED L3 only when all channels have no PID #78

Merged
sb10q merged 1 commits from atse/thermostat:l3-led-fix into master 2023-08-07 16:15:25 +08:00
2 changed files with 13 additions and 1 deletions

View File

@ -475,6 +475,15 @@ impl Channels {
serde_json_core::to_vec(&summaries)
}
pub fn pid_engaged(&mut self) -> bool {
for channel in 0..CHANNELS {
if self.channel_state(channel).pid_engaged {
return true;
}
}
false
}
fn pwm_summary(&mut self, channel: usize) -> PwmSummary {
PwmSummary {
channel,

View File

@ -187,7 +187,10 @@ impl Handler {
match pin {
PwmPin::ISet => {
channels.channel_state(channel).pid_engaged = false;
leds.g3.off();
// Only turn off LED when PID is disengaged on all channels
if !channels.pid_engaged() {
leds.g3.off();
}
let current = ElectricCurrent::new::<ampere>(value);
channels.set_i(channel, current);
channels.power_up(channel);