1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 13:56:24 +00:00

♻️ Refactor status screen timeout

This commit is contained in:
Scott Lahteine 2021-06-27 00:33:44 -05:00
parent e3ae76d76d
commit 2b37a71eba
9 changed files with 56 additions and 54 deletions

View File

@ -3397,10 +3397,15 @@
#endif #endif
#endif #endif
#if HAS_LCD_MENU
// LCD timeout to status screen default is 15s // LCD timeout to status screen default is 15s
#ifndef LCD_TIMEOUT_TO_STATUS #ifndef LCD_TIMEOUT_TO_STATUS
#define LCD_TIMEOUT_TO_STATUS 15000 #define LCD_TIMEOUT_TO_STATUS 15000
#endif #endif
#if LCD_TIMEOUT_TO_STATUS
#define SCREENS_CAN_TIME_OUT 1
#endif
#endif
// Add commands that need sub-codes to this list // Add commands that need sub-codes to this list
#if ANY(G38_PROBE_TARGET, CNC_COORDINATE_SYSTEMS, POWER_LOSS_RECOVERY) #if ANY(G38_PROBE_TARGET, CNC_COORDINATE_SYSTEMS, POWER_LOSS_RECOVERY)

View File

@ -45,7 +45,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
return false; return false;
} }
#if LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
if (EventLoop::get_pressed_tag() != 0) { if (EventLoop::get_pressed_tag() != 0) {
reset_menu_timeout(); reset_menu_timeout();
} }
@ -65,7 +65,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
} }
void BaseScreen::onIdle() { void BaseScreen::onIdle() {
#if LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) { if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
reset_menu_timeout(); reset_menu_timeout();
#if ENABLED(TOUCH_UI_DEBUG) #if ENABLED(TOUCH_UI_DEBUG)
@ -77,12 +77,10 @@ void BaseScreen::onIdle() {
} }
void BaseScreen::reset_menu_timeout() { void BaseScreen::reset_menu_timeout() {
#if LCD_TIMEOUT_TO_STATUS > 0 TERN_(SCREENS_CAN_TIME_OUT, last_interaction = millis());
last_interaction = millis();
#endif
} }
#if LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
uint32_t BaseScreen::last_interaction; uint32_t BaseScreen::last_interaction;
#endif #endif

View File

@ -27,7 +27,7 @@
class BaseScreen : public UIScreen { class BaseScreen : public UIScreen {
protected: protected:
#if LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
static uint32_t last_interaction; static uint32_t last_interaction;
#endif #endif

View File

@ -165,8 +165,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif #endif
#endif #endif
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
bool MarlinUI::defer_return_to_status; bool MarlinUI::defer_return_to_status;
millis_t MarlinUI::return_to_status_ms = 0;
#endif #endif
uint8_t MarlinUI::lcd_status_update_delay = 1; // First update one loop delayed uint8_t MarlinUI::lcd_status_update_delay = 1; // First update one loop delayed
@ -815,9 +816,6 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
LCDViewAction MarlinUI::lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; LCDViewAction MarlinUI::lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
millis_t next_lcd_update_ms; millis_t next_lcd_update_ms;
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
millis_t MarlinUI::return_to_status_ms = 0;
#endif
inline bool can_encode() { inline bool can_encode() {
return !BUTTON_PRESSED(ENC_EN); // Update encoder only when ENC_EN is not LOW (pressed) return !BUTTON_PRESSED(ENC_EN); // Update encoder only when ENC_EN is not LOW (pressed)
@ -828,12 +826,6 @@ void MarlinUI::update() {
static uint16_t max_display_update_time = 0; static uint16_t max_display_update_time = 0;
millis_t ms = millis(); millis_t ms = millis();
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
#define RESET_STATUS_TIMEOUT() (return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS)
#else
#define RESET_STATUS_TIMEOUT() NOOP
#endif
#ifdef LED_BACKLIGHT_TIMEOUT #ifdef LED_BACKLIGHT_TIMEOUT
leds.update_timeout(powersupply_on); leds.update_timeout(powersupply_on);
#endif #endif
@ -859,7 +851,7 @@ void MarlinUI::update() {
#if HAS_TOUCH_BUTTONS #if HAS_TOUCH_BUTTONS
if (touch_buttons) { if (touch_buttons) {
RESET_STATUS_TIMEOUT(); reset_status_timeout(ms);
if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority
if (ELAPSED(ms, next_button_update_ms)) { if (ELAPSED(ms, next_button_update_ms)) {
encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * epps * encoderDirection; encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * epps * encoderDirection;
@ -914,7 +906,7 @@ void MarlinUI::update() {
TERN_(HAS_SLOW_BUTTONS, slow_buttons = read_slow_buttons()); // Buttons that take too long to read in interrupt context TERN_(HAS_SLOW_BUTTONS, slow_buttons = read_slow_buttons()); // Buttons that take too long to read in interrupt context
if (TERN0(IS_RRW_KEYPAD, handle_keypad())) if (TERN0(IS_RRW_KEYPAD, handle_keypad()))
RESET_STATUS_TIMEOUT(); reset_status_timeout(ms);
uint8_t abs_diff = ABS(encoderDiff); uint8_t abs_diff = ABS(encoderDiff);
@ -980,7 +972,7 @@ void MarlinUI::update() {
encoderDiff = 0; encoderDiff = 0;
} }
RESET_STATUS_TIMEOUT(); reset_status_timeout(ms);
refresh(LCDVIEW_REDRAW_NOW); refresh(LCDVIEW_REDRAW_NOW);
@ -1006,7 +998,7 @@ void MarlinUI::update() {
lcd_status_update_delay = ++filename_scroll_pos >= filename_scroll_max ? 12 : 4; // Long delay at end and start lcd_status_update_delay = ++filename_scroll_pos >= filename_scroll_max ? 12 : 4; // Long delay at end and start
if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0; if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0;
refresh(LCDVIEW_REDRAW_NOW); refresh(LCDVIEW_REDRAW_NOW);
RESET_STATUS_TIMEOUT(); reset_status_timeout(ms);
} }
#endif #endif
@ -1075,10 +1067,10 @@ void MarlinUI::update() {
NOLESS(max_display_update_time, millis() - ms); NOLESS(max_display_update_time, millis() - ms);
} }
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0 #if SCREENS_CAN_TIME_OUT
// Return to Status Screen after a timeout // Return to Status Screen after a timeout
if (on_status_screen() || defer_return_to_status) if (on_status_screen() || defer_return_to_status)
RESET_STATUS_TIMEOUT(); reset_status_timeout(ms);
else if (ELAPSED(ms, return_to_status_ms)) else if (ELAPSED(ms, return_to_status_ms))
return_to_status(); return_to_status();
#endif #endif

View File

@ -445,11 +445,14 @@ public:
static PGM_P get_preheat_label(const uint8_t m); static PGM_P get_preheat_label(const uint8_t m);
#endif #endif
#if HAS_LCD_MENU #if SCREENS_CAN_TIME_OUT
#if LCD_TIMEOUT_TO_STATUS static inline void reset_status_timeout(const millis_t ms) { return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; }
static millis_t return_to_status_ms; #else
static inline void reset_status_timeout(const millis_t) {}
#endif #endif
#if HAS_LCD_MENU
#if HAS_TOUCH_BUTTONS #if HAS_TOUCH_BUTTONS
static uint8_t touch_buttons; static uint8_t touch_buttons;
static uint8_t repeat_delay; static uint8_t repeat_delay;
@ -479,7 +482,7 @@ public:
static screenFunc_t currentScreen; static screenFunc_t currentScreen;
static bool screen_changed; static bool screen_changed;
static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0); static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
static void save_previous_screen(); static void push_current_screen();
// goto_previous_screen and go_back may also be used as menu item callbacks // goto_previous_screen and go_back may also be used as menu item callbacks
static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back)); static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
@ -494,12 +497,12 @@ public:
static void lcd_in_status(const bool inStatus); static void lcd_in_status(const bool inStatus);
#endif #endif
FORCE_INLINE static bool screen_is_sticky() {
return TERN1(SCREENS_CAN_TIME_OUT, defer_return_to_status);
}
FORCE_INLINE static void defer_status_screen(const bool defer=true) { FORCE_INLINE static void defer_status_screen(const bool defer=true) {
#if LCD_TIMEOUT_TO_STATUS > 0 TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
defer_return_to_status = defer;
#else
UNUSED(defer);
#endif
} }
static inline void goto_previous_screen_no_defer() { static inline void goto_previous_screen_no_defer() {
@ -651,16 +654,18 @@ public:
private: private:
#if SCREENS_CAN_TIME_OUT
static millis_t return_to_status_ms;
static bool defer_return_to_status;
#else
static constexpr bool defer_return_to_status = false;
#endif
#if HAS_STATUS_MESSAGE #if HAS_STATUS_MESSAGE
static void finish_status(const bool persist); static void finish_status(const bool persist);
#endif #endif
#if HAS_WIRED_LCD #if HAS_WIRED_LCD
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
static bool defer_return_to_status;
#else
static constexpr bool defer_return_to_status = false;
#endif
static void draw_status_screen(); static void draw_status_screen();
#if HAS_GRAPHICAL_TFT #if HAS_GRAPHICAL_TFT
static void tft_idle(); static void tft_idle();

View File

@ -50,9 +50,12 @@
int8_t encoderTopLine, encoderLine, screen_items; int8_t encoderTopLine, encoderLine, screen_items;
typedef struct { typedef struct {
screenFunc_t menu_function; screenFunc_t menu_function; // The screen's function
uint32_t encoder_position; uint32_t encoder_position; // The position of the encoder
int8_t top_line, items; int8_t top_line, items; // The amount of scroll, and the number of items
#if SCREENS_CAN_TIME_OUT
bool sticky; // The screen is sticky
#endif
} menuPosition; } menuPosition;
menuPosition screen_history[6]; menuPosition screen_history[6];
uint8_t screen_history_depth = 0; uint8_t screen_history_depth = 0;
@ -75,9 +78,9 @@ bool MenuEditItemBase::liveEdit;
void MarlinUI::return_to_status() { goto_screen(status_screen); } void MarlinUI::return_to_status() { goto_screen(status_screen); }
void MarlinUI::save_previous_screen() { void MarlinUI::push_current_screen() {
if (screen_history_depth < COUNT(screen_history)) if (screen_history_depth < COUNT(screen_history))
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items }; screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items OPTARG(SCREENS_CAN_TIME_OUT, screen_is_sticky()) };
} }
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) { void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
@ -90,6 +93,7 @@ void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_b
is_back ? 0 : sh.top_line, is_back ? 0 : sh.top_line,
sh.items sh.items
); );
defer_status_screen(TERN_(SCREENS_CAN_TIME_OUT, sh.sticky));
} }
else else
return_to_status(); return_to_status();
@ -147,7 +151,7 @@ void MenuEditItemBase::goto_edit_screen(
) { ) {
TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true); TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
ui.screen_changed = true; ui.screen_changed = true;
ui.save_previous_screen(); ui.push_current_screen();
ui.refresh(); ui.refresh();
editLabel = el; editLabel = el;
editValue = ev; editValue = ev;
@ -237,7 +241,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
// //
void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) { void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) {
static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING); static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
save_previous_screen(); push_current_screen();
goto_screen([]{ goto_screen([]{
if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message); if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message);
}); });
@ -371,6 +375,7 @@ void MenuItem_confirm::select_screen(
selectFunc_t yesFunc, selectFunc_t noFunc, selectFunc_t yesFunc, selectFunc_t noFunc,
PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/ PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
) { ) {
ui.defer_status_screen();
const bool ui_selection = ui.update_selection(), got_click = ui.use_click(); const bool ui_selection = ui.update_selection(), got_click = ui.use_click();
if (got_click || ui.should_draw()) { if (got_click || ui.should_draw()) {
draw_select_screen(yes, no, ui_selection, pref, string, suff); draw_select_screen(yes, no, ui_selection, pref, string, suff);
@ -378,7 +383,6 @@ void MenuItem_confirm::select_screen(
selectFunc_t callFunc = ui_selection ? yesFunc : noFunc; selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
if (callFunc) callFunc(); else ui.goto_previous_screen(); if (callFunc) callFunc(); else ui.goto_previous_screen();
} }
ui.defer_status_screen();
} }
} }

View File

@ -39,7 +39,7 @@ class MenuItem_submenu : public MenuItemBase {
FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) { FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
_draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]); _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
} }
static inline void action(PGM_P const, const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); } static inline void action(PGM_P const, const screenFunc_t func) { ui.push_current_screen(); ui.goto_screen(func); }
}; };
// Any menu item that invokes an immediate action // Any menu item that invokes an immediate action
@ -406,7 +406,7 @@ class MenuItem_bool : public MenuEditItemBase {
#define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \ #define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
if (encoderLine == _thisItemNr && ui.use_click()) { \ if (encoderLine == _thisItemNr && ui.use_click()) { \
ui.save_previous_screen(); \ ui.push_current_screen(); \
ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \ ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
return; \ return; \
} \ } \

View File

@ -177,7 +177,7 @@ void Password::menu_password() {
START_MENU(); START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS); BACK_ITEM(MSG_ADVANCED_SETTINGS);
SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password); SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password);
ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.save_previous_screen(); remove_password(); } ); ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.push_current_screen(); remove_password(); } );
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings); ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
#endif #endif

View File

@ -93,9 +93,7 @@ void Touch::idle() {
} }
#endif #endif
#if LCD_TIMEOUT_TO_STATUS ui.reset_status_timeout(last_touch_ms);
ui.return_to_status_ms = last_touch_ms + LCD_TIMEOUT_TO_STATUS;
#endif
if (touch_time) { if (touch_time) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)