refactoring based on Michael's comments

This commit is contained in:
proddy
2026-08-07 13:42:45 +02:00
parent 285361c09f
commit e22b82e913
+8 -5
View File
@@ -67,7 +67,6 @@ bool LED::loop(uint8_t healthcheck, bool button_busy) {
set_led(Color::YELLOW); // Yellow
} else {
reset_led();
previous_healthcheck_ = System::HEALTHCHECK_RESET;
}
return false;
}
@@ -75,7 +74,6 @@ bool LED::loop(uint8_t healthcheck, bool button_busy) {
// check the system health.
// Set the sequence accordingly, only if the healthcheck is not 0 and has changed
if (healthcheck != previous_healthcheck_) {
previous_healthcheck_ = healthcheck;
color_steps_[0] = Color::OFF;
color_steps_[1] = Color::OFF;
color_steps_[2] = Color::OFF;
@@ -83,9 +81,7 @@ bool LED::loop(uint8_t healthcheck, bool button_busy) {
// if the healthcheck is 0, i.e. system is healthy, reset the LED
if (healthcheck == 0) {
reset_led();
return false;
}
} else {
// 1 flash (blue) is the EMS bus is not connected
// 2 flashes (red, red) if the network (wifi or ethernet) is not connected
// 3 flashes (red, red, blue) is both the bus and the network are not connected
@@ -110,6 +106,9 @@ bool LED::loop(uint8_t healthcheck, bool button_busy) {
}
}
previous_healthcheck_ = healthcheck; // must be set after reset_led(), which invalidates it
}
// there's nothing to flash, so leave the LED in the state reset_led() gave it.
// Running the sequence here would keep writing Color::OFF and a healthy system would never show green.
if (healthcheck == 0 || button_busy) {
@@ -131,6 +130,10 @@ void LED::reset_led() {
color_steps_[1] = Color::OFF;
color_steps_[2] = Color::OFF;
// invalidate the last health state so the sequence is rebuilt on the next check,
// needed because the color steps above have been cleared
previous_healthcheck_ = System::HEALTHCHECK_RESET;
// rewind the sequence so it starts from the top if the health degrades again
led_long_timer_ = 1; // 1 will kick it off immediately
led_short_timer_ = 0;