Skip to content

Commit 668dcc8

Browse files
authored
fix(hepa-uv): fix issue when turning on UV after re-seating the hepa/uv on the flex. (#802)
1 parent 241fb03 commit 668dcc8

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

include/hepa-uv/core/uv_task.hpp

+26-31
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class UVMessageHandler {
9191
debounce_timer.start();
9292

9393
// update states
94+
update_safety_relay_state();
9495
door_closed = gpio::is_set(drive_pins.door_open);
9596
reed_switch_set = gpio::is_set(drive_pins.reed_switch);
96-
update_safety_relay_state();
9797
if (m.pin == drive_pins.uv_push_button.pin)
9898
uv_push_button = !uv_push_button;
9999
}
@@ -120,14 +120,13 @@ class UVMessageHandler {
120120
}
121121

122122
void set_uv_light_state(bool light_on, uint32_t timeout_s = DELAY_S) {
123-
// reset push button state if the door is opened or the reed switch is
124-
// not set
123+
// set error state if the door is opened or the reed switch is not set
125124
if (!door_closed || !reed_switch_set) {
126125
if (_timer.is_running()) {
127126
gpio::reset(drive_pins.uv_on_off);
128127
_timer.stop();
129-
// send error message when door/reed state change while uv
130-
// is on
128+
129+
// send error message when door/reed is not set while uv is on
131130
auto resp = can::messages::ErrorMessage{
132131
.message_index = 0,
133132
.severity = can::ids::ErrorSeverity::unrecoverable,
@@ -150,6 +149,27 @@ class UVMessageHandler {
150149
return;
151150
}
152151

152+
// The safety relay needs to be active (Door Closed, Reed Switch set, and
153+
// Push Button pressed) in order to turn on the UV Light. So Send an
154+
// error if the safety relay is not active when trying to turn on the light.
155+
update_safety_relay_state();
156+
if (light_on && !safety_relay_active) {
157+
if (_timer.is_running()) _timer.stop();
158+
gpio::reset(drive_pins.uv_on_off);
159+
auto msg = can::messages::ErrorMessage{
160+
.message_index = 0,
161+
.severity = can::ids::ErrorSeverity::warning,
162+
.error_code = can::ids::ErrorCode::safety_relay_inactive,
163+
};
164+
can_client.send_can_message(can::ids::NodeId::host, msg);
165+
led_control_client.send_led_control_message(
166+
led_control_task_messages::PushButtonLED(UV_BUTTON, 0, 0, 50,
167+
0));
168+
169+
uv_light_on = false;
170+
return;
171+
}
172+
153173
// set the UV Ballast
154174
uv_light_on = (light_on && timeout_s > 0);
155175
// update the push button state
@@ -166,41 +186,16 @@ class UVMessageHandler {
166186
_timer.start();
167187
} else {
168188
gpio::reset(drive_pins.uv_on_off);
189+
if (_timer.is_running()) _timer.stop();
169190
// Set the push button LED's to idle (white)
170191
led_control_client.send_led_control_message(
171192
led_control_task_messages::PushButtonLED(UV_BUTTON, 0, 0, 0,
172193
50));
173-
if (_timer.is_running()) _timer.stop();
174194
}
175195

176196
// wait 10ms for safety relay, then update the states
177197
ot_utils::freertos_sleep::sleep(100);
178198
uv_current_ma = uv_hardware.get_uv_light_current();
179-
update_safety_relay_state();
180-
if (uv_light_on && !safety_relay_active) {
181-
// we tried to set the uv light, but the relay is not active
182-
if (_timer.is_running()) {
183-
gpio::reset(drive_pins.uv_on_off);
184-
_timer.stop();
185-
led_control_client.send_led_control_message(
186-
led_control_task_messages::PushButtonLED(UV_BUTTON, 0, 0,
187-
50, 0));
188-
}
189-
// send error
190-
auto msg = can::messages::ErrorMessage{
191-
.message_index = 0,
192-
.severity = can::ids::ErrorSeverity::warning,
193-
.error_code = can::ids::ErrorCode::safety_relay_inactive,
194-
};
195-
can_client.send_can_message(can::ids::NodeId::host, msg);
196-
197-
uv_push_button = false;
198-
uv_light_on = false;
199-
uv_current_ma = 0;
200-
return;
201-
}
202-
203-
// TODO: send state change CAN message to host
204199
}
205200

206201
// state tracking variables

0 commit comments

Comments
 (0)