From f7efe6f6c5fc57ff1bdfd3dee6ccd751898d5e84 Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Tue, 12 Feb 2019 00:27:59 +0100 Subject: [PATCH] [2.0.x] Fix TEMP_STAT_LED startup init (#13120) --- Marlin/src/feature/leds/tempstat.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Marlin/src/feature/leds/tempstat.cpp b/Marlin/src/feature/leds/tempstat.cpp index 8a5a4a0b70..190df69c5c 100644 --- a/Marlin/src/feature/leds/tempstat.cpp +++ b/Marlin/src/feature/leds/tempstat.cpp @@ -32,26 +32,24 @@ #include "../../module/temperature.h" void handle_status_leds(void) { - static uint8_t red_led = LOW; + static int8_t old_red = -1; // Invalid value to force LED initialization static millis_t next_status_led_update_ms = 0; if (ELAPSED(millis(), next_status_led_update_ms)) { next_status_led_update_ms += 500; // Update every 0.5s float max_temp = 0.0; #if HAS_HEATED_BED - max_temp = MAX(max_temp, thermalManager.degTargetBed(), thermalManager.degBed()); + max_temp = MAX(thermalManager.degTargetBed(), thermalManager.degBed()); #endif HOTEND_LOOP() max_temp = MAX(max_temp, thermalManager.degHotend(e), thermalManager.degTargetHotend(e)); - const uint8_t new_led = (max_temp > 55.0) ? HIGH : (max_temp < 54.0) ? LOW : red_led; - if (new_led != red_led) { - red_led = new_led; + const int8_t new_red = (max_temp > 55.0) ? HIGH : (max_temp < 54.0 || old_red < 0) ? LOW : old_red; + if (new_red != old_red) { + old_red = new_red; #if PIN_EXISTS(STAT_LED_RED) - WRITE(STAT_LED_RED_PIN, new_led); - #if PIN_EXISTS(STAT_LED_BLUE) - WRITE(STAT_LED_BLUE_PIN, !new_led); - #endif - #else - WRITE(STAT_LED_BLUE_PIN, new_led); + WRITE(STAT_LED_RED_PIN, new_red); + #endif + #if PIN_EXISTS(STAT_LED_BLUE) + WRITE(STAT_LED_BLUE_PIN, !new_red); #endif } }