♻️ Display sleep minutes, encoder disable option (#24618)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
EvilGremlin 2022-08-25 20:16:55 +03:00 committed by Scott Lahteine
parent f088722ae8
commit ef1cf0d5a1
23 changed files with 80 additions and 72 deletions

View File

@ -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

View File

@ -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
@ -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

View File

@ -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
@ -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)"
);
}

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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
@ -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

View File

@ -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

View File

@ -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");

View File

@ -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");

View File

@ -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.");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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
@ -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();
@ -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

View File

@ -270,20 +270,19 @@ public:
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

View File

@ -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)

View File

@ -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)

View File

@ -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
@ -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

View File

@ -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

View File

@ -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() {
@ -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

View File

@ -402,8 +402,8 @@ typedef struct SettingsDataStruct {
//
// Display Sleep
//
#if LCD_BACKLIGHT_TIMEOUT
uint16_t lcd_backlight_timeout; // M255 S
#if LCD_BACKLIGHT_TIMEOUT_MINS
uint8_t backlight_timeout_minutes; // M255 S
#elif HAS_DISPLAY_SLEEP
uint8_t sleep_timeout_minutes; // M255 S
#endif
@ -640,7 +640,7 @@ void MarlinSettings::postprocess() {
TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast());
TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness());
#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
ui.refresh_screen_timeout();
@ -1157,8 +1157,8 @@ void MarlinSettings::postprocess() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
EEPROM_WRITE(ui.lcd_backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EEPROM_WRITE(ui.backlight_timeout_minutes);
#elif HAS_DISPLAY_SLEEP
EEPROM_WRITE(ui.sleep_timeout_minutes);
#endif
@ -2108,8 +2108,8 @@ void MarlinSettings::postprocess() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
EEPROM_READ(ui.lcd_backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EEPROM_READ(ui.backlight_timeout_minutes);
#elif HAS_DISPLAY_SLEEP
EEPROM_READ(ui.sleep_timeout_minutes);
#endif
@ -3198,8 +3198,8 @@ void MarlinSettings::reset() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
ui.lcd_backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS;
#elif HAS_DISPLAY_SLEEP
ui.sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES;
#endif

View File

@ -213,7 +213,7 @@ opt_set MOTHERBOARD BOARD_RAMPS_14_EFB EXTRUDERS 1 \
TEMP_SENSOR_0 -2 TEMP_SENSOR_REDUNDANT -2 \
TEMP_SENSOR_REDUNDANT_SOURCE E1 TEMP_SENSOR_REDUNDANT_TARGET E0 \
TEMP_0_CS_PIN 11 TEMP_1_CS_PIN 12 \
LCD_BACKLIGHT_TIMEOUT 30
LCD_BACKLIGHT_TIMEOUT_MINS 2
opt_enable MPCTEMP MINIPANEL
opt_disable PIDTEMP
exec_test $1 $2 "MEGA2560 RAMPS | Redundant temperature sensor | 2x MAX6675 | BL Timeout" "$3"