Pārlūkot izejas kodu

✨ DOGM Display Sleep (#23992)

Co-authored-by: borland1 <barryorlando@hotmail.com>
Scott Lahteine 2 gadus atpakaļ
vecāks
revīzija
32e6767b5a
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 11
- 0
Marlin/Configuration_adv.h Parādīt failu

@@ -1697,6 +1697,17 @@
1697 1697
   //#define USE_SMALL_INFOFONT
1698 1698
 
1699 1699
   /**
1700
+   * Graphical Display Sleep
1701
+   *
1702
+   * The U8G library provides sleep / wake functions for SH1106, SSD1306,
1703
+   * SSD1309, and some other DOGM displays.
1704
+   * Enable this option to save energy and prevent OLED pixel burn-in.
1705
+   * Adds the menu item Configuration > LCD Timeout (m) to set a wait period
1706
+   * from 0 (disabled) to 99 minutes.
1707
+   */
1708
+  //#define DISPLAY_SLEEP_MINUTES 2  // (minutes) Timeout before turning off the screen
1709
+
1710
+  /**
1700 1711
    * ST7920-based LCDs can emulate a 16 x 4 character display using
1701 1712
    * the ST7920 character-generator for very fast screen updates.
1702 1713
    * Enable LIGHTWEIGHT_UI to use this special display mode.

+ 1
- 0
Marlin/src/core/language.h Parādīt failu

@@ -303,6 +303,7 @@
303 303
 #define STR_MATERIAL_HEATUP                 "Material heatup parameters"
304 304
 #define STR_LCD_CONTRAST                    "LCD Contrast"
305 305
 #define STR_LCD_BRIGHTNESS                  "LCD Brightness"
306
+#define STR_DISPLAY_SLEEP                   "Display Sleep"
306 307
 #define STR_UI_LANGUAGE                     "UI Language"
307 308
 #define STR_Z_PROBE_OFFSET                  "Z-Probe Offset"
308 309
 #define STR_TEMPERATURE_UNITS               "Temperature Units"

+ 6
- 0
Marlin/src/gcode/gcode.h Parādīt failu

@@ -202,6 +202,7 @@
202 202
  * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
203 203
  * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
204 204
  * M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
205
+ * M255 - Set LCD sleep time: "M255 S<minutes>" (0-99). (Requires an LCD with brightness or sleep/wake)
205 206
  * M256 - Set LCD brightness: "M256 B<brightness>" (0-255). (Requires an LCD with brightness control)
206 207
  * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
207 208
  * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
@@ -879,6 +880,11 @@ private:
879 880
     static void M250_report(const bool forReplay=true);
880 881
   #endif
881 882
 
883
+  #if HAS_DISPLAY_SLEEP
884
+    static void M255();
885
+    static void M255_report(const bool forReplay=true);
886
+  #endif
887
+
882 888
   #if HAS_LCD_BRIGHTNESS
883 889
     static void M256();
884 890
     static void M256_report(const bool forReplay=true);

+ 58
- 0
Marlin/src/gcode/lcd/M255.cpp Parādīt failu

@@ -0,0 +1,58 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../../inc/MarlinConfig.h"
23
+
24
+#if HAS_GCODE_M255
25
+
26
+#include "../gcode.h"
27
+#include "../../lcd/marlinui.h"
28
+
29
+/**
30
+ * M255: Set the LCD sleep timeout (in minutes)
31
+ *  S<minutes> - Period of inactivity required for display / backlight sleep
32
+ */
33
+void GcodeSuite::M255() {
34
+  if (parser.seenval('S')) {
35
+    #if HAS_DISPLAY_SLEEP
36
+      const int m = parser.value_int();
37
+      ui.sleep_timeout_minutes = constrain(m, SLEEP_TIMEOUT_MIN, SLEEP_TIMEOUT_MAX);
38
+    #else
39
+      const int s = parser.value_int() * 60;
40
+      ui.lcd_backlight_timeout = constrain(s, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX);
41
+    #endif
42
+  }
43
+  else
44
+    M255_report();
45
+}
46
+
47
+void GcodeSuite::M255_report(const bool forReplay/*=true*/) {
48
+  report_heading_etc(forReplay, F(STR_DISPLAY_SLEEP));
49
+  SERIAL_ECHOLNPGM("  M255 S",
50
+    #if HAS_DISPLAY_SLEEP
51
+      ui.sleep_timeout_minutes, " ; (minutes)"
52
+    #else
53
+      ui.lcd_backlight_timeout, " ; (seconds)"
54
+    #endif
55
+  );
56
+}
57
+
58
+#endif // HAS_GCODE_M255

+ 6
- 0
Marlin/src/inc/Conditionals_adv.h Parādīt failu

@@ -628,6 +628,12 @@
628 628
 #if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT)
629 629
   #define HAS_LEDS_OFF_FLAG 1
630 630
 #endif
631
+#ifdef DISPLAY_SLEEP_MINUTES
632
+  #define HAS_DISPLAY_SLEEP 1
633
+#endif
634
+#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT
635
+  #define HAS_GCODE_M255 1
636
+#endif
631 637
 
632 638
 #if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451)
633 639
   #define HAS_MOTOR_CURRENT_I2C 1

+ 11
- 0
Marlin/src/inc/SanityCheck.h Parādīt failu

@@ -2992,6 +2992,17 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2992 2992
 #endif
2993 2993
 
2994 2994
 /**
2995
+ * Display Sleep is not supported by these common displays
2996
+ */
2997
+#if HAS_DISPLAY_SLEEP
2998
+  #if ANY(IS_U8GLIB_LM6059_AF, IS_U8GLIB_ST7565_64128, REPRAPWORLD_GRAPHICAL_LCD, FYSETC_MINI, ENDER2_STOCKDISPLAY, MINIPANEL)
2999
+    #error "DISPLAY_SLEEP_MINUTES is not supported by your display."
3000
+  #elif !WITHIN(DISPLAY_SLEEP_MINUTES, 0, 255)
3001
+    #error "DISPLAY_SLEEP_MINUTES must be between 0 and 255."
3002
+  #endif
3003
+#endif
3004
+
3005
+/**
2995 3006
  * Some boards forbid the use of -1 Native USB
2996 3007
  */
2997 3008
 #if ENABLED(BOARD_NO_NATIVE_USB)

+ 5
- 0
Marlin/src/lcd/dogm/marlinui_DOGM.cpp Parādīt failu

@@ -342,6 +342,11 @@ void MarlinUI::draw_kill_screen() {
342 342
 
343 343
 void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
344 344
 
345
+#if HAS_DISPLAY_SLEEP
346
+  void MarlinUI::sleep_on()  { u8g.sleepOn(); }
347
+  void MarlinUI::sleep_off() { u8g.sleepOff(); }
348
+#endif
349
+
345 350
 #if HAS_LCD_BRIGHTNESS
346 351
 
347 352
   void MarlinUI::_set_brightness() {

+ 1
- 0
Marlin/src/lcd/language/language_en.h Parādīt failu

@@ -422,6 +422,7 @@ namespace Language_en {
422 422
   LSTR MSG_CONTRAST                       = _UxGT("LCD Contrast");
423 423
   LSTR MSG_BRIGHTNESS                     = _UxGT("LCD Brightness");
424 424
   LSTR MSG_LCD_TIMEOUT_SEC                = _UxGT("LCD Timeout (s)");
425
+  LSTR MSG_SCREEN_TIMEOUT                 = _UxGT("LCD Timeout (m)");
425 426
   LSTR MSG_BRIGHTNESS_OFF                 = _UxGT("Backlight Off");
426 427
   LSTR MSG_STORE_EEPROM                   = _UxGT("Store Settings");
427 428
   LSTR MSG_LOAD_EEPROM                    = _UxGT("Load Settings");

+ 14
- 0
Marlin/src/lcd/marlinui.cpp Parādīt failu

@@ -192,6 +192,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
192 192
     WRITE(LCD_BACKLIGHT_PIN, HIGH);
193 193
   }
194 194
 
195
+#elif HAS_DISPLAY_SLEEP
196
+
197
+  uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load()
198
+  millis_t MarlinUI::screen_timeout_millis = 0;
199
+  void MarlinUI::refresh_screen_timeout() {
200
+    screen_timeout_millis = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0;
201
+    sleep_off();
202
+  }
203
+
195 204
 #endif
196 205
 
197 206
 void MarlinUI::init() {
@@ -1061,6 +1070,8 @@ void MarlinUI::init() {
1061 1070
 
1062 1071
           #if LCD_BACKLIGHT_TIMEOUT
1063 1072
             refresh_backlight_timeout();
1073
+          #elif HAS_DISPLAY_SLEEP
1074
+            refresh_screen_timeout();
1064 1075
           #endif
1065 1076
 
1066 1077
           refresh(LCDVIEW_REDRAW_NOW);
@@ -1172,6 +1183,9 @@ void MarlinUI::init() {
1172 1183
           WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1173 1184
           backlight_off_ms = 0;
1174 1185
         }
1186
+      #elif HAS_DISPLAY_SLEEP
1187
+        if (screen_timeout_millis && ELAPSED(ms, screen_timeout_millis))
1188
+          sleep_on();
1175 1189
       #endif
1176 1190
 
1177 1191
       // Change state of drawing flag between screen updates

+ 8
- 0
Marlin/src/lcd/marlinui.h Parādīt failu

@@ -279,6 +279,14 @@ public:
279 279
     static uint16_t lcd_backlight_timeout;
280 280
     static millis_t backlight_off_ms;
281 281
     static void refresh_backlight_timeout();
282
+  #elif HAS_DISPLAY_SLEEP
283
+    #define SLEEP_TIMEOUT_MIN 0
284
+    #define SLEEP_TIMEOUT_MAX 99
285
+    static uint8_t sleep_timeout_minutes;
286
+    static millis_t screen_timeout_millis;
287
+    static void refresh_screen_timeout();
288
+    static void sleep_on();
289
+    static void sleep_off();
282 290
   #endif
283 291
 
284 292
   #if HAS_DWIN_E3V2_BASIC

+ 2
- 0
Marlin/src/lcd/menu/menu_configuration.cpp Parādīt failu

@@ -547,6 +547,8 @@ void menu_configuration() {
547 547
   //
548 548
   #if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX
549 549
     EDIT_ITEM(uint16_4, MSG_LCD_TIMEOUT_SEC, &ui.lcd_backlight_timeout, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX, ui.refresh_backlight_timeout);
550
+  #elif HAS_DISPLAY_SLEEP
551
+    EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, SLEEP_TIMEOUT_MIN, SLEEP_TIMEOUT_MAX, ui.refresh_screen_timeout);
550 552
   #endif
551 553
 
552 554
   #if ENABLED(FWRETRACT)

+ 16
- 1
Marlin/src/module/settings.cpp Parādīt failu

@@ -402,7 +402,9 @@ typedef struct SettingsDataStruct {
402 402
   // Display Sleep
403 403
   //
404 404
   #if LCD_BACKLIGHT_TIMEOUT
405
-    uint16_t lcd_backlight_timeout;                     // (G-code needed)
405
+    uint16_t lcd_backlight_timeout;                     // M255 S
406
+  #elif HAS_DISPLAY_SLEEP
407
+    uint8_t sleep_timeout_minutes;                      // M255 S
406 408
   #endif
407 409
 
408 410
   //
@@ -631,6 +633,8 @@ void MarlinSettings::postprocess() {
631 633
 
632 634
   #if LCD_BACKLIGHT_TIMEOUT
633 635
     ui.refresh_backlight_timeout();
636
+  #elif HAS_DISPLAY_SLEEP
637
+    ui.refresh_screen_timeout();
634 638
   #endif
635 639
 }
636 640
 
@@ -1146,6 +1150,8 @@ void MarlinSettings::postprocess() {
1146 1150
     //
1147 1151
     #if LCD_BACKLIGHT_TIMEOUT
1148 1152
       EEPROM_WRITE(ui.lcd_backlight_timeout);
1153
+    #elif HAS_DISPLAY_SLEEP
1154
+      EEPROM_WRITE(ui.sleep_timeout_minutes);
1149 1155
     #endif
1150 1156
 
1151 1157
     //
@@ -2095,6 +2101,8 @@ void MarlinSettings::postprocess() {
2095 2101
       //
2096 2102
       #if LCD_BACKLIGHT_TIMEOUT
2097 2103
         EEPROM_READ(ui.lcd_backlight_timeout);
2104
+      #elif HAS_DISPLAY_SLEEP
2105
+        EEPROM_READ(ui.sleep_timeout_minutes);
2098 2106
       #endif
2099 2107
 
2100 2108
       //
@@ -3172,6 +3180,8 @@ void MarlinSettings::reset() {
3172 3180
   //
3173 3181
   #if LCD_BACKLIGHT_TIMEOUT
3174 3182
     ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
3183
+  #elif HAS_DISPLAY_SLEEP
3184
+    ui.sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES;
3175 3185
   #endif
3176 3186
 
3177 3187
   //
@@ -3503,6 +3513,11 @@ void MarlinSettings::reset() {
3503 3513
     TERN_(HAS_LCD_CONTRAST, gcode.M250_report(forReplay));
3504 3514
 
3505 3515
     //
3516
+    // Display Sleep
3517
+    //
3518
+    TERN_(HAS_GCODE_M255, gcode.M255_report(forReplay));
3519
+
3520
+    //
3506 3521
     // LCD Brightness
3507 3522
     //
3508 3523
     TERN_(HAS_LCD_BRIGHTNESS, gcode.M256_report(forReplay));

+ 2
- 1
ini/features.ini Parādīt failu

@@ -37,7 +37,7 @@ USES_LIQUIDCRYSTAL_I2C                 = marcoschwartz/LiquidCrystal_I2C@1.1.4
37 37
 USES_LIQUIDTWI2                        = LiquidTWI2@1.2.7
38 38
 HAS_LCDPRINT                           = src_filter=+<src/lcd/lcdprint.cpp>
39 39
 HAS_MARLINUI_HD44780                   = src_filter=+<src/lcd/HD44780>
40
-HAS_MARLINUI_U8GLIB                    = U8glib-HAL@~0.5.0
40
+HAS_MARLINUI_U8GLIB                    = U8glib-HAL@~0.5.2
41 41
                                          src_filter=+<src/lcd/dogm>
42 42
 HAS_(FSMC|SPI|LTDC)_TFT                = src_filter=+<src/HAL/STM32/tft> +<src/HAL/STM32F1/tft> +<src/lcd/tft_io>
43 43
 HAS_FSMC_TFT                           = src_filter=+<src/HAL/STM32/tft/tft_fsmc.cpp> +<src/HAL/STM32F1/tft/tft_fsmc.cpp>
@@ -202,6 +202,7 @@ HAS_RESUME_CONTINUE                    = src_filter=+<src/gcode/lcd/M0_M1.cpp>
202 202
 LCD_SET_PROGRESS_MANUALLY              = src_filter=+<src/gcode/lcd/M73.cpp>
203 203
 HAS_STATUS_MESSAGE                     = src_filter=+<src/gcode/lcd/M117.cpp>
204 204
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
205
+HAS_GCODE_M255                         = src_filter=+<src/gcode/lcd/M255.cpp>
205 206
 HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
206 207
 HAS_BUZZER                             = src_filter=+<src/gcode/lcd/M300.cpp>
207 208
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>

Notiek ielāde…
Atcelt
Saglabāt