From b04a61c414ad3de9d6ce0540ec67b1e28e8bb84d Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 7 Aug 2023 13:28:51 +0800 Subject: [PATCH] Turn off LED L3 only when all channels have no PID Change the behaviour of LED L3 to turn off only when all channels have PID disengaged, as opposed to when any channel disengages PID. Otherwise, when disengaging PID on a Thermostat that has had both channels engaged in PID, the LED would turn off, even when PID is still engaged on the other channel. This lets the LED better reflect the status of the Thermostat as a whole, as it would stay on as long as PID is engaged on at least one channel. --- src/channels.rs | 9 +++++++++ src/command_handler.rs | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/channels.rs b/src/channels.rs index c86305d..3b70a6f 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -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, diff --git a/src/command_handler.rs b/src/command_handler.rs index b2d3ae0..a0cca45 100644 --- a/src/command_handler.rs +++ b/src/command_handler.rs @@ -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::(value); channels.set_i(channel, current); channels.power_up(channel);