Skip to content

Commit

Permalink
♻️ Display sleep minutes, encoder disable option (MarlinFirmware#24618)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
EvilGremlin and thinkyhead authored Aug 25, 2022
1 parent 6704c0b commit 2f91154
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 72 deletions.
7 changes: 4 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3156,10 +3156,11 @@
//
//#define TOUCH_SCREEN
#if ENABLED(TOUCH_SCREEN)
#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus

//#define TOUCH_IDLE_SLEEP 300 // (s) Turn off the TFT backlight if set (5mn)
//#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
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@
//
// LCD Backlight Timeout
//
//#define LCD_BACKLIGHT_TIMEOUT 30 // (s) Timeout before turning off the backlight
//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight

#if HAS_BED_PROBE && EITHER(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI)
//#define PROBE_OFFSET_WIZARD // Add a Probe Z Offset calibration option to the LCD menu
Expand Down Expand Up @@ -1739,7 +1739,7 @@
* 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
//#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
Expand Down
14 changes: 5 additions & 9 deletions Marlin/src/gcode/lcd/M255.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
*/
void GcodeSuite::M255() {
if (parser.seenval('S')) {
const int m = parser.value_int();
#if HAS_DISPLAY_SLEEP
const int m = parser.value_int();
ui.sleep_timeout_minutes = constrain(m, SLEEP_TIMEOUT_MIN, SLEEP_TIMEOUT_MAX);
ui.sleep_timeout_minutes = constrain(m, ui.sleep_timeout_min, ui.sleep_timeout_max);
#else
const unsigned int s = parser.value_ushort() * 60;
ui.lcd_backlight_timeout = constrain(s, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX);
ui.backlight_timeout_minutes = constrain(m, ui.backlight_timeout_min, ui.backlight_timeout_max);
#endif
}
else
Expand All @@ -47,11 +46,8 @@ void GcodeSuite::M255() {
void GcodeSuite::M255_report(const bool forReplay/*=true*/) {
report_heading_etc(forReplay, F(STR_DISPLAY_SLEEP));
SERIAL_ECHOLNPGM(" M255 S",
#if HAS_DISPLAY_SLEEP
ui.sleep_timeout_minutes, " ; (minutes)"
#else
ui.lcd_backlight_timeout, " ; (seconds)"
#endif
TERN(HAS_DISPLAY_SLEEP, ui.sleep_timeout_minutes, ui.backlight_timeout_minutes),
" ; (minutes)"
);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@

// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
#if ENABLED(TOUCH_SCREEN)
#if TOUCH_IDLE_SLEEP
#if TOUCH_IDLE_SLEEP_MINS
#define HAS_TOUCH_SLEEP 1
#endif
#if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@
#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT)
#define HAS_LEDS_OFF_FLAG 1
#endif
#ifdef DISPLAY_SLEEP_MINUTES
#ifdef DISPLAY_SLEEP_MINUTES || TOUCH_IDLE_SLEEP_MINS
#define HAS_DISPLAY_SLEEP 1
#endif
#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT
#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT_MINS
#define HAS_GCODE_M255 1
#endif

Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,10 @@
#define HAS_ROTARY_ENCODER 1
#endif

#if DISABLED(DISABLE_ENCODER) && ANY(HAS_ROTARY_ENCODER, HAS_ADC_BUTTONS) && ANY(TFT_CLASSIC_UI, TFT_COLOR_UI)
#define HAS_BACK_ITEM 1
#endif

#if PIN_EXISTS(SAFE_POWER) && DISABLED(DISABLE_DRIVER_SAFE_POWER_PROTECT)
#define HAS_DRIVER_SAFE_POWER_PROTECT 1
#endif
Expand Down
10 changes: 7 additions & 3 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@
#error "LEVEL_CORNERS_* settings have been renamed BED_TRAMMING_*."
#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)."
#elif defined(LCD_BACKLIGHT_TIMEOUT)
#error "LCD_BACKLIGHT_TIMEOUT (seconds) is now LCD_BACKLIGHT_TIMEOUT_MINS (minutes)."
#endif

// L64xx stepper drivers have been removed
Expand Down Expand Up @@ -3030,11 +3034,11 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif
#endif

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
#if !HAS_ENCODER_ACTION
#error "LCD_BACKLIGHT_TIMEOUT requires an LCD with encoder or keypad."
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
#elif !PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_TIMEOUT requires LCD_BACKLIGHT_PIN."
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN."
#endif
#endif

Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ void MarlinUI::draw_kill_screen() {
void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop

#if HAS_DISPLAY_SLEEP
void MarlinUI::sleep_on() { u8g.sleepOn(); }
void MarlinUI::sleep_off() { u8g.sleepOff(); }
void MarlinUI::sleep_display(const bool sleep) { sleep ? u8g.sleepOn() : u8g.sleepOff(); }
#endif

#if HAS_LCD_BRIGHTNESS
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_de.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ namespace Language_de {
LSTR MSG_ADVANCE_K_E = _UxGT("Vorschubfaktor *");
LSTR MSG_CONTRAST = _UxGT("LCD-Kontrast");
LSTR MSG_BRIGHTNESS = _UxGT("LCD-Helligkeit");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD-Ruhezustand (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Timeout (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("LCD ausschalten");
LSTR MSG_STORE_EEPROM = _UxGT("Konfig. speichern");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ namespace Language_en {
LSTR MSG_ADVANCE_K_E = _UxGT("Advance K *");
LSTR MSG_CONTRAST = _UxGT("LCD Contrast");
LSTR MSG_BRIGHTNESS = _UxGT("LCD Brightness");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD Timeout (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Timeout (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Backlight Off");
LSTR MSG_STORE_EEPROM = _UxGT("Store Settings");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/language/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ namespace Language_fr {
LSTR MSG_ADVANCE_K_E = _UxGT("Avance K *");
LSTR MSG_BRIGHTNESS = _UxGT("Luminosité LCD");
LSTR MSG_CONTRAST = _UxGT("Contraste LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Veille LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Veille LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Éteindre l'écran LCD");
LSTR MSG_STORE_EEPROM = _UxGT("Enregistrer config.");
LSTR MSG_LOAD_EEPROM = _UxGT("Charger config.");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ namespace Language_it {
LSTR MSG_ADVANCE_K_E = _UxGT("K Avanzamento *");
LSTR MSG_CONTRAST = _UxGT("Contrasto LCD");
LSTR MSG_BRIGHTNESS = _UxGT("Luminosità LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Timeout LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Timeout LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Spegni Retroillum.");
LSTR MSG_STORE_EEPROM = _UxGT("Salva impostazioni");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_sk.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ namespace Language_sk {
LSTR MSG_ADVANCE_K_E = _UxGT("K pre posun *");
LSTR MSG_CONTRAST = _UxGT("Kontrast LCD");
LSTR MSG_BRIGHTNESS = _UxGT("Jas LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Čas. limit LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Čas. limit LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Podsviet. vyp.");
LSTR MSG_STORE_EEPROM = _UxGT("Uložiť nastavenie");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/language/language_uk.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace Language_uk {
LSTR MSG_CONTRAST = _UxGT("Контраст");
LSTR MSG_BRIGHTNESS = _UxGT("Яскравість");
#endif
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD Таймаут, с");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Таймаут, x");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Підсвітка вимк.");
LSTR MSG_STORE_EEPROM = _UxGT("Зберегти в EEPROM");
LSTR MSG_LOAD_EEPROM = _UxGT("Зчитати з EEPROM");
Expand Down
18 changes: 11 additions & 7 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,26 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
#endif

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS

uint16_t MarlinUI::lcd_backlight_timeout; // Initialized by settings.load()
constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;

uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::backlight_off_ms = 0;
void MarlinUI::refresh_backlight_timeout() {
backlight_off_ms = lcd_backlight_timeout ? millis() + lcd_backlight_timeout * 1000UL : 0;
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
WRITE(LCD_BACKLIGHT_PIN, HIGH);
}

#elif HAS_DISPLAY_SLEEP

constexpr uint8_t MarlinUI::sleep_timeout_min, MarlinUI::sleep_timeout_max;

uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::screen_timeout_millis = 0;
void MarlinUI::refresh_screen_timeout() {
screen_timeout_millis = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0;
sleep_off();
sleep_display(false);
}

#endif
Expand Down Expand Up @@ -1059,7 +1063,7 @@ void MarlinUI::init() {

reset_status_timeout(ms);

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
refresh_screen_timeout();
Expand Down Expand Up @@ -1169,14 +1173,14 @@ void MarlinUI::init() {
return_to_status();
#endif

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
backlight_off_ms = 0;
}
#elif HAS_DISPLAY_SLEEP
if (screen_timeout_millis && ELAPSED(ms, screen_timeout_millis))
sleep_on();
sleep_display();
#endif

// Change state of drawing flag between screen updates
Expand Down
15 changes: 7 additions & 8 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,19 @@ class MarlinUI {
FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
#endif

#if LCD_BACKLIGHT_TIMEOUT
#define LCD_BKL_TIMEOUT_MIN 1u
#define LCD_BKL_TIMEOUT_MAX UINT16_MAX // Slightly more than 18 hours
static uint16_t lcd_backlight_timeout;
#if LCD_BACKLIGHT_TIMEOUT_MINS
static constexpr uint8_t backlight_timeout_min = 0;
static constexpr uint8_t backlight_timeout_max = 99;
static uint8_t backlight_timeout_minutes;
static millis_t backlight_off_ms;
static void refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
#define SLEEP_TIMEOUT_MIN 0
#define SLEEP_TIMEOUT_MAX 99
static constexpr uint8_t sleep_timeout_min = 0;
static constexpr uint8_t sleep_timeout_max = 99;
static uint8_t sleep_timeout_minutes;
static millis_t screen_timeout_millis;
static void refresh_screen_timeout();
static void sleep_on();
static void sleep_off();
static void sleep_display(const bool sleep=true);
#endif

#if HAS_DWIN_E3V2_BASIC
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,10 @@ void menu_configuration() {
//
// Set display backlight / sleep timeout
//
#if LCD_BACKLIGHT_TIMEOUT && LCD_BKL_TIMEOUT_MIN < LCD_BKL_TIMEOUT_MAX
EDIT_ITEM(uint16_4, MSG_LCD_TIMEOUT_SEC, &ui.lcd_backlight_timeout, LCD_BKL_TIMEOUT_MIN, LCD_BKL_TIMEOUT_MAX, ui.refresh_backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout);
#elif HAS_DISPLAY_SLEEP
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, SLEEP_TIMEOUT_MIN, SLEEP_TIMEOUT_MAX, ui.refresh_screen_timeout);
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout);
#endif

#if ENABLED(FWRETRACT)
Expand Down
9 changes: 7 additions & 2 deletions Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,13 @@ class MenuItem_bool : public MenuEditItemBase {

// Predefined menu item types //

#define BACK_ITEM_F(FLABEL) MENU_ITEM_F(back, FLABEL)
#define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)
#if HAS_BACK_ITEM
#define BACK_ITEM_F(FLABEL) MENU_ITEM_F(back, FLABEL)
#define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)
#else
#define BACK_ITEM_F(FLABEL) NOOP
#define BACK_ITEM(LABEL) NOOP
#endif

#define ACTION_ITEM_N_S_F(N, S, FLABEL, ACTION) MENU_ITEM_N_S_F(function, N, S, FLABEL, ACTION)
#define ACTION_ITEM_N_S(N, S, LABEL, ACTION) ACTION_ITEM_N_S_F(N, S, GET_TEXT_F(LABEL), ACTION)
Expand Down
22 changes: 11 additions & 11 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ void menu_main() {
SUBMENU(MSG_TEMPERATURE, menu_temperature);
#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
YESNO_ITEM(MSG_FILAMENTCHANGE,
menu_change_filament, nullptr,
GET_TEXT_F(MSG_FILAMENTCHANGE), (const char *)nullptr, F("?")
);
#else
SUBMENU(MSG_FILAMENTCHANGE, menu_change_filament);
#endif
#endif

#if HAS_POWER_MONITOR
SUBMENU(MSG_POWER_MONITOR, menu_power_monitor);
#endif
Expand All @@ -349,17 +360,6 @@ void menu_main() {
}
#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
YESNO_ITEM(MSG_FILAMENTCHANGE,
menu_change_filament, nullptr,
GET_TEXT_F(MSG_FILAMENTCHANGE), (const char *)nullptr, F("?")
);
#else
SUBMENU(MSG_FILAMENTCHANGE, menu_change_filament);
#endif
#endif

#if ENABLED(LCD_INFO_MENU)
SUBMENU(MSG_INFO_MENU, menu_info);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
}

#endif // HAS_TOUCH_SLEEP
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TouchButtons touchBt;

void TouchButtons::init() {
touchIO.Init();
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60));
}

uint8_t TouchButtons::read_buttons() {
Expand Down Expand Up @@ -135,7 +135,7 @@ uint8_t TouchButtons::read_buttons() {
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
}

#endif // HAS_TOUCH_SLEEP
Expand Down
Loading

0 comments on commit 2f91154

Please sign in to comment.