Skip to content

Commit

Permalink
🔧 TOUCH_IDLE_SLEEP_MINS => DISPLAY_SLEEP_MINUTES
Browse files Browse the repository at this point in the history
Follow up to #26517
  • Loading branch information
thinkyhead committed Feb 4, 2024
1 parent 9364cbb commit 1dee4d9
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 126 deletions.
1 change: 0 additions & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 12 additions & 16 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<minutes> and a menu item
#define EDITABLE_DISPLAY_TIMEOUT // Edit sleep / backlight timeout with M255 S<minutes> and a menu item
#endif

//
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/inc/Changes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
47 changes: 14 additions & 33 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1448,14 +1428,14 @@ void MarlinUI::init() {

#endif // HAS_ENCODER_ACTION

#endif // HAS_WIRED_LCD

void MarlinUI::completion_feedback(const bool good/*=true*/) {
wake_display(); // Wake the screen for all audio feedback
#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();
}
if (good) OKAY_BUZZ(); else ERR_BUZZ();
#endif

#endif // HAS_WIRED_LCD
}

void MarlinUI::host_notify_P(PGM_P const pstr) {
TERN_(HOST_STATUS_NOTIFICATIONS, hostui.notify_P(pstr));
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ class MarlinUI {
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
Expand Down Expand Up @@ -582,16 +584,7 @@ class MarlinUI {
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);
Expand All @@ -604,7 +597,7 @@ class MarlinUI {

static void status_screen();

#endif
#endif // HAS_WIRED_LCD

#if HAS_MARLINUI_U8GLIB
static bool drawing_screen, first_page;
Expand Down Expand Up @@ -635,9 +628,10 @@ class MarlinUI {

#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
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1dee4d9

Please sign in to comment.