From 0e7be8e8c4b1a7ca351ce19b462cac2d27fab82d Mon Sep 17 00:00:00 2001 From: "M. FURIC Franck" Date: Sat, 26 Feb 2022 23:54:04 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20LCD=20Backlight=20Timer=20(#23768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 2 +- Marlin/Configuration_adv.h | 5 ++++ Marlin/src/inc/SanityCheck.h | 8 ++++++ Marlin/src/lcd/language/language_en.h | 1 + Marlin/src/lcd/language/language_fr.h | 1 + Marlin/src/lcd/marlinui.cpp | 24 ++++++++++++++-- Marlin/src/lcd/marlinui.h | 8 ++++++ Marlin/src/lcd/menu/menu_configuration.cpp | 4 +++ Marlin/src/module/settings.cpp | 32 ++++++++++++++++++++++ 9 files changed, 82 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 6f7b1bdf4a30..7162e74acbcf 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2820,7 +2820,7 @@ #define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus - //#define TOUCH_IDLE_SLEEP 300 // (secs) Turn off the TFT backlight if set (5mn) + //#define TOUCH_IDLE_SLEEP 300 // (s) Turn off the TFT backlight if set (5mn) #define TOUCH_SCREEN_CALIBRATION diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 910e779b2a54..4a9cb77b8bc1 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1277,6 +1277,11 @@ #define FEEDRATE_CHANGE_BEEP_FREQUENCY 440 #endif +// +// LCD Backlight Timeout +// +//#define LCD_BACKLIGHT_TIMEOUT 30 // (s) Timeout before turning off the backlight + #if HAS_BED_PROBE && EITHER(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI) //#define PROBE_OFFSET_WIZARD // Add a Probe Z Offset calibration option to the LCD menu #if ENABLED(PROBE_OFFSET_WIZARD) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 7b335dc9295c..e847339e2aff 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2857,6 +2857,14 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #endif +#if LCD_BACKLIGHT_TIMEOUT + #if !HAS_ENCODER_ACTION + #error "LCD_BACKLIGHT_TIMEOUT requires an LCD with encoder or keypad." + #elif !PIN_EXISTS(LCD_BACKLIGHT) + #error "LCD_BACKLIGHT_TIMEOUT requires LCD_BACKLIGHT_PIN." + #endif +#endif + /** * Some boards forbid the use of -1 Native USB */ diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index d8d161701fdb..9925f225e381 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -402,6 +402,7 @@ namespace Language_en { LSTR MSG_ADVANCE_K_E = _UxGT("Advance K *"); LSTR MSG_CONTRAST = _UxGT("LCD Contrast"); LSTR MSG_BRIGHTNESS = _UxGT("LCD Brightness"); + LSTR MSG_LCD_BKL_TIMEOUT = _UxGT("LCD Sleep (s)"); LSTR MSG_STORE_EEPROM = _UxGT("Store Settings"); LSTR MSG_LOAD_EEPROM = _UxGT("Load Settings"); LSTR MSG_RESTORE_DEFAULTS = _UxGT("Restore Defaults"); diff --git a/Marlin/src/lcd/language/language_fr.h b/Marlin/src/lcd/language/language_fr.h index 2eb64fc2c228..02f9d2f54994 100644 --- a/Marlin/src/lcd/language/language_fr.h +++ b/Marlin/src/lcd/language/language_fr.h @@ -335,6 +335,7 @@ namespace Language_fr { LSTR MSG_ADVANCE_K_E = _UxGT("Avance K *"); LSTR MSG_BRIGHTNESS = _UxGT("Luminosité LCD"); LSTR MSG_CONTRAST = _UxGT("Contraste LCD"); + LSTR MSG_LCD_BKL_TIMEOUT = _UxGT("Veille LCD (s)"); LSTR MSG_STORE_EEPROM = _UxGT("Enregistrer config."); LSTR MSG_LOAD_EEPROM = _UxGT("Charger config."); LSTR MSG_RESTORE_DEFAULTS = _UxGT("Restaurer défauts"); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index d0cc2a25b8a3..d2884cc3f16f 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -180,6 +180,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update #endif +#if LCD_BACKLIGHT_TIMEOUT + uint16_t MarlinUI::lcd_backlight_timeout; // Initialized by settings.load() + millis_t MarlinUI::backlight_off_ms = 0; + void MarlinUI::refresh_backlight_timeout() { + backlight_off_ms = lcd_backlight_timeout ? millis() + lcd_backlight_timeout * 1000UL : 0; + WRITE(LCD_BACKLIGHT_PIN, HIGH); + } +#endif + void MarlinUI::init() { init_lcd(); @@ -1033,14 +1042,18 @@ void MarlinUI::init() { reset_status_timeout(ms); + #if LCD_BACKLIGHT_TIMEOUT + refresh_backlight_timeout(); + #endif + refresh(LCDVIEW_REDRAW_NOW); #if LED_POWEROFF_TIMEOUT > 0 if (!powerManager.psu_on) leds.reset_timeout(ms); #endif - } + } // encoder activity - #endif + #endif // HAS_ENCODER_ACTION // This runs every ~100ms when idling often enough. // Instead of tracking changes just redraw the Status Screen once per second. @@ -1137,6 +1150,13 @@ void MarlinUI::init() { return_to_status(); #endif + #if LCD_BACKLIGHT_TIMEOUT + if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) { + WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off + backlight_off_ms = 0; + } + #endif + // Change state of drawing flag between screen updates if (!drawing_screen) switch (lcdDrawUpdate) { case LCDVIEW_CLEAR_CALL_REDRAW: diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 17c246873788..15e9f73d653b 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -275,6 +275,14 @@ class MarlinUI { FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); } #endif + #if LCD_BACKLIGHT_TIMEOUT + #define LCD_BKL_TIMEOUT_MIN 1 + #define LCD_BKL_TIMEOUT_MAX (60*60*18) // 18 hours max within uint16_t + static uint16_t lcd_backlight_timeout; + static millis_t backlight_off_ms; + static void refresh_backlight_timeout(); + #endif + #if HAS_DWIN_E3V2_BASIC static void refresh(); #else diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 33e43b08ebda..b4e9287bd4a3 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -541,6 +541,10 @@ void menu_configuration() { #if HAS_LCD_CONTRAST && LCD_CONTRAST_MIN < LCD_CONTRAST_MAX EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true); #endif + #if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX + EDIT_ITEM(uint16_4, MSG_LCD_BKL_TIMEOUT, &ui.lcd_backlight_timeout, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX, ui.refresh_backlight_timeout); + #endif + #if ENABLED(FWRETRACT) SUBMENU(MSG_RETRACT, menu_config_retract); #endif diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index bcbe8fa985ee..66316edbbb32 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -391,6 +391,13 @@ typedef struct SettingsDataStruct { // uint8_t lcd_brightness; // M256 B + // + // LCD_BACKLIGHT_TIMEOUT + // + #if LCD_BACKLIGHT_TIMEOUT + uint16_t lcd_backlight_timeout; // (G-code needed) + #endif + // // Controller fan settings // @@ -607,6 +614,10 @@ void MarlinSettings::postprocess() { // Moved as last update due to interference with Neopixel init TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast()); TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness()); + + #if LCD_BACKLIGHT_TIMEOUT + ui.refresh_backlight_timeout(); + #endif } #if BOTH(PRINTCOUNTER, EEPROM_SETTINGS) @@ -1108,6 +1119,13 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(lcd_brightness); } + // + // LCD Backlight Timeout + // + #if LCD_BACKLIGHT_TIMEOUT + EEPROM_WRITE(ui.lcd_backlight_timeout); + #endif + // // Controller Fan // @@ -2015,6 +2033,13 @@ void MarlinSettings::postprocess() { TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.brightness = lcd_brightness); } + // + // LCD Backlight Timeout + // + #if LCD_BACKLIGHT_TIMEOUT + EEPROM_READ(ui.lcd_backlight_timeout); + #endif + // // Controller Fan // @@ -3040,6 +3065,13 @@ void MarlinSettings::reset() { // TERN_(HAS_LCD_BRIGHTNESS, ui.brightness = LCD_BRIGHTNESS_DEFAULT); + // + // LCD Backlight Timeout + // + #if LCD_BACKLIGHT_TIMEOUT + ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT; + #endif + // // Controller Fan //