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
   #endif
3397
   #endif
3398
 #endif
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
 #endif
3408
 #endif
3404
 
3409
 
3405
 // Add commands that need sub-codes to this list
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
     return false;
45
     return false;
46
   }
46
   }
47
 
47
 
48
-  #if LCD_TIMEOUT_TO_STATUS > 0
48
+  #if SCREENS_CAN_TIME_OUT
49
     if (EventLoop::get_pressed_tag() != 0) {
49
     if (EventLoop::get_pressed_tag() != 0) {
50
       reset_menu_timeout();
50
       reset_menu_timeout();
51
     }
51
     }
65
 }
65
 }
66
 
66
 
67
 void BaseScreen::onIdle() {
67
 void BaseScreen::onIdle() {
68
-  #if LCD_TIMEOUT_TO_STATUS > 0
68
+  #if SCREENS_CAN_TIME_OUT
69
     if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
69
     if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
70
       reset_menu_timeout();
70
       reset_menu_timeout();
71
       #if ENABLED(TOUCH_UI_DEBUG)
71
       #if ENABLED(TOUCH_UI_DEBUG)
77
 }
77
 }
78
 
78
 
79
 void BaseScreen::reset_menu_timeout() {
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
   uint32_t BaseScreen::last_interaction;
84
   uint32_t BaseScreen::last_interaction;
87
 #endif
85
 #endif
88
 
86
 

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

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

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

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

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

449
     static PGM_P get_preheat_label(const uint8_t m);
449
     static PGM_P get_preheat_label(const uint8_t m);
450
   #endif
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
   #if HAS_LCD_MENU
458
   #if HAS_LCD_MENU
453
-    #if LCD_TIMEOUT_TO_STATUS
454
-      static millis_t return_to_status_ms;
455
-    #endif
456
 
459
 
457
     #if HAS_TOUCH_BUTTONS
460
     #if HAS_TOUCH_BUTTONS
458
       static uint8_t touch_buttons;
461
       static uint8_t touch_buttons;
483
     static screenFunc_t currentScreen;
486
     static screenFunc_t currentScreen;
484
     static bool screen_changed;
487
     static bool screen_changed;
485
     static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
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
     // goto_previous_screen and go_back may also be used as menu item callbacks
491
     // goto_previous_screen and go_back may also be used as menu item callbacks
489
     static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
492
     static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
498
       static void lcd_in_status(const bool inStatus);
501
       static void lcd_in_status(const bool inStatus);
499
     #endif
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
     FORCE_INLINE static void defer_status_screen(const bool defer=true) {
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
     static inline void goto_previous_screen_no_defer() {
512
     static inline void goto_previous_screen_no_defer() {
655
 
658
 
656
 private:
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
   #if HAS_STATUS_MESSAGE
668
   #if HAS_STATUS_MESSAGE
659
     static void finish_status(const bool persist);
669
     static void finish_status(const bool persist);
660
   #endif
670
   #endif
661
 
671
 
662
   #if HAS_WIRED_LCD
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
     static void draw_status_screen();
673
     static void draw_status_screen();
669
     #if HAS_GRAPHICAL_TFT
674
     #if HAS_GRAPHICAL_TFT
670
       static void tft_idle();
675
       static void tft_idle();

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

50
 int8_t encoderTopLine, encoderLine, screen_items;
50
 int8_t encoderTopLine, encoderLine, screen_items;
51
 
51
 
52
 typedef struct {
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
 } menuPosition;
59
 } menuPosition;
57
 menuPosition screen_history[6];
60
 menuPosition screen_history[6];
58
 uint8_t screen_history_depth = 0;
61
 uint8_t screen_history_depth = 0;
75
 
78
 
76
 void MarlinUI::return_to_status() { goto_screen(status_screen); }
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
   if (screen_history_depth < COUNT(screen_history))
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
 void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
86
 void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
90
       is_back ? 0 : sh.top_line,
93
       is_back ? 0 : sh.top_line,
91
       sh.items
94
       sh.items
92
     );
95
     );
96
+    defer_status_screen(TERN_(SCREENS_CAN_TIME_OUT, sh.sticky));
93
   }
97
   }
94
   else
98
   else
95
     return_to_status();
99
     return_to_status();
147
 ) {
151
 ) {
148
   TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
152
   TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
149
   ui.screen_changed = true;
153
   ui.screen_changed = true;
150
-  ui.save_previous_screen();
154
+  ui.push_current_screen();
151
   ui.refresh();
155
   ui.refresh();
152
   editLabel = el;
156
   editLabel = el;
153
   editValue = ev;
157
   editValue = ev;
237
 //
241
 //
238
 void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) {
242
 void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) {
239
   static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
243
   static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
240
-  save_previous_screen();
244
+  push_current_screen();
241
   goto_screen([]{
245
   goto_screen([]{
242
     if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message);
246
     if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message);
243
   });
247
   });
371
   selectFunc_t yesFunc, selectFunc_t noFunc,
375
   selectFunc_t yesFunc, selectFunc_t noFunc,
372
   PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
376
   PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
373
 ) {
377
 ) {
378
+  ui.defer_status_screen();
374
   const bool ui_selection = ui.update_selection(), got_click = ui.use_click();
379
   const bool ui_selection = ui.update_selection(), got_click = ui.use_click();
375
   if (got_click || ui.should_draw()) {
380
   if (got_click || ui.should_draw()) {
376
     draw_select_screen(yes, no, ui_selection, pref, string, suff);
381
     draw_select_screen(yes, no, ui_selection, pref, string, suff);
378
       selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
383
       selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
379
       if (callFunc) callFunc(); else ui.goto_previous_screen();
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
     FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
39
     FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
40
       _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
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
 // Any menu item that invokes an immediate action
45
 // Any menu item that invokes an immediate action
406
 
406
 
407
 #define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do {             \
407
 #define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do {             \
408
   if (encoderLine == _thisItemNr && ui.use_click()) {        \
408
   if (encoderLine == _thisItemNr && ui.use_click()) {        \
409
-    ui.save_previous_screen();                               \
409
+    ui.push_current_screen();                                \
410
     ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
410
     ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
411
     return;                                                  \
411
     return;                                                  \
412
   }                                                          \
412
   }                                                          \

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

177
   START_MENU();
177
   START_MENU();
178
   BACK_ITEM(MSG_ADVANCED_SETTINGS);
178
   BACK_ITEM(MSG_ADVANCED_SETTINGS);
179
   SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password);
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
   #if ENABLED(EEPROM_SETTINGS)
181
   #if ENABLED(EEPROM_SETTINGS)
182
     ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
182
     ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
183
   #endif
183
   #endif

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

93
       }
93
       }
94
     #endif
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
     if (touch_time) {
98
     if (touch_time) {
101
       #if ENABLED(TOUCH_SCREEN_CALIBRATION)
99
       #if ENABLED(TOUCH_SCREEN_CALIBRATION)

Loading…
Cancel
Save