Browse Source

♻️ Refactor status screen timeout

Scott Lahteine 4 years ago
parent
commit
f9051e5469

+ 8
- 3
Marlin/src/inc/Conditionals_post.h View File

@@ -3397,9 +3397,14 @@
3397 3397
   #endif
3398 3398
 #endif
3399 3399
 
3400
-// LCD timeout to status screen default is 15s
3401
-#ifndef LCD_TIMEOUT_TO_STATUS
3402
-  #define LCD_TIMEOUT_TO_STATUS 15000
3400
+#if HAS_LCD_MENU
3401
+  // LCD timeout to status screen default is 15s
3402
+  #ifndef LCD_TIMEOUT_TO_STATUS
3403
+    #define LCD_TIMEOUT_TO_STATUS 15000
3404
+  #endif
3405
+  #if LCD_TIMEOUT_TO_STATUS
3406
+    #define SCREENS_CAN_TIME_OUT 1
3407
+  #endif
3403 3408
 #endif
3404 3409
 
3405 3410
 // Add commands that need sub-codes to this list

+ 4
- 6
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_screen.cpp View File

@@ -45,7 +45,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
45 45
     return false;
46 46
   }
47 47
 
48
-  #if LCD_TIMEOUT_TO_STATUS > 0
48
+  #if SCREENS_CAN_TIME_OUT
49 49
     if (EventLoop::get_pressed_tag() != 0) {
50 50
       reset_menu_timeout();
51 51
     }
@@ -65,7 +65,7 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t
65 65
 }
66 66
 
67 67
 void BaseScreen::onIdle() {
68
-  #if LCD_TIMEOUT_TO_STATUS > 0
68
+  #if SCREENS_CAN_TIME_OUT
69 69
     if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
70 70
       reset_menu_timeout();
71 71
       #if ENABLED(TOUCH_UI_DEBUG)
@@ -77,12 +77,10 @@ void BaseScreen::onIdle() {
77 77
 }
78 78
 
79 79
 void BaseScreen::reset_menu_timeout() {
80
-  #if LCD_TIMEOUT_TO_STATUS > 0
81
-    last_interaction = millis();
82
-  #endif
80
+  TERN_(SCREENS_CAN_TIME_OUT, last_interaction = millis());
83 81
 }
84 82
 
85
-#if LCD_TIMEOUT_TO_STATUS > 0
83
+#if SCREENS_CAN_TIME_OUT
86 84
   uint32_t BaseScreen::last_interaction;
87 85
 #endif
88 86
 

+ 1
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_screen.h View File

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

+ 8
- 16
Marlin/src/lcd/marlinui.cpp View File

@@ -165,8 +165,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
165 165
   #endif
166 166
 #endif
167 167
 
168
-#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
168
+#if SCREENS_CAN_TIME_OUT
169 169
   bool MarlinUI::defer_return_to_status;
170
+  millis_t MarlinUI::return_to_status_ms = 0;
170 171
 #endif
171 172
 
172 173
 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*/) {
815 816
 
816 817
 LCDViewAction MarlinUI::lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
817 818
 millis_t next_lcd_update_ms;
818
-#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
819
-  millis_t MarlinUI::return_to_status_ms = 0;
820
-#endif
821 819
 
822 820
 inline bool can_encode() {
823 821
   return !BUTTON_PRESSED(ENC_EN); // Update encoder only when ENC_EN is not LOW (pressed)
@@ -828,12 +826,6 @@ void MarlinUI::update() {
828 826
   static uint16_t max_display_update_time = 0;
829 827
   millis_t ms = millis();
830 828
 
831
-  #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
832
-    #define RESET_STATUS_TIMEOUT() (return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS)
833
-  #else
834
-    #define RESET_STATUS_TIMEOUT() NOOP
835
-  #endif
836
-
837 829
   #ifdef LED_BACKLIGHT_TIMEOUT
838 830
     leds.update_timeout(powersupply_on);
839 831
   #endif
@@ -859,7 +851,7 @@ void MarlinUI::update() {
859 851
 
860 852
     #if HAS_TOUCH_BUTTONS
861 853
       if (touch_buttons) {
862
-        RESET_STATUS_TIMEOUT();
854
+        reset_status_timeout(ms);
863 855
         if (touch_buttons & (EN_A | EN_B)) {              // Menu arrows, in priority
864 856
           if (ELAPSED(ms, next_button_update_ms)) {
865 857
             encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * epps * encoderDirection;
@@ -914,7 +906,7 @@ void MarlinUI::update() {
914 906
       TERN_(HAS_SLOW_BUTTONS, slow_buttons = read_slow_buttons()); // Buttons that take too long to read in interrupt context
915 907
 
916 908
       if (TERN0(IS_RRW_KEYPAD, handle_keypad()))
917
-        RESET_STATUS_TIMEOUT();
909
+        reset_status_timeout(ms);
918 910
 
919 911
       uint8_t abs_diff = ABS(encoderDiff);
920 912
 
@@ -980,7 +972,7 @@ void MarlinUI::update() {
980 972
           encoderDiff = 0;
981 973
         }
982 974
 
983
-        RESET_STATUS_TIMEOUT();
975
+        reset_status_timeout(ms);
984 976
 
985 977
         refresh(LCDVIEW_REDRAW_NOW);
986 978
 
@@ -1006,7 +998,7 @@ void MarlinUI::update() {
1006 998
         lcd_status_update_delay = ++filename_scroll_pos >= filename_scroll_max ? 12 : 4; // Long delay at end and start
1007 999
         if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0;
1008 1000
         refresh(LCDVIEW_REDRAW_NOW);
1009
-        RESET_STATUS_TIMEOUT();
1001
+        reset_status_timeout(ms);
1010 1002
       }
1011 1003
     #endif
1012 1004
 
@@ -1075,10 +1067,10 @@ void MarlinUI::update() {
1075 1067
         NOLESS(max_display_update_time, millis() - ms);
1076 1068
     }
1077 1069
 
1078
-    #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
1070
+    #if SCREENS_CAN_TIME_OUT
1079 1071
       // Return to Status Screen after a timeout
1080 1072
       if (on_status_screen() || defer_return_to_status)
1081
-        RESET_STATUS_TIMEOUT();
1073
+        reset_status_timeout(ms);
1082 1074
       else if (ELAPSED(ms, return_to_status_ms))
1083 1075
         return_to_status();
1084 1076
     #endif

+ 19
- 14
Marlin/src/lcd/marlinui.h View File

@@ -449,10 +449,13 @@ public:
449 449
     static PGM_P get_preheat_label(const uint8_t m);
450 450
   #endif
451 451
 
452
+  #if SCREENS_CAN_TIME_OUT
453
+    static inline void reset_status_timeout(const millis_t ms) { return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; }
454
+  #else
455
+    static inline void reset_status_timeout(const millis_t) {}
456
+  #endif
457
+
452 458
   #if HAS_LCD_MENU
453
-    #if LCD_TIMEOUT_TO_STATUS
454
-      static millis_t return_to_status_ms;
455
-    #endif
456 459
 
457 460
     #if HAS_TOUCH_BUTTONS
458 461
       static uint8_t touch_buttons;
@@ -483,7 +486,7 @@ public:
483 486
     static screenFunc_t currentScreen;
484 487
     static bool screen_changed;
485 488
     static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
486
-    static void save_previous_screen();
489
+    static void push_current_screen();
487 490
 
488 491
     // goto_previous_screen and go_back may also be used as menu item callbacks
489 492
     static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
@@ -498,12 +501,12 @@ public:
498 501
       static void lcd_in_status(const bool inStatus);
499 502
     #endif
500 503
 
504
+    FORCE_INLINE static bool screen_is_sticky() {
505
+      return TERN1(SCREENS_CAN_TIME_OUT, defer_return_to_status);
506
+    }
507
+
501 508
     FORCE_INLINE static void defer_status_screen(const bool defer=true) {
502
-      #if LCD_TIMEOUT_TO_STATUS > 0
503
-        defer_return_to_status = defer;
504
-      #else
505
-        UNUSED(defer);
506
-      #endif
509
+      TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
507 510
     }
508 511
 
509 512
     static inline void goto_previous_screen_no_defer() {
@@ -655,16 +658,18 @@ public:
655 658
 
656 659
 private:
657 660
 
661
+  #if SCREENS_CAN_TIME_OUT
662
+    static millis_t return_to_status_ms;
663
+    static bool defer_return_to_status;
664
+  #else
665
+    static constexpr bool defer_return_to_status = false;
666
+  #endif
667
+
658 668
   #if HAS_STATUS_MESSAGE
659 669
     static void finish_status(const bool persist);
660 670
   #endif
661 671
 
662 672
   #if HAS_WIRED_LCD
663
-    #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
664
-      static bool defer_return_to_status;
665
-    #else
666
-      static constexpr bool defer_return_to_status = false;
667
-    #endif
668 673
     static void draw_status_screen();
669 674
     #if HAS_GRAPHICAL_TFT
670 675
       static void tft_idle();

+ 12
- 8
Marlin/src/lcd/menu/menu.cpp View File

@@ -50,9 +50,12 @@
50 50
 int8_t encoderTopLine, encoderLine, screen_items;
51 51
 
52 52
 typedef struct {
53
-  screenFunc_t menu_function;
54
-  uint32_t encoder_position;
55
-  int8_t top_line, items;
53
+  screenFunc_t menu_function;     // The screen's function
54
+  uint32_t encoder_position;      // The position of the encoder
55
+  int8_t top_line, items;         // The amount of scroll, and the number of items
56
+  #if SCREENS_CAN_TIME_OUT
57
+    bool sticky;                  // The screen is sticky
58
+  #endif
56 59
 } menuPosition;
57 60
 menuPosition screen_history[6];
58 61
 uint8_t screen_history_depth = 0;
@@ -75,9 +78,9 @@ bool         MenuEditItemBase::liveEdit;
75 78
 
76 79
 void MarlinUI::return_to_status() { goto_screen(status_screen); }
77 80
 
78
-void MarlinUI::save_previous_screen() {
81
+void MarlinUI::push_current_screen() {
79 82
   if (screen_history_depth < COUNT(screen_history))
80
-    screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
83
+    screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items OPTARG(SCREENS_CAN_TIME_OUT, screen_is_sticky()) };
81 84
 }
82 85
 
83 86
 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
90 93
       is_back ? 0 : sh.top_line,
91 94
       sh.items
92 95
     );
96
+    defer_status_screen(TERN_(SCREENS_CAN_TIME_OUT, sh.sticky));
93 97
   }
94 98
   else
95 99
     return_to_status();
@@ -147,7 +151,7 @@ void MenuEditItemBase::goto_edit_screen(
147 151
 ) {
148 152
   TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
149 153
   ui.screen_changed = true;
150
-  ui.save_previous_screen();
154
+  ui.push_current_screen();
151 155
   ui.refresh();
152 156
   editLabel = el;
153 157
   editValue = ev;
@@ -237,7 +241,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
237 241
 //
238 242
 void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) {
239 243
   static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
240
-  save_previous_screen();
244
+  push_current_screen();
241 245
   goto_screen([]{
242 246
     if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message);
243 247
   });
@@ -371,6 +375,7 @@ void MenuItem_confirm::select_screen(
371 375
   selectFunc_t yesFunc, selectFunc_t noFunc,
372 376
   PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
373 377
 ) {
378
+  ui.defer_status_screen();
374 379
   const bool ui_selection = ui.update_selection(), got_click = ui.use_click();
375 380
   if (got_click || ui.should_draw()) {
376 381
     draw_select_screen(yes, no, ui_selection, pref, string, suff);
@@ -378,7 +383,6 @@ void MenuItem_confirm::select_screen(
378 383
       selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
379 384
       if (callFunc) callFunc(); else ui.goto_previous_screen();
380 385
     }
381
-    ui.defer_status_screen();
382 386
   }
383 387
 }
384 388
 

+ 2
- 2
Marlin/src/lcd/menu/menu_item.h View File

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

+ 1
- 1
Marlin/src/lcd/menu/menu_password.cpp View File

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

+ 1
- 3
Marlin/src/lcd/tft/touch.cpp View File

@@ -93,9 +93,7 @@ void Touch::idle() {
93 93
       }
94 94
     #endif
95 95
 
96
-    #if LCD_TIMEOUT_TO_STATUS
97
-      ui.return_to_status_ms = last_touch_ms + LCD_TIMEOUT_TO_STATUS;
98
-    #endif
96
+    ui.reset_status_timeout(last_touch_ms);
99 97
 
100 98
     if (touch_time) {
101 99
       #if ENABLED(TOUCH_SCREEN_CALIBRATION)

Loading…
Cancel
Save