From 1dee4d92c61b14458cd394d1f609f0dc80282092 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 4 Feb 2024 12:09:08 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20TOUCH=5FIDLE=5FSLEEP=5FMINS=20?= =?UTF-8?q?=3D>=20DISPLAY=5FSLEEP=5FMINUTES?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow up to #26517 --- Marlin/Configuration.h | 1 - Marlin/Configuration_adv.h | 28 +++++------ Marlin/src/inc/Changes.h | 4 +- Marlin/src/inc/Conditionals_LCD.h | 3 -- Marlin/src/inc/Conditionals_adv.h | 2 +- Marlin/src/inc/SanityCheck.h | 22 ++++----- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 2 +- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 34 ++++++------- Marlin/src/lcd/marlinui.cpp | 49 ++++++------------- Marlin/src/lcd/marlinui.h | 18 +++---- Marlin/src/lcd/menu/menu.cpp | 3 ++ Marlin/src/lcd/menu/menu_media.cpp | 1 - Marlin/src/lcd/tft/touch.cpp | 18 ++++--- Marlin/src/lcd/tft/touch.h | 3 +- Marlin/src/lcd/tft/ui_color_ui.cpp | 2 +- Marlin/src/lcd/tft/ui_common.cpp | 4 +- Marlin/src/lcd/tft/ui_common.h | 6 +-- Marlin/src/lcd/touch/touch_buttons.cpp | 21 +++++--- Marlin/src/lcd/touch/touch_buttons.h | 3 +- Marlin/src/module/settings.cpp | 2 +- Marlin/src/module/temperature.cpp | 8 +-- 21 files changed, 107 insertions(+), 127 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9a0cd1addc..87908d1821 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -3414,7 +3414,6 @@ #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus //#define DISABLE_ENCODER // Disable the click encoder, if any - //#define TOUCH_IDLE_SLEEP_MINS 5 // (minutes) Display Sleep after a period of inactivity. Set with M255 S. #define TOUCH_SCREEN_CALIBRATION diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 49eea39180..558fd70a9e 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1970,17 +1970,6 @@ // Western only. Not available for Cyrillic, Kana, Turkish, Greek, or Chinese. //#define USE_SMALL_INFOFONT - /** - * Graphical Display Sleep - * - * The U8G library provides sleep / wake functions for SH1106, SSD1306, - * SSD1309, and some other DOGM displays. - * Enable this option to save energy and prevent OLED pixel burn-in. - * Adds the menu item Configuration > LCD Timeout (m) to set a wait period - * from 0 (disabled) to 99 minutes. - */ - //#define DISPLAY_SLEEP_MINUTES 2 // (minutes) Timeout before turning off the screen. Set with M255 S. - /** * ST7920-based LCDs can emulate a 16 x 4 character display using * the ST7920 character-generator for very fast screen updates. @@ -2229,13 +2218,20 @@ //#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan #endif -// -// LCD Backlight Timeout -// Requires a display with a controllable backlight -// +/** + * Display Sleep + * Enable this option to save energy and prevent OLED pixel burn-in. + */ +//#define DISPLAY_SLEEP_MINUTES 2 // (minutes) Timeout before turning off the screen + +/** + * LCD Backlight Timeout + * Requires a display with a controllable backlight + */ //#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight + #if defined(DISPLAY_SLEEP_MINUTES) || defined(LCD_BACKLIGHT_TIMEOUT_MINS) - #define EDITABLE_DISPLAY_TIMEOUT // Edit timeout with M255 S and a menu item + #define EDITABLE_DISPLAY_TIMEOUT // Edit sleep / backlight timeout with M255 S and a menu item #endif // diff --git a/Marlin/src/inc/Changes.h b/Marlin/src/inc/Changes.h index 47f23babb2..6156326f69 100644 --- a/Marlin/src/inc/Changes.h +++ b/Marlin/src/inc/Changes.h @@ -600,7 +600,9 @@ #elif defined(LEVEL_CENTER_TOO) #error "LEVEL_CENTER_TOO is now BED_TRAMMING_INCLUDE_CENTER." #elif defined(TOUCH_IDLE_SLEEP) - #error "TOUCH_IDLE_SLEEP (seconds) is now TOUCH_IDLE_SLEEP_MINS (minutes)." + #error "TOUCH_IDLE_SLEEP (seconds) is now DISPLAY_SLEEP_MINUTES (minutes)." +#elif defined(TOUCH_IDLE_SLEEP_MINS) + #error "TOUCH_IDLE_SLEEP_MINS is now DISPLAY_SLEEP_MINUTES." #elif defined(LCD_BACKLIGHT_TIMEOUT) #error "LCD_BACKLIGHT_TIMEOUT (seconds) is now LCD_BACKLIGHT_TIMEOUT_MINS (minutes)." #elif defined(LCD_SET_PROGRESS_MANUALLY) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index bff742a5bc..af2ea772c3 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1850,9 +1850,6 @@ // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' #if ENABLED(TOUCH_SCREEN) - #if TOUCH_IDLE_SLEEP_MINS - #define HAS_TOUCH_SLEEP 1 - #endif #if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046) #define TFT_TOUCH_DEVICE_XPT2046 // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8 #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 379600d915..93acd89aa9 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -912,7 +912,7 @@ #if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, HAS_MEDIA) #define HAS_LEDS_OFF_FLAG 1 #endif -#if defined(DISPLAY_SLEEP_MINUTES) || defined(TOUCH_IDLE_SLEEP_MINS) +#ifdef DISPLAY_SLEEP_MINUTES #define HAS_DISPLAY_SLEEP 1 #endif #ifdef LCD_BACKLIGHT_TIMEOUT_MINS diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a5ba460f7f..0736e96629 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2785,6 +2785,8 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i #if HAS_BACKLIGHT_TIMEOUT #if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2) #error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad." + #elif HAS_DISPLAY_SLEEP + #error "LCD_BACKLIGHT_TIMEOUT_MINS and DISPLAY_SLEEP_MINUTES are not currently supported at the same time." #elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST) #if PIN_EXISTS(LCD_BACKLIGHT) #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 #elif !PIN_EXISTS(LCD_BACKLIGHT) && DISABLED(HAS_DWIN_E3V2) #error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN, NEOPIXEL_BKGD_INDEX_FIRST, or an Ender-3 V2 DWIN LCD." #endif +#elif HAS_DISPLAY_SLEEP + #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) + #error "DISPLAY_SLEEP_MINUTES is not supported by your display." + #undef HAS_DISPLAY_SLEEP + #elif !WITHIN(DISPLAY_SLEEP_MINUTES, 0, 255) + #error "DISPLAY_SLEEP_MINUTES must be between 0 and 255." + #elif DISABLED(EDITABLE_DISPLAY_TIMEOUT) && DISPLAY_SLEEP_MINUTES == 0 + #error "DISPLAY_SLEEP_MINUTES must be greater than 0 with EDITABLE_DISPLAY_TIMEOUT disabled." + #endif #endif // Startup Tune requirements @@ -2806,17 +2817,6 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i #endif #endif -/** - * Display Sleep is not supported by these common displays - */ -#if HAS_DISPLAY_SLEEP - #if ANY(IS_U8GLIB_LM6059_AF, IS_U8GLIB_ST7565_64128, REPRAPWORLD_GRAPHICAL_LCD, FYSETC_MINI_12864, CR10_STOCKDISPLAY, MINIPANEL) - #error "DISPLAY_SLEEP_MINUTES is not supported by your display." - #elif !WITHIN(DISPLAY_SLEEP_MINUTES, 0, 255) - #error "DISPLAY_SLEEP_MINUTES must be between 0 and 255." - #endif -#endif - /** * Some boards forbid the use of -1 Native USB */ diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 08e197ebb5..cfff78ad40 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -377,7 +377,7 @@ void MarlinUI::draw_kill_screen() { void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop #if HAS_DISPLAY_SLEEP - void MarlinUI::sleep_display(const bool sleep) { sleep ? u8g.sleepOn() : u8g.sleepOff(); } + void MarlinUI::sleep_display(const bool sleep/*=true*/) { sleep ? u8g.sleepOn() : u8g.sleepOff(); } #endif #if HAS_LCD_BRIGHTNESS diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index c6aff38dc9..51bbee78b9 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -78,10 +78,6 @@ TFT_IO tftio; #include "../marlinui.h" #endif -#if HAS_TOUCH_BUTTONS && HAS_TOUCH_SLEEP - #define HAS_TOUCH_BUTTONS_SLEEP 1 -#endif - #include "../touch/touch_buttons.h" #include "../scaled_tft.h" @@ -389,25 +385,29 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u case U8G_DEV_MSG_PAGE_FIRST: { page = 0; - #if HAS_TOUCH_BUTTONS_SLEEP - static bool sleepCleared; - if (touchBt.isSleeping()) { - if (!sleepCleared) { - sleepCleared = true; - u8g_upscale_clear_lcd(u8g, dev, buffer); - TERN_(HAS_TOUCH_BUTTONS, redrawTouchButtons = true); + #if HAS_TOUCH_BUTTONS + #if HAS_DISPLAY_SLEEP + static bool sleepCleared; + if (touchBt.isSleeping()) { + if (!sleepCleared) { + sleepCleared = true; + u8g_upscale_clear_lcd(u8g, dev, buffer); + redrawTouchButtons = true; + } + break; } - break; - } - else - sleepCleared = false; + else + sleepCleared = false; + #endif + drawTouchButtons(u8g, dev); #endif - TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev)); setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI); } break; case U8G_DEV_MSG_PAGE_NEXT: - if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break; + #if HAS_TOUCH_BUTTONS && HAS_DISPLAY_SLEEP + if (touchBt.isSleeping()) break; + #endif if (++page > (HEIGHT / PAGE_HEIGHT)) return 1; for (uint8_t y = 0; y < PAGE_HEIGHT; ++y) { diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 23cb0a7058..313131d87a 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -214,14 +214,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; millis_t MarlinUI::screen_timeout_ms = 0; void MarlinUI::refresh_screen_timeout() { - screen_timeout_ms = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0; - sleep_display(false); + screen_timeout_ms = sleep_timeout_minutes ? millis() + MIN_TO_MS(sleep_timeout_minutes) : 0; + wake_display(); } - #if !HAS_TOUCH_SLEEP && !HAS_MARLINUI_U8GLIB // without DOGM (COLOR_UI) - void MarlinUI::sleep_display(const bool sleep) {} // if unimplemented - #endif - #endif void MarlinUI::init() { @@ -766,25 +762,9 @@ void MarlinUI::init() { draw_kill_screen(); } - #if HAS_TOUCH_SLEEP - #if HAS_TOUCH_BUTTONS - #include "touch/touch_buttons.h" - #else - #include "tft/touch.h" - #endif - // Wake up a sleeping TFT - void MarlinUI::wakeup_screen() { - TERN(HAS_TOUCH_BUTTONS, touchBt.wakeUp(), touch.wakeUp()); - } - #if HAS_DISPLAY_SLEEP && !HAS_MARLINUI_U8GLIB // without DOGM (COLOR_UI) - void MarlinUI::sleep_display(const bool sleep) { - if (!sleep) wakeup_screen(); // relay extra wake up events - } - #endif - #endif - void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) { - TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up the TFT with most buttons + wake_display(); // Wake the screen for any click sound + TERN_(HAS_MARLINUI_MENU, refresh()); #if HAS_ENCODER_ACTION @@ -1063,7 +1043,7 @@ void MarlinUI::init() { abs_diff = epps; // Treat as a full step size encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff; // ...in the spin direction. } - TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen()); + if (lastEncoderDiff != encoderDiff) wake_display(); lastEncoderDiff = encoderDiff; #endif @@ -1448,15 +1428,15 @@ void MarlinUI::init() { #endif // HAS_ENCODER_ACTION - #if HAS_SOUND - void MarlinUI::completion_feedback(const bool good/*=true*/) { - TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click... - if (good) OKAY_BUZZ(); else ERR_BUZZ(); - } - #endif - #endif // HAS_WIRED_LCD +void MarlinUI::completion_feedback(const bool good/*=true*/) { + wake_display(); // Wake the screen for all audio feedback + #if HAS_SOUND + if (good) OKAY_BUZZ(); else ERR_BUZZ(); + #endif +} + void MarlinUI::host_notify_P(PGM_P const pstr) { TERN_(HOST_STATUS_NOTIFICATIONS, hostui.notify_P(pstr)); } @@ -1574,7 +1554,7 @@ void MarlinUI::host_notify(const char * const cstr) { */ void MarlinUI::_set_alert(const char * const ustr, const int8_t level, const bool pgm) { pgm ? set_status_and_level_P(ustr, level) : set_status_and_level(ustr, level); - TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); + wake_display(); TERN_(HAS_MARLINUI_MENU, return_to_status()); } @@ -1722,7 +1702,8 @@ void MarlinUI::host_notify(const char * const cstr) { defer_status_screen(); #endif - TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); + wake_display(); + TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_PAUSE_RESUME, F("UI Pause"), F("Resume"))); LCD_MESSAGE(MSG_PRINT_PAUSED); diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index d578826e49..04f4aea24f 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -292,9 +292,11 @@ public: static constexpr uint8_t sleep_timeout_max = 99; static millis_t screen_timeout_ms; static void refresh_screen_timeout(); - static void sleep_display(const bool sleep=true); #endif + static void sleep_display(const bool=true) IF_DISABLED(HAS_DISPLAY_SLEEP, {}); + static void wake_display() { sleep_display(false); } + #if HAS_DWIN_E3V2_BASIC static void refresh(); #else @@ -582,16 +584,7 @@ public: static void pause_filament_display(const millis_t ms=millis()) { next_filament_display = ms + 5000UL; } #endif - #if HAS_TOUCH_SLEEP - static void wakeup_screen(); - #endif - static void quick_feedback(const bool clear_buttons=true); - #if HAS_SOUND - static void completion_feedback(const bool good=true); - #else - static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); } - #endif #if ENABLED(ADVANCED_PAUSE_FEATURE) static void draw_hotend_status(const uint8_t row, const uint8_t extruder); @@ -604,7 +597,7 @@ public: static void status_screen(); - #endif + #endif // HAS_WIRED_LCD #if HAS_MARLINUI_U8GLIB static bool drawing_screen, first_page; @@ -635,9 +628,10 @@ public: #if !HAS_WIRED_LCD static void quick_feedback(const bool=true) {} - static void completion_feedback(const bool=true) {} #endif + static void completion_feedback(const bool good=true); + #if HAS_MEDIA #if ALL(SCROLL_LONG_FILENAMES, HAS_MARLINUI_MENU) #define MARLINUI_SCROLL_NAME 1 diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 1c77d9a092..e98c9b48c0 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -168,6 +168,9 @@ void MenuEditItemBase::goto_edit_screen( */ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) { if (currentScreen != screen) { + + wake_display(); + thermalManager.set_menu_cold_override(false); TERN_(IS_DWIN_MARLINUI, did_first_redraw = false); diff --git a/Marlin/src/lcd/menu/menu_media.cpp b/Marlin/src/lcd/menu/menu_media.cpp index daa396601f..42ff2b1f26 100644 --- a/Marlin/src/lcd/menu/menu_media.cpp +++ b/Marlin/src/lcd/menu/menu_media.cpp @@ -48,7 +48,6 @@ void lcd_sd_updir() { goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items); sd_encoder_position = 0xFFFF; defer_status_screen(); - TERN_(HAS_TOUCH_SLEEP, ui.wakeup_screen()); } #endif diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index d325355002..8ebfc91409 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -38,6 +38,8 @@ #include "tft.h" +Touch touch; + bool Touch::enabled = true; int16_t Touch::x, Touch::y; touch_control_t Touch::controls[]; @@ -48,7 +50,7 @@ millis_t Touch::next_touch_ms = 0, Touch::repeat_delay, Touch::touch_time; TouchControlType Touch::touch_control_type = NONE; -#if HAS_TOUCH_SLEEP +#if HAS_DISPLAY_SLEEP millis_t Touch::next_sleep_ms; // = 0 #endif #if HAS_RESUME_CONTINUE @@ -59,7 +61,7 @@ void Touch::init() { TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); reset(); io.init(); - TERN_(HAS_TOUCH_SLEEP, wakeUp()); + TERN_(HAS_DISPLAY_SLEEP, wakeUp()); enable(); } @@ -278,7 +280,7 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) { #endif #endif - #if HAS_TOUCH_SLEEP + #if HAS_DISPLAY_SLEEP if (is_touched) wakeUp(); else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen()) @@ -288,7 +290,7 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) { return is_touched; } -#if HAS_TOUCH_SLEEP +#if HAS_DISPLAY_SLEEP void Touch::sleepTimeout() { #if HAS_LCD_BRIGHTNESS @@ -308,12 +310,14 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) { next_touch_ms = millis() + 100; safe_delay(20); } - next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes); + next_sleep_ms = ui.sleep_timeout_minutes ? millis() + MIN_TO_MS(ui.sleep_timeout_minutes) : 0; } -#endif // HAS_TOUCH_SLEEP + void MarlinUI::sleep_display(const bool sleep/*=true*/) { + if (!sleep) touch.wakeUp(); + } -Touch touch; +#endif // HAS_DISPLAY_SLEEP bool MarlinUI::touch_pressed() { return touch.is_clicked(); diff --git a/Marlin/src/lcd/tft/touch.h b/Marlin/src/lcd/tft/touch.h index 93f9327a15..efbd427c31 100644 --- a/Marlin/src/lcd/tft/touch.h +++ b/Marlin/src/lcd/tft/touch.h @@ -71,7 +71,6 @@ typedef struct __attribute__((__packed__)) { #define UBL_REPEAT_DELAY 125 #define FREE_MOVE_RANGE 32 -#define TSLP_PREINIT 0 #define TSLP_SLEEPING 1 class Touch { @@ -105,7 +104,7 @@ class Touch { } static void disable() { enabled = false; } static void enable() { enabled = true; } - #if HAS_TOUCH_SLEEP + #if HAS_DISPLAY_SLEEP static millis_t next_sleep_ms; static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; } static void sleepTimeout(); diff --git a/Marlin/src/lcd/tft/ui_color_ui.cpp b/Marlin/src/lcd/tft/ui_color_ui.cpp index 4febd29865..279ea9715a 100644 --- a/Marlin/src/lcd/tft/ui_color_ui.cpp +++ b/Marlin/src/lcd/tft/ui_color_ui.cpp @@ -47,7 +47,7 @@ void MarlinUI::tft_idle() { #if ENABLED(TOUCH_SCREEN) - if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return; + if (TERN0(HAS_DISPLAY_SLEEP, lcd_sleep_task())) return; if (draw_menu_navigation) { add_control(NAVIGATION_PAGE_UP_X, NAVIGATION_PAGE_UP_Y, PAGE_UP, imgPageUp, encoderTopLine > 0); add_control(NAVIGATION_PAGE_DOWN_X, NAVIGATION_PAGE_DOWN_Y, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items); diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index a1766b0676..944be77ab5 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -188,7 +188,7 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { #endif -#if HAS_TOUCH_SLEEP +#if ALL(TOUCH_SCREEN, HAS_DISPLAY_SLEEP) bool lcd_sleep_task() { static bool sleepCleared; @@ -207,7 +207,7 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { return false; } -#endif // HAS_TOUCH_SLEEP +#endif void text_line(const uint16_t y, uint16_t color) { tft.canvas(0, y, TFT_WIDTH, MENU_ITEM_HEIGHT); diff --git a/Marlin/src/lcd/tft/ui_common.h b/Marlin/src/lcd/tft/ui_common.h index 8229ab36ab..3a67768f35 100644 --- a/Marlin/src/lcd/tft/ui_common.h +++ b/Marlin/src/lcd/tft/ui_common.h @@ -104,9 +104,9 @@ void disable_steppers(); #if HAS_EXTRUDERS void e_select(); #endif -#endif -#if HAS_TOUCH_SLEEP - bool lcd_sleep_task(); + #if HAS_DISPLAY_SLEEP + bool lcd_sleep_task(); + #endif #endif void draw_heater_status(uint16_t x, uint16_t y, const int8_t heater); diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 652a043714..f6f4c66e77 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -37,7 +37,7 @@ #error "Unknown Touch Screen Type." #endif -#if HAS_TOUCH_SLEEP +#if HAS_DISPLAY_SLEEP millis_t TouchButtons::next_sleep_ms; #endif @@ -58,7 +58,9 @@ TouchButtons touchBt; void TouchButtons::init() { touchIO.init(); - TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60)); + #if HAS_DISPLAY_SLEEP + next_sleep_ms = ui.sleep_timeout_minutes ? millis() + MIN_TO_MS(ui.sleep_timeout_minutes) : 0; + #endif } uint8_t TouchButtons::read_buttons() { @@ -70,10 +72,10 @@ uint8_t TouchButtons::read_buttons() { const bool is_touched = TOUCH_PORTRAIT == _TOUCH_ORIENTATION ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y); - #if HAS_TOUCH_SLEEP + #if HAS_DISPLAY_SLEEP if (is_touched) wakeUp(); - else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen()) + else if (next_sleep_ms && !isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen()) sleepTimeout(); #endif @@ -129,7 +131,7 @@ uint8_t TouchButtons::read_buttons() { return 0; } -#if HAS_TOUCH_SLEEP +#if HAS_DISPLAY_SLEEP void TouchButtons::sleepTimeout() { #if HAS_LCD_BRIGHTNESS @@ -139,6 +141,7 @@ uint8_t TouchButtons::read_buttons() { #endif next_sleep_ms = TSLP_SLEEPING; } + void TouchButtons::wakeUp() { if (isSleeping()) { #if HAS_LCD_BRIGHTNESS @@ -147,9 +150,13 @@ uint8_t TouchButtons::read_buttons() { WRITE(TFT_BACKLIGHT_PIN, HIGH); #endif } - next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes); + next_sleep_ms = ui.sleep_timeout_minutes ? millis() + MIN_TO_MS(ui.sleep_timeout_minutes) : 0; } -#endif // HAS_TOUCH_SLEEP + void MarlinUI::sleep_display(const bool sleep/*=true*/) { + if (!sleep) touchBt.wakeUp(); + } + +#endif // HAS_DISPLAY_SLEEP #endif // HAS_TOUCH_BUTTONS diff --git a/Marlin/src/lcd/touch/touch_buttons.h b/Marlin/src/lcd/touch/touch_buttons.h index 39768f2594..bfb86c6b6f 100644 --- a/Marlin/src/lcd/touch/touch_buttons.h +++ b/Marlin/src/lcd/touch/touch_buttons.h @@ -53,14 +53,13 @@ #define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING #define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT -#define TSLP_PREINIT 0 #define TSLP_SLEEPING 1 class TouchButtons { public: static void init(); static uint8_t read_buttons(); - #if HAS_TOUCH_SLEEP + #if HAS_DISPLAY_SLEEP static millis_t next_sleep_ms; static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; } static void sleepTimeout(); diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 2dc48ebbf0..b382f80d51 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -3468,7 +3468,7 @@ void MarlinSettings::reset() { #if HAS_BACKLIGHT_TIMEOUT ui.backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS; #elif HAS_DISPLAY_SLEEP - ui.sleep_timeout_minutes = TERN(TOUCH_SCREEN, TOUCH_IDLE_SLEEP_MINS, DISPLAY_SLEEP_MINUTES); + ui.sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES; #endif #endif diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 4ff62d0172..5ac26794a4 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -854,11 +854,11 @@ volatile bool Temperature::raw_temps_ready = false; #endif } // every 2 seconds - // Timeout after MAX_CYCLE_TIME_PID_AUTOTUNE minutes since the last undershoot/overshoot cycle - #ifndef MAX_CYCLE_TIME_PID_AUTOTUNE - #define MAX_CYCLE_TIME_PID_AUTOTUNE 20L + // Timeout after PID_AUTOTUNE_MAX_CYCLE_MINS minutes since the last undershoot/overshoot cycle + #ifndef PID_AUTOTUNE_MAX_CYCLE_MINS + #define PID_AUTOTUNE_MAX_CYCLE_MINS 20L #endif - if ((ms - _MIN(t1, t2)) > (MAX_CYCLE_TIME_PID_AUTOTUNE * 60L * 1000L)) { + if ((ms - _MIN(t1, t2)) > MIN_TO_MS(PID_AUTOTUNE_MAX_CYCLE_MINS)) { TERN_(DWIN_CREALITY_LCD, dwinPopupTemperature(0)); TERN_(PROUI_PID_TUNE, dwinPidTuning(PID_TUNING_TIMEOUT)); TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));