Browse Source

✨ DOGM Display Sleep (#23992)

Co-authored-by: borland1 <barryorlando@hotmail.com>
Scott Lahteine 3 years ago
parent
commit
32e6767b5a
No account linked to committer's email address

+ 11
- 0
Marlin/Configuration_adv.h View File

1697
   //#define USE_SMALL_INFOFONT
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
    * ST7920-based LCDs can emulate a 16 x 4 character display using
1711
    * ST7920-based LCDs can emulate a 16 x 4 character display using
1701
    * the ST7920 character-generator for very fast screen updates.
1712
    * the ST7920 character-generator for very fast screen updates.
1702
    * Enable LIGHTWEIGHT_UI to use this special display mode.
1713
    * Enable LIGHTWEIGHT_UI to use this special display mode.

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

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

+ 6
- 0
Marlin/src/gcode/gcode.h View File

202
  * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
202
  * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
203
  * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
203
  * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
204
  * M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
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
  * M256 - Set LCD brightness: "M256 B<brightness>" (0-255). (Requires an LCD with brightness control)
206
  * M256 - Set LCD brightness: "M256 B<brightness>" (0-255). (Requires an LCD with brightness control)
206
  * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
207
  * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
207
  * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
208
  * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
879
     static void M250_report(const bool forReplay=true);
880
     static void M250_report(const bool forReplay=true);
880
   #endif
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
   #if HAS_LCD_BRIGHTNESS
888
   #if HAS_LCD_BRIGHTNESS
883
     static void M256();
889
     static void M256();
884
     static void M256_report(const bool forReplay=true);
890
     static void M256_report(const bool forReplay=true);

+ 58
- 0
Marlin/src/gcode/lcd/M255.cpp View File

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 View File

628
 #if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT)
628
 #if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT)
629
   #define HAS_LEDS_OFF_FLAG 1
629
   #define HAS_LEDS_OFF_FLAG 1
630
 #endif
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
 #if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451)
638
 #if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451)
633
   #define HAS_MOTOR_CURRENT_I2C 1
639
   #define HAS_MOTOR_CURRENT_I2C 1

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

2992
 #endif
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
  * Some boards forbid the use of -1 Native USB
3006
  * Some boards forbid the use of -1 Native USB
2996
  */
3007
  */
2997
 #if ENABLED(BOARD_NO_NATIVE_USB)
3008
 #if ENABLED(BOARD_NO_NATIVE_USB)

+ 5
- 0
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

342
 
342
 
343
 void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
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
 #if HAS_LCD_BRIGHTNESS
350
 #if HAS_LCD_BRIGHTNESS
346
 
351
 
347
   void MarlinUI::_set_brightness() {
352
   void MarlinUI::_set_brightness() {

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

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

+ 14
- 0
Marlin/src/lcd/marlinui.cpp View File

192
     WRITE(LCD_BACKLIGHT_PIN, HIGH);
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
 #endif
204
 #endif
196
 
205
 
197
 void MarlinUI::init() {
206
 void MarlinUI::init() {
1061
 
1070
 
1062
           #if LCD_BACKLIGHT_TIMEOUT
1071
           #if LCD_BACKLIGHT_TIMEOUT
1063
             refresh_backlight_timeout();
1072
             refresh_backlight_timeout();
1073
+          #elif HAS_DISPLAY_SLEEP
1074
+            refresh_screen_timeout();
1064
           #endif
1075
           #endif
1065
 
1076
 
1066
           refresh(LCDVIEW_REDRAW_NOW);
1077
           refresh(LCDVIEW_REDRAW_NOW);
1172
           WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1183
           WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1173
           backlight_off_ms = 0;
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
       #endif
1189
       #endif
1176
 
1190
 
1177
       // Change state of drawing flag between screen updates
1191
       // Change state of drawing flag between screen updates

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

279
     static uint16_t lcd_backlight_timeout;
279
     static uint16_t lcd_backlight_timeout;
280
     static millis_t backlight_off_ms;
280
     static millis_t backlight_off_ms;
281
     static void refresh_backlight_timeout();
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
   #endif
290
   #endif
283
 
291
 
284
   #if HAS_DWIN_E3V2_BASIC
292
   #if HAS_DWIN_E3V2_BASIC

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

547
   //
547
   //
548
   #if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX
548
   #if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX
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);
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
   #endif
552
   #endif
551
 
553
 
552
   #if ENABLED(FWRETRACT)
554
   #if ENABLED(FWRETRACT)

+ 16
- 1
Marlin/src/module/settings.cpp View File

402
   // Display Sleep
402
   // Display Sleep
403
   //
403
   //
404
   #if LCD_BACKLIGHT_TIMEOUT
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
   #endif
408
   #endif
407
 
409
 
408
   //
410
   //
631
 
633
 
632
   #if LCD_BACKLIGHT_TIMEOUT
634
   #if LCD_BACKLIGHT_TIMEOUT
633
     ui.refresh_backlight_timeout();
635
     ui.refresh_backlight_timeout();
636
+  #elif HAS_DISPLAY_SLEEP
637
+    ui.refresh_screen_timeout();
634
   #endif
638
   #endif
635
 }
639
 }
636
 
640
 
1146
     //
1150
     //
1147
     #if LCD_BACKLIGHT_TIMEOUT
1151
     #if LCD_BACKLIGHT_TIMEOUT
1148
       EEPROM_WRITE(ui.lcd_backlight_timeout);
1152
       EEPROM_WRITE(ui.lcd_backlight_timeout);
1153
+    #elif HAS_DISPLAY_SLEEP
1154
+      EEPROM_WRITE(ui.sleep_timeout_minutes);
1149
     #endif
1155
     #endif
1150
 
1156
 
1151
     //
1157
     //
2095
       //
2101
       //
2096
       #if LCD_BACKLIGHT_TIMEOUT
2102
       #if LCD_BACKLIGHT_TIMEOUT
2097
         EEPROM_READ(ui.lcd_backlight_timeout);
2103
         EEPROM_READ(ui.lcd_backlight_timeout);
2104
+      #elif HAS_DISPLAY_SLEEP
2105
+        EEPROM_READ(ui.sleep_timeout_minutes);
2098
       #endif
2106
       #endif
2099
 
2107
 
2100
       //
2108
       //
3172
   //
3180
   //
3173
   #if LCD_BACKLIGHT_TIMEOUT
3181
   #if LCD_BACKLIGHT_TIMEOUT
3174
     ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
3182
     ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
3183
+  #elif HAS_DISPLAY_SLEEP
3184
+    ui.sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES;
3175
   #endif
3185
   #endif
3176
 
3186
 
3177
   //
3187
   //
3503
     TERN_(HAS_LCD_CONTRAST, gcode.M250_report(forReplay));
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
     // LCD Brightness
3521
     // LCD Brightness
3507
     //
3522
     //
3508
     TERN_(HAS_LCD_BRIGHTNESS, gcode.M256_report(forReplay));
3523
     TERN_(HAS_LCD_BRIGHTNESS, gcode.M256_report(forReplay));

+ 2
- 1
ini/features.ini View File

37
 USES_LIQUIDTWI2                        = LiquidTWI2@1.2.7
37
 USES_LIQUIDTWI2                        = LiquidTWI2@1.2.7
38
 HAS_LCDPRINT                           = src_filter=+<src/lcd/lcdprint.cpp>
38
 HAS_LCDPRINT                           = src_filter=+<src/lcd/lcdprint.cpp>
39
 HAS_MARLINUI_HD44780                   = src_filter=+<src/lcd/HD44780>
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
                                          src_filter=+<src/lcd/dogm>
41
                                          src_filter=+<src/lcd/dogm>
42
 HAS_(FSMC|SPI|LTDC)_TFT                = src_filter=+<src/HAL/STM32/tft> +<src/HAL/STM32F1/tft> +<src/lcd/tft_io>
42
 HAS_(FSMC|SPI|LTDC)_TFT                = src_filter=+<src/HAL/STM32/tft> +<src/HAL/STM32F1/tft> +<src/lcd/tft_io>
43
 HAS_FSMC_TFT                           = src_filter=+<src/HAL/STM32/tft/tft_fsmc.cpp> +<src/HAL/STM32F1/tft/tft_fsmc.cpp>
43
 HAS_FSMC_TFT                           = src_filter=+<src/HAL/STM32/tft/tft_fsmc.cpp> +<src/HAL/STM32F1/tft/tft_fsmc.cpp>
202
 LCD_SET_PROGRESS_MANUALLY              = src_filter=+<src/gcode/lcd/M73.cpp>
202
 LCD_SET_PROGRESS_MANUALLY              = src_filter=+<src/gcode/lcd/M73.cpp>
203
 HAS_STATUS_MESSAGE                     = src_filter=+<src/gcode/lcd/M117.cpp>
203
 HAS_STATUS_MESSAGE                     = src_filter=+<src/gcode/lcd/M117.cpp>
204
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
204
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
205
+HAS_GCODE_M255                         = src_filter=+<src/gcode/lcd/M255.cpp>
205
 HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
206
 HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
206
 HAS_BUZZER                             = src_filter=+<src/gcode/lcd/M300.cpp>
207
 HAS_BUZZER                             = src_filter=+<src/gcode/lcd/M300.cpp>
207
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>
208
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>

Loading…
Cancel
Save