From 6dcb77f7b59ce894bbb1ffec9064681155a3da4b Mon Sep 17 00:00:00 2001 From: ellensp Date: Mon, 8 Feb 2021 15:36:04 +1300 Subject: [PATCH] Fix mini12864 v2.1 + PSU control + NeoPixel backlight (#21021) --- Marlin/src/feature/leds/leds.cpp | 12 +++++++----- Marlin/src/feature/leds/leds.h | 2 +- Marlin/src/lcd/marlinui.cpp | 2 +- Marlin/src/lcd/menu/menu_led.cpp | 13 +++++++++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp index ef9099fb2..c8cbdec33 100644 --- a/Marlin/src/feature/leds/leds.cpp +++ b/Marlin/src/feature/leds/leds.cpp @@ -147,11 +147,13 @@ void LEDLights::set_color(const LEDColor &incol millis_t LEDLights::led_off_time; // = 0 void LEDLights::update_timeout(const bool power_on) { - const millis_t ms = millis(); - if (power_on) - reset_timeout(ms); - else if (ELAPSED(ms, led_off_time)) - set_off(); + if (lights_on) { + const millis_t ms = millis(); + if (power_on) + reset_timeout(ms); + else if (ELAPSED(ms, led_off_time)) + set_off(); + } } #endif diff --git a/Marlin/src/feature/leds/leds.h b/Marlin/src/feature/leds/leds.h index 57b21d576..d41c61144 100644 --- a/Marlin/src/feature/leds/leds.h +++ b/Marlin/src/feature/leds/leds.h @@ -203,7 +203,7 @@ public: public: static inline void reset_timeout(const millis_t &ms) { led_off_time = ms + LED_BACKLIGHT_TIMEOUT; - if (!lights_on) set_default(); + if (!lights_on) update(); } static void update_timeout(const bool power_on); #endif diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index eea697a46..eaee08f43 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -994,7 +994,7 @@ void MarlinUI::update() { refresh(LCDVIEW_REDRAW_NOW); #ifdef LED_BACKLIGHT_TIMEOUT - leds.reset_timeout(ms); + if (!powersupply_on) leds.reset_timeout(ms); #endif } diff --git a/Marlin/src/lcd/menu/menu_led.cpp b/Marlin/src/lcd/menu/menu_led.cpp index 552c03a69..de5750278 100644 --- a/Marlin/src/lcd/menu/menu_led.cpp +++ b/Marlin/src/lcd/menu/menu_led.cpp @@ -121,11 +121,20 @@ void menu_led() { BACK_ITEM(MSG_MAIN); #if ENABLED(LED_CONTROL_MENU) - editable.state = leds.lights_on; - EDIT_ITEM(bool, MSG_LEDS, &editable.state, leds.toggle); + #if ENABLED(PSU_CONTROL) + extern bool powersupply_on; + #else + constexpr bool powersupply_on = true; + #endif + if (powersupply_on) { + editable.state = leds.lights_on; + EDIT_ITEM(bool, MSG_LEDS, &editable.state, leds.toggle); + } + #if ENABLED(LED_COLOR_PRESETS) ACTION_ITEM(MSG_SET_LEDS_DEFAULT, leds.set_default); #endif + #if ENABLED(NEOPIXEL2_SEPARATE) editable.state = leds2.lights_on; EDIT_ITEM(bool, MSG_LEDS2, &editable.state, leds2.toggle);