mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-27 05:48:43 +00:00
♻️ Refactor status screen timeout
This commit is contained in:
parent
e3ae76d76d
commit
2b37a71eba
@ -3397,9 +3397,14 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// LCD timeout to status screen default is 15s
|
||||
#ifndef LCD_TIMEOUT_TO_STATUS
|
||||
#define LCD_TIMEOUT_TO_STATUS 15000
|
||||
#if HAS_LCD_MENU
|
||||
// LCD timeout to status screen default is 15s
|
||||
#ifndef LCD_TIMEOUT_TO_STATUS
|
||||
#define LCD_TIMEOUT_TO_STATUS 15000
|
||||
#endif
|
||||
#if LCD_TIMEOUT_TO_STATUS
|
||||
#define SCREENS_CAN_TIME_OUT 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Add commands that need sub-codes to this list
|
||||
|
@ -45,7 +45,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
|
||||
return false;
|
||||
}
|
||||
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
if (EventLoop::get_pressed_tag() != 0) {
|
||||
reset_menu_timeout();
|
||||
}
|
||||
@ -65,7 +65,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
|
||||
}
|
||||
|
||||
void BaseScreen::onIdle() {
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
|
||||
reset_menu_timeout();
|
||||
#if ENABLED(TOUCH_UI_DEBUG)
|
||||
@ -77,12 +77,10 @@ void BaseScreen::onIdle() {
|
||||
}
|
||||
|
||||
void BaseScreen::reset_menu_timeout() {
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
last_interaction = millis();
|
||||
#endif
|
||||
TERN_(SCREENS_CAN_TIME_OUT, last_interaction = millis());
|
||||
}
|
||||
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
uint32_t BaseScreen::last_interaction;
|
||||
#endif
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
class BaseScreen : public UIScreen {
|
||||
protected:
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
static uint32_t last_interaction;
|
||||
#endif
|
||||
|
||||
|
@ -165,8 +165,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
bool MarlinUI::defer_return_to_status;
|
||||
millis_t MarlinUI::return_to_status_ms = 0;
|
||||
#endif
|
||||
|
||||
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;
|
||||
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() {
|
||||
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;
|
||||
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
|
||||
leds.update_timeout(powersupply_on);
|
||||
#endif
|
||||
@ -859,7 +851,7 @@ void MarlinUI::update() {
|
||||
|
||||
#if HAS_TOUCH_BUTTONS
|
||||
if (touch_buttons) {
|
||||
RESET_STATUS_TIMEOUT();
|
||||
reset_status_timeout(ms);
|
||||
if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority
|
||||
if (ELAPSED(ms, next_button_update_ms)) {
|
||||
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
|
||||
|
||||
if (TERN0(IS_RRW_KEYPAD, handle_keypad()))
|
||||
RESET_STATUS_TIMEOUT();
|
||||
reset_status_timeout(ms);
|
||||
|
||||
uint8_t abs_diff = ABS(encoderDiff);
|
||||
|
||||
@ -980,7 +972,7 @@ void MarlinUI::update() {
|
||||
encoderDiff = 0;
|
||||
}
|
||||
|
||||
RESET_STATUS_TIMEOUT();
|
||||
reset_status_timeout(ms);
|
||||
|
||||
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
|
||||
if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0;
|
||||
refresh(LCDVIEW_REDRAW_NOW);
|
||||
RESET_STATUS_TIMEOUT();
|
||||
reset_status_timeout(ms);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1075,10 +1067,10 @@ void MarlinUI::update() {
|
||||
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
|
||||
if (on_status_screen() || defer_return_to_status)
|
||||
RESET_STATUS_TIMEOUT();
|
||||
reset_status_timeout(ms);
|
||||
else if (ELAPSED(ms, return_to_status_ms))
|
||||
return_to_status();
|
||||
#endif
|
||||
|
@ -445,10 +445,13 @@ public:
|
||||
static PGM_P get_preheat_label(const uint8_t m);
|
||||
#endif
|
||||
|
||||
#if SCREENS_CAN_TIME_OUT
|
||||
static inline void reset_status_timeout(const millis_t ms) { return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; }
|
||||
#else
|
||||
static inline void reset_status_timeout(const millis_t) {}
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_MENU
|
||||
#if LCD_TIMEOUT_TO_STATUS
|
||||
static millis_t return_to_status_ms;
|
||||
#endif
|
||||
|
||||
#if HAS_TOUCH_BUTTONS
|
||||
static uint8_t touch_buttons;
|
||||
@ -479,7 +482,7 @@ public:
|
||||
static screenFunc_t currentScreen;
|
||||
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 save_previous_screen();
|
||||
static void push_current_screen();
|
||||
|
||||
// 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));
|
||||
@ -494,12 +497,12 @@ public:
|
||||
static void lcd_in_status(const bool inStatus);
|
||||
#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) {
|
||||
#if LCD_TIMEOUT_TO_STATUS > 0
|
||||
defer_return_to_status = defer;
|
||||
#else
|
||||
UNUSED(defer);
|
||||
#endif
|
||||
TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
|
||||
}
|
||||
|
||||
static inline void goto_previous_screen_no_defer() {
|
||||
@ -651,16 +654,18 @@ public:
|
||||
|
||||
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
|
||||
static void finish_status(const bool persist);
|
||||
#endif
|
||||
|
||||
#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();
|
||||
#if HAS_GRAPHICAL_TFT
|
||||
static void tft_idle();
|
||||
|
@ -50,9 +50,12 @@
|
||||
int8_t encoderTopLine, encoderLine, screen_items;
|
||||
|
||||
typedef struct {
|
||||
screenFunc_t menu_function;
|
||||
uint32_t encoder_position;
|
||||
int8_t top_line, items;
|
||||
screenFunc_t menu_function; // The screen's function
|
||||
uint32_t encoder_position; // The position of the encoder
|
||||
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 screen_history[6];
|
||||
uint8_t screen_history_depth = 0;
|
||||
@ -75,9 +78,9 @@ bool MenuEditItemBase::liveEdit;
|
||||
|
||||
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))
|
||||
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*/)) {
|
||||
@ -90,6 +93,7 @@ void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_b
|
||||
is_back ? 0 : sh.top_line,
|
||||
sh.items
|
||||
);
|
||||
defer_status_screen(TERN_(SCREENS_CAN_TIME_OUT, sh.sticky));
|
||||
}
|
||||
else
|
||||
return_to_status();
|
||||
@ -147,7 +151,7 @@ void MenuEditItemBase::goto_edit_screen(
|
||||
) {
|
||||
TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
|
||||
ui.screen_changed = true;
|
||||
ui.save_previous_screen();
|
||||
ui.push_current_screen();
|
||||
ui.refresh();
|
||||
editLabel = el;
|
||||
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*/) {
|
||||
static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
|
||||
save_previous_screen();
|
||||
push_current_screen();
|
||||
goto_screen([]{
|
||||
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,
|
||||
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();
|
||||
if (got_click || ui.should_draw()) {
|
||||
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;
|
||||
if (callFunc) callFunc(); else ui.goto_previous_screen();
|
||||
}
|
||||
ui.defer_status_screen();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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, ...) {
|
||||
_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
|
||||
@ -406,7 +406,7 @@ class MenuItem_bool : public MenuEditItemBase {
|
||||
|
||||
#define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
|
||||
if (encoderLine == _thisItemNr && ui.use_click()) { \
|
||||
ui.save_previous_screen(); \
|
||||
ui.push_current_screen(); \
|
||||
ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
|
||||
return; \
|
||||
} \
|
||||
|
@ -177,7 +177,7 @@ void Password::menu_password() {
|
||||
START_MENU();
|
||||
BACK_ITEM(MSG_ADVANCED_SETTINGS);
|
||||
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)
|
||||
ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
|
||||
#endif
|
||||
|
@ -93,9 +93,7 @@ void Touch::idle() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LCD_TIMEOUT_TO_STATUS
|
||||
ui.return_to_status_ms = last_touch_ms + LCD_TIMEOUT_TO_STATUS;
|
||||
#endif
|
||||
ui.reset_status_timeout(last_touch_ms);
|
||||
|
||||
if (touch_time) {
|
||||
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||
|
Loading…
Reference in New Issue
Block a user