Skip to content

Commit 1dee4d9

Browse files
committed
🔧 TOUCH_IDLE_SLEEP_MINS => DISPLAY_SLEEP_MINUTES
Follow up to MarlinFirmware#26517
1 parent 9364cbb commit 1dee4d9

21 files changed

+106
-126
lines changed

Marlin/Configuration.h

-1
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,6 @@
34143414
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
34153415

34163416
//#define DISABLE_ENCODER // Disable the click encoder, if any
3417-
//#define TOUCH_IDLE_SLEEP_MINS 5 // (minutes) Display Sleep after a period of inactivity. Set with M255 S.
34183417

34193418
#define TOUCH_SCREEN_CALIBRATION
34203419

Marlin/Configuration_adv.h

+12-16
Original file line numberDiff line numberDiff line change
@@ -1970,17 +1970,6 @@
19701970
// Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese.
19711971
//#define USE_SMALL_INFOFONT
19721972

1973-
/**
1974-
* Graphical Display Sleep
1975-
*
1976-
* The U8G library provides sleep / wake functions for SH1106, SSD1306,
1977-
* SSD1309, and some other DOGM displays.
1978-
* Enable this option to save energy and prevent OLED pixel burn-in.
1979-
* Adds the menu item Configuration > LCD Timeout (m) to set a wait period
1980-
* from 0 (disabled) to 99 minutes.
1981-
*/
1982-
//#define DISPLAY_SLEEP_MINUTES 2 // (minutes) Timeout before turning off the screen. Set with M255 S.
1983-
19841973
/**
19851974
* ST7920-based LCDs can emulate a 16 x 4 character display using
19861975
* the ST7920 character-generator for very fast screen updates.
@@ -2229,13 +2218,20 @@
22292218
//#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
22302219
#endif
22312220

2232-
//
2233-
// LCD Backlight Timeout
2234-
// Requires a display with a controllable backlight
2235-
//
2221+
/**
2222+
* Display Sleep
2223+
* Enable this option to save energy and prevent OLED pixel burn-in.
2224+
*/
2225+
//#define DISPLAY_SLEEP_MINUTES 2 // (minutes) Timeout before turning off the screen
2226+
2227+
/**
2228+
* LCD Backlight Timeout
2229+
* Requires a display with a controllable backlight
2230+
*/
22362231
//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight
2232+
22372233
#if defined(DISPLAY_SLEEP_MINUTES) || defined(LCD_BACKLIGHT_TIMEOUT_MINS)
2238-
#define EDITABLE_DISPLAY_TIMEOUT // Edit timeout with M255 S<minutes> and a menu item
2234+
#define EDITABLE_DISPLAY_TIMEOUT // Edit sleep / backlight timeout with M255 S<minutes> and a menu item
22392235
#endif
22402236

22412237
//

Marlin/src/inc/Changes.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@
600600
#elif defined(LEVEL_CENTER_TOO)
601601
#error "LEVEL_CENTER_TOO is now BED_TRAMMING_INCLUDE_CENTER."
602602
#elif defined(TOUCH_IDLE_SLEEP)
603-
#error "TOUCH_IDLE_SLEEP (seconds) is now TOUCH_IDLE_SLEEP_MINS (minutes)."
603+
#error "TOUCH_IDLE_SLEEP (seconds) is now DISPLAY_SLEEP_MINUTES (minutes)."
604+
#elif defined(TOUCH_IDLE_SLEEP_MINS)
605+
#error "TOUCH_IDLE_SLEEP_MINS is now DISPLAY_SLEEP_MINUTES."
604606
#elif defined(LCD_BACKLIGHT_TIMEOUT)
605607
#error "LCD_BACKLIGHT_TIMEOUT (seconds) is now LCD_BACKLIGHT_TIMEOUT_MINS (minutes)."
606608
#elif defined(LCD_SET_PROGRESS_MANUALLY)

Marlin/src/inc/Conditionals_LCD.h

-3
Original file line numberDiff line numberDiff line change
@@ -1850,9 +1850,6 @@
18501850

18511851
// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
18521852
#if ENABLED(TOUCH_SCREEN)
1853-
#if TOUCH_IDLE_SLEEP_MINS
1854-
#define HAS_TOUCH_SLEEP 1
1855-
#endif
18561853
#if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
18571854
#define TFT_TOUCH_DEVICE_XPT2046 // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
18581855
#endif

Marlin/src/inc/Conditionals_adv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@
912912
#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, HAS_MEDIA)
913913
#define HAS_LEDS_OFF_FLAG 1
914914
#endif
915-
#if defined(DISPLAY_SLEEP_MINUTES) || defined(TOUCH_IDLE_SLEEP_MINS)
915+
#ifdef DISPLAY_SLEEP_MINUTES
916916
#define HAS_DISPLAY_SLEEP 1
917917
#endif
918918
#ifdef LCD_BACKLIGHT_TIMEOUT_MINS

Marlin/src/inc/SanityCheck.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,8 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
27852785
#if HAS_BACKLIGHT_TIMEOUT
27862786
#if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2)
27872787
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
2788+
#elif HAS_DISPLAY_SLEEP
2789+
#error "LCD_BACKLIGHT_TIMEOUT_MINS and DISPLAY_SLEEP_MINUTES are not currently supported at the same time."
27882790
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)
27892791
#if PIN_EXISTS(LCD_BACKLIGHT)
27902792
#error "LCD_BACKLIGHT_PIN and NEOPIXEL_BKGD_INDEX_FIRST are not supported at the same time."
@@ -2794,6 +2796,15 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
27942796
#elif !PIN_EXISTS(LCD_BACKLIGHT) && DISABLED(HAS_DWIN_E3V2)
27952797
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN, NEOPIXEL_BKGD_INDEX_FIRST, or an Ender-3 V2 DWIN LCD."
27962798
#endif
2799+
#elif HAS_DISPLAY_SLEEP
2800+
#if NONE(TOUCH_SCREEN, HAS_MARLINUI_U8GLIB) || ANY(IS_U8GLIB_LM6059_AF, IS_U8GLIB_ST7565_64128, REPRAPWORLD_GRAPHICAL_LCD, FYSETC_MINI_12864, CR10_STOCKDISPLAY, MINIPANEL)
2801+
#error "DISPLAY_SLEEP_MINUTES is not supported by your display."
2802+
#undef HAS_DISPLAY_SLEEP
2803+
#elif !WITHIN(DISPLAY_SLEEP_MINUTES, 0, 255)
2804+
#error "DISPLAY_SLEEP_MINUTES must be between 0 and 255."
2805+
#elif DISABLED(EDITABLE_DISPLAY_TIMEOUT) && DISPLAY_SLEEP_MINUTES == 0
2806+
#error "DISPLAY_SLEEP_MINUTES must be greater than 0 with EDITABLE_DISPLAY_TIMEOUT disabled."
2807+
#endif
27972808
#endif
27982809

27992810
// Startup Tune requirements
@@ -2806,17 +2817,6 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
28062817
#endif
28072818
#endif
28082819

2809-
/**
2810-
* Display Sleep is not supported by these common displays
2811-
*/
2812-
#if HAS_DISPLAY_SLEEP
2813-
#if ANY(IS_U8GLIB_LM6059_AF, IS_U8GLIB_ST7565_64128, REPRAPWORLD_GRAPHICAL_LCD, FYSETC_MINI_12864, CR10_STOCKDISPLAY, MINIPANEL)
2814-
#error "DISPLAY_SLEEP_MINUTES is not supported by your display."
2815-
#elif !WITHIN(DISPLAY_SLEEP_MINUTES, 0, 255)
2816-
#error "DISPLAY_SLEEP_MINUTES must be between 0 and 255."
2817-
#endif
2818-
#endif
2819-
28202820
/**
28212821
* Some boards forbid the use of -1 Native USB
28222822
*/

Marlin/src/lcd/dogm/marlinui_DOGM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void MarlinUI::draw_kill_screen() {
377377
void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
378378

379379
#if HAS_DISPLAY_SLEEP
380-
void MarlinUI::sleep_display(const bool sleep) { sleep ? u8g.sleepOn() : u8g.sleepOff(); }
380+
void MarlinUI::sleep_display(const bool sleep/*=true*/) { sleep ? u8g.sleepOn() : u8g.sleepOff(); }
381381
#endif
382382

383383
#if HAS_LCD_BRIGHTNESS

Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ TFT_IO tftio;
7878
#include "../marlinui.h"
7979
#endif
8080

81-
#if HAS_TOUCH_BUTTONS && HAS_TOUCH_SLEEP
82-
#define HAS_TOUCH_BUTTONS_SLEEP 1
83-
#endif
84-
8581
#include "../touch/touch_buttons.h"
8682
#include "../scaled_tft.h"
8783

@@ -389,25 +385,29 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
389385

390386
case U8G_DEV_MSG_PAGE_FIRST: {
391387
page = 0;
392-
#if HAS_TOUCH_BUTTONS_SLEEP
393-
static bool sleepCleared;
394-
if (touchBt.isSleeping()) {
395-
if (!sleepCleared) {
396-
sleepCleared = true;
397-
u8g_upscale_clear_lcd(u8g, dev, buffer);
398-
TERN_(HAS_TOUCH_BUTTONS, redrawTouchButtons = true);
388+
#if HAS_TOUCH_BUTTONS
389+
#if HAS_DISPLAY_SLEEP
390+
static bool sleepCleared;
391+
if (touchBt.isSleeping()) {
392+
if (!sleepCleared) {
393+
sleepCleared = true;
394+
u8g_upscale_clear_lcd(u8g, dev, buffer);
395+
redrawTouchButtons = true;
396+
}
397+
break;
399398
}
400-
break;
401-
}
402-
else
403-
sleepCleared = false;
399+
else
400+
sleepCleared = false;
401+
#endif
402+
drawTouchButtons(u8g, dev);
404403
#endif
405-
TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
406404
setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
407405
} break;
408406

409407
case U8G_DEV_MSG_PAGE_NEXT:
410-
if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break;
408+
#if HAS_TOUCH_BUTTONS && HAS_DISPLAY_SLEEP
409+
if (touchBt.isSleeping()) break;
410+
#endif
411411
if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
412412

413413
for (uint8_t y = 0; y < PAGE_HEIGHT; ++y) {

Marlin/src/lcd/marlinui.cpp

+14-33
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
214214

215215
millis_t MarlinUI::screen_timeout_ms = 0;
216216
void MarlinUI::refresh_screen_timeout() {
217-
screen_timeout_ms = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0;
218-
sleep_display(false);
217+
screen_timeout_ms = sleep_timeout_minutes ? millis() + MIN_TO_MS(sleep_timeout_minutes) : 0;
218+
wake_display();
219219
}
220220

221-
#if !HAS_TOUCH_SLEEP && !HAS_MARLINUI_U8GLIB // without DOGM (COLOR_UI)
222-
void MarlinUI::sleep_display(const bool sleep) {} // if unimplemented
223-
#endif
224-
225221
#endif
226222

227223
void MarlinUI::init() {
@@ -766,25 +762,9 @@ void MarlinUI::init() {
766762
draw_kill_screen();
767763
}
768764

769-
#if HAS_TOUCH_SLEEP
770-
#if HAS_TOUCH_BUTTONS
771-
#include "touch/touch_buttons.h"
772-
#else
773-
#include "tft/touch.h"
774-
#endif
775-
// Wake up a sleeping TFT
776-
void MarlinUI::wakeup_screen() {
777-
TERN(HAS_TOUCH_BUTTONS, touchBt.wakeUp(), touch.wakeUp());
778-
}
779-
#if HAS_DISPLAY_SLEEP && !HAS_MARLINUI_U8GLIB // without DOGM (COLOR_UI)
780-
void MarlinUI::sleep_display(const bool sleep) {
781-
if (!sleep) wakeup_screen(); // relay extra wake up events
782-
}
783-
#endif
784-
#endif
785-
786765
void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
787-
TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up the TFT with most buttons
766+
wake_display(); // Wake the screen for any click sound
767+
788768
TERN_(HAS_MARLINUI_MENU, refresh());
789769

790770
#if HAS_ENCODER_ACTION
@@ -1063,7 +1043,7 @@ void MarlinUI::init() {
10631043
abs_diff = epps; // Treat as a full step size
10641044
encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff; // ...in the spin direction.
10651045
}
1066-
TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen());
1046+
if (lastEncoderDiff != encoderDiff) wake_display();
10671047
lastEncoderDiff = encoderDiff;
10681048
#endif
10691049

@@ -1448,14 +1428,14 @@ void MarlinUI::init() {
14481428

14491429
#endif // HAS_ENCODER_ACTION
14501430

1431+
#endif // HAS_WIRED_LCD
1432+
1433+
void MarlinUI::completion_feedback(const bool good/*=true*/) {
1434+
wake_display(); // Wake the screen for all audio feedback
14511435
#if HAS_SOUND
1452-
void MarlinUI::completion_feedback(const bool good/*=true*/) {
1453-
TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
1454-
if (good) OKAY_BUZZ(); else ERR_BUZZ();
1455-
}
1436+
if (good) OKAY_BUZZ(); else ERR_BUZZ();
14561437
#endif
1457-
1458-
#endif // HAS_WIRED_LCD
1438+
}
14591439

14601440
void MarlinUI::host_notify_P(PGM_P const pstr) {
14611441
TERN_(HOST_STATUS_NOTIFICATIONS, hostui.notify_P(pstr));
@@ -1574,7 +1554,7 @@ void MarlinUI::host_notify(const char * const cstr) {
15741554
*/
15751555
void MarlinUI::_set_alert(const char * const ustr, const int8_t level, const bool pgm) {
15761556
pgm ? set_status_and_level_P(ustr, level) : set_status_and_level(ustr, level);
1577-
TERN_(HAS_TOUCH_SLEEP, wakeup_screen());
1557+
wake_display();
15781558
TERN_(HAS_MARLINUI_MENU, return_to_status());
15791559
}
15801560

@@ -1722,7 +1702,8 @@ void MarlinUI::host_notify(const char * const cstr) {
17221702
defer_status_screen();
17231703
#endif
17241704

1725-
TERN_(HAS_TOUCH_SLEEP, wakeup_screen());
1705+
wake_display();
1706+
17261707
TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_PAUSE_RESUME, F("UI Pause"), F("Resume")));
17271708

17281709
LCD_MESSAGE(MSG_PRINT_PAUSED);

Marlin/src/lcd/marlinui.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ class MarlinUI {
292292
static constexpr uint8_t sleep_timeout_max = 99;
293293
static millis_t screen_timeout_ms;
294294
static void refresh_screen_timeout();
295-
static void sleep_display(const bool sleep=true);
296295
#endif
297296

297+
static void sleep_display(const bool=true) IF_DISABLED(HAS_DISPLAY_SLEEP, {});
298+
static void wake_display() { sleep_display(false); }
299+
298300
#if HAS_DWIN_E3V2_BASIC
299301
static void refresh();
300302
#else
@@ -582,16 +584,7 @@ class MarlinUI {
582584
static void pause_filament_display(const millis_t ms=millis()) { next_filament_display = ms + 5000UL; }
583585
#endif
584586

585-
#if HAS_TOUCH_SLEEP
586-
static void wakeup_screen();
587-
#endif
588-
589587
static void quick_feedback(const bool clear_buttons=true);
590-
#if HAS_SOUND
591-
static void completion_feedback(const bool good=true);
592-
#else
593-
static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
594-
#endif
595588

596589
#if ENABLED(ADVANCED_PAUSE_FEATURE)
597590
static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
@@ -604,7 +597,7 @@ class MarlinUI {
604597

605598
static void status_screen();
606599

607-
#endif
600+
#endif // HAS_WIRED_LCD
608601

609602
#if HAS_MARLINUI_U8GLIB
610603
static bool drawing_screen, first_page;
@@ -635,9 +628,10 @@ class MarlinUI {
635628

636629
#if !HAS_WIRED_LCD
637630
static void quick_feedback(const bool=true) {}
638-
static void completion_feedback(const bool=true) {}
639631
#endif
640632

633+
static void completion_feedback(const bool good=true);
634+
641635
#if HAS_MEDIA
642636
#if ALL(SCROLL_LONG_FILENAMES, HAS_MARLINUI_MENU)
643637
#define MARLINUI_SCROLL_NAME 1

Marlin/src/lcd/menu/menu.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ void MenuEditItemBase::goto_edit_screen(
168168
*/
169169
void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
170170
if (currentScreen != screen) {
171+
172+
wake_display();
173+
171174
thermalManager.set_menu_cold_override(false);
172175

173176
TERN_(IS_DWIN_MARLINUI, did_first_redraw = false);

Marlin/src/lcd/menu/menu_media.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void lcd_sd_updir() {
4848
goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
4949
sd_encoder_position = 0xFFFF;
5050
defer_status_screen();
51-
TERN_(HAS_TOUCH_SLEEP, ui.wakeup_screen());
5251
}
5352

5453
#endif

0 commit comments

Comments
 (0)