@@ -91,9 +91,9 @@ class UVMessageHandler {
91
91
debounce_timer.start ();
92
92
93
93
// update states
94
+ update_safety_relay_state ();
94
95
door_closed = gpio::is_set (drive_pins.door_open );
95
96
reed_switch_set = gpio::is_set (drive_pins.reed_switch );
96
- update_safety_relay_state ();
97
97
if (m.pin == drive_pins.uv_push_button .pin )
98
98
uv_push_button = !uv_push_button;
99
99
}
@@ -120,14 +120,13 @@ class UVMessageHandler {
120
120
}
121
121
122
122
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
125
124
if (!door_closed || !reed_switch_set) {
126
125
if (_timer.is_running ()) {
127
126
gpio::reset (drive_pins.uv_on_off );
128
127
_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
131
130
auto resp = can::messages::ErrorMessage{
132
131
.message_index = 0 ,
133
132
.severity = can::ids::ErrorSeverity::unrecoverable,
@@ -150,6 +149,27 @@ class UVMessageHandler {
150
149
return ;
151
150
}
152
151
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
+
153
173
// set the UV Ballast
154
174
uv_light_on = (light_on && timeout_s > 0 );
155
175
// update the push button state
@@ -166,41 +186,16 @@ class UVMessageHandler {
166
186
_timer.start ();
167
187
} else {
168
188
gpio::reset (drive_pins.uv_on_off );
189
+ if (_timer.is_running ()) _timer.stop ();
169
190
// Set the push button LED's to idle (white)
170
191
led_control_client.send_led_control_message (
171
192
led_control_task_messages::PushButtonLED (UV_BUTTON, 0 , 0 , 0 ,
172
193
50 ));
173
- if (_timer.is_running ()) _timer.stop ();
174
194
}
175
195
176
196
// wait 10ms for safety relay, then update the states
177
197
ot_utils::freertos_sleep::sleep (100 );
178
198
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
204
199
}
205
200
206
201
// state tracking variables
0 commit comments