Browse Source

✨ LCD Backlight Timer (#23768)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
M. FURIC Franck 2 years ago
parent
commit
0e7be8e8c4
No account linked to committer's email address

+ 1
- 1
Marlin/Configuration.h View File

@@ -2820,7 +2820,7 @@
2820 2820
   #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2821 2821
   #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
2822 2822
 
2823
-  //#define TOUCH_IDLE_SLEEP 300 // (secs) Turn off the TFT backlight if set (5mn)
2823
+  //#define TOUCH_IDLE_SLEEP 300 // (s) Turn off the TFT backlight if set (5mn)
2824 2824
 
2825 2825
   #define TOUCH_SCREEN_CALIBRATION
2826 2826
 

+ 5
- 0
Marlin/Configuration_adv.h View File

@@ -1277,6 +1277,11 @@
1277 1277
   #define FEEDRATE_CHANGE_BEEP_FREQUENCY 440
1278 1278
 #endif
1279 1279
 
1280
+//
1281
+// LCD Backlight Timeout
1282
+//
1283
+//#define LCD_BACKLIGHT_TIMEOUT 30 // (s) Timeout before turning off the backlight
1284
+
1280 1285
 #if HAS_BED_PROBE && EITHER(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI)
1281 1286
   //#define PROBE_OFFSET_WIZARD       // Add a Probe Z Offset calibration option to the LCD menu
1282 1287
   #if ENABLED(PROBE_OFFSET_WIZARD)

+ 8
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -2857,6 +2857,14 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2857 2857
   #endif
2858 2858
 #endif
2859 2859
 
2860
+#if LCD_BACKLIGHT_TIMEOUT
2861
+  #if !HAS_ENCODER_ACTION
2862
+    #error "LCD_BACKLIGHT_TIMEOUT requires an LCD with encoder or keypad."
2863
+  #elif !PIN_EXISTS(LCD_BACKLIGHT)
2864
+    #error "LCD_BACKLIGHT_TIMEOUT requires LCD_BACKLIGHT_PIN."
2865
+  #endif
2866
+#endif
2867
+
2860 2868
 /**
2861 2869
  * Some boards forbid the use of -1 Native USB
2862 2870
  */

+ 1
- 0
Marlin/src/lcd/language/language_en.h View File

@@ -402,6 +402,7 @@ namespace Language_en {
402 402
   LSTR MSG_ADVANCE_K_E                    = _UxGT("Advance K *");
403 403
   LSTR MSG_CONTRAST                       = _UxGT("LCD Contrast");
404 404
   LSTR MSG_BRIGHTNESS                     = _UxGT("LCD Brightness");
405
+  LSTR MSG_LCD_BKL_TIMEOUT                = _UxGT("LCD Sleep (s)");
405 406
   LSTR MSG_STORE_EEPROM                   = _UxGT("Store Settings");
406 407
   LSTR MSG_LOAD_EEPROM                    = _UxGT("Load Settings");
407 408
   LSTR MSG_RESTORE_DEFAULTS               = _UxGT("Restore Defaults");

+ 1
- 0
Marlin/src/lcd/language/language_fr.h View File

@@ -335,6 +335,7 @@ namespace Language_fr {
335 335
   LSTR MSG_ADVANCE_K_E                    = _UxGT("Avance K *");
336 336
   LSTR MSG_BRIGHTNESS                     = _UxGT("Luminosité LCD");
337 337
   LSTR MSG_CONTRAST                       = _UxGT("Contraste LCD");
338
+  LSTR MSG_LCD_BKL_TIMEOUT                = _UxGT("Veille LCD (s)");
338 339
   LSTR MSG_STORE_EEPROM                   = _UxGT("Enregistrer config.");
339 340
   LSTR MSG_LOAD_EEPROM                    = _UxGT("Charger config.");
340 341
   LSTR MSG_RESTORE_DEFAULTS               = _UxGT("Restaurer défauts");

+ 22
- 2
Marlin/src/lcd/marlinui.cpp View File

@@ -180,6 +180,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
180 180
   volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
181 181
 #endif
182 182
 
183
+#if LCD_BACKLIGHT_TIMEOUT
184
+  uint16_t MarlinUI::lcd_backlight_timeout; // Initialized by settings.load()
185
+  millis_t MarlinUI::backlight_off_ms = 0;
186
+  void MarlinUI::refresh_backlight_timeout() {
187
+    backlight_off_ms = lcd_backlight_timeout ? millis() + lcd_backlight_timeout * 1000UL : 0;
188
+    WRITE(LCD_BACKLIGHT_PIN, HIGH);
189
+  }
190
+#endif
191
+
183 192
 void MarlinUI::init() {
184 193
 
185 194
   init_lcd();
@@ -1033,14 +1042,18 @@ void MarlinUI::init() {
1033 1042
 
1034 1043
           reset_status_timeout(ms);
1035 1044
 
1045
+          #if LCD_BACKLIGHT_TIMEOUT
1046
+            refresh_backlight_timeout();
1047
+          #endif
1048
+
1036 1049
           refresh(LCDVIEW_REDRAW_NOW);
1037 1050
 
1038 1051
           #if LED_POWEROFF_TIMEOUT > 0
1039 1052
             if (!powerManager.psu_on) leds.reset_timeout(ms);
1040 1053
           #endif
1041
-        }
1054
+        } // encoder activity
1042 1055
 
1043
-      #endif
1056
+      #endif // HAS_ENCODER_ACTION
1044 1057
 
1045 1058
       // This runs every ~100ms when idling often enough.
1046 1059
       // Instead of tracking changes just redraw the Status Screen once per second.
@@ -1137,6 +1150,13 @@ void MarlinUI::init() {
1137 1150
           return_to_status();
1138 1151
       #endif
1139 1152
 
1153
+      #if LCD_BACKLIGHT_TIMEOUT
1154
+        if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
1155
+          WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1156
+          backlight_off_ms = 0;
1157
+        }
1158
+      #endif
1159
+
1140 1160
       // Change state of drawing flag between screen updates
1141 1161
       if (!drawing_screen) switch (lcdDrawUpdate) {
1142 1162
         case LCDVIEW_CLEAR_CALL_REDRAW:

+ 8
- 0
Marlin/src/lcd/marlinui.h View File

@@ -275,6 +275,14 @@ public:
275 275
     FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
276 276
   #endif
277 277
 
278
+  #if LCD_BACKLIGHT_TIMEOUT
279
+    #define LCD_BKL_TIMEOUT_MIN 1
280
+    #define LCD_BKL_TIMEOUT_MAX (60*60*18) // 18 hours max within uint16_t
281
+    static uint16_t lcd_backlight_timeout;
282
+    static millis_t backlight_off_ms;
283
+    static void refresh_backlight_timeout();
284
+  #endif
285
+
278 286
   #if HAS_DWIN_E3V2_BASIC
279 287
     static void refresh();
280 288
   #else

+ 4
- 0
Marlin/src/lcd/menu/menu_configuration.cpp View File

@@ -541,6 +541,10 @@ void menu_configuration() {
541 541
   #if HAS_LCD_CONTRAST && LCD_CONTRAST_MIN < LCD_CONTRAST_MAX
542 542
     EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
543 543
   #endif
544
+  #if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX
545
+    EDIT_ITEM(uint16_4, MSG_LCD_BKL_TIMEOUT, &ui.lcd_backlight_timeout, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX, ui.refresh_backlight_timeout);
546
+  #endif
547
+
544 548
   #if ENABLED(FWRETRACT)
545 549
     SUBMENU(MSG_RETRACT, menu_config_retract);
546 550
   #endif

+ 32
- 0
Marlin/src/module/settings.cpp View File

@@ -392,6 +392,13 @@ typedef struct SettingsDataStruct {
392 392
   uint8_t lcd_brightness;                               // M256 B
393 393
 
394 394
   //
395
+  // LCD_BACKLIGHT_TIMEOUT
396
+  //
397
+  #if LCD_BACKLIGHT_TIMEOUT
398
+    uint16_t lcd_backlight_timeout;                     // (G-code needed)
399
+  #endif
400
+
401
+  //
395 402
   // Controller fan settings
396 403
   //
397 404
   controllerFan_settings_t controllerFan_settings;      // M710
@@ -607,6 +614,10 @@ void MarlinSettings::postprocess() {
607 614
   // Moved as last update due to interference with Neopixel init
608 615
   TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast());
609 616
   TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness());
617
+
618
+  #if LCD_BACKLIGHT_TIMEOUT
619
+    ui.refresh_backlight_timeout();
620
+  #endif
610 621
 }
611 622
 
612 623
 #if BOTH(PRINTCOUNTER, EEPROM_SETTINGS)
@@ -1109,6 +1120,13 @@ void MarlinSettings::postprocess() {
1109 1120
     }
1110 1121
 
1111 1122
     //
1123
+    // LCD Backlight Timeout
1124
+    //
1125
+    #if LCD_BACKLIGHT_TIMEOUT
1126
+      EEPROM_WRITE(ui.lcd_backlight_timeout);
1127
+    #endif
1128
+
1129
+    //
1112 1130
     // Controller Fan
1113 1131
     //
1114 1132
     {
@@ -2016,6 +2034,13 @@ void MarlinSettings::postprocess() {
2016 2034
       }
2017 2035
 
2018 2036
       //
2037
+      // LCD Backlight Timeout
2038
+      //
2039
+      #if LCD_BACKLIGHT_TIMEOUT
2040
+        EEPROM_READ(ui.lcd_backlight_timeout);
2041
+      #endif
2042
+
2043
+      //
2019 2044
       // Controller Fan
2020 2045
       //
2021 2046
       {
@@ -3041,6 +3066,13 @@ void MarlinSettings::reset() {
3041 3066
   TERN_(HAS_LCD_BRIGHTNESS, ui.brightness = LCD_BRIGHTNESS_DEFAULT);
3042 3067
 
3043 3068
   //
3069
+  // LCD Backlight Timeout
3070
+  //
3071
+  #if LCD_BACKLIGHT_TIMEOUT
3072
+    ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
3073
+  #endif
3074
+
3075
+  //
3044 3076
   // Controller Fan
3045 3077
   //
3046 3078
   TERN_(USE_CONTROLLER_FAN, controllerFan.reset());

Loading…
Cancel
Save