Browse Source

Improve touch buttons behavior (#16109)

Tanguy Pruvot 4 years ago
parent
commit
ab61c09bff

+ 1
- 1
Marlin/src/inc/Conditionals_LCD.h View File

@@ -290,7 +290,7 @@
290 290
 
291 291
 #ifndef STD_ENCODER_PULSES_PER_STEP
292 292
   #if ENABLED(TOUCH_BUTTONS)
293
-    #define STD_ENCODER_PULSES_PER_STEP 1
293
+    #define STD_ENCODER_PULSES_PER_STEP 2
294 294
   #else
295 295
     #define STD_ENCODER_PULSES_PER_STEP 5
296 296
   #endif

+ 9
- 0
Marlin/src/lcd/menu/menu_main.cpp View File

@@ -106,7 +106,11 @@ void menu_main() {
106 106
     SUBMENU(MSG_TUNE, menu_tune);
107 107
   }
108 108
   else {
109
+
109 110
     #if !HAS_ENCODER_WHEEL && ENABLED(SDSUPPORT)
111
+
112
+      // *** IF THIS SECTION IS CHANGED, REPRODUCE BELOW ***
113
+
110 114
       //
111 115
       // Autostart
112 116
       //
@@ -134,6 +138,7 @@ void menu_main() {
134 138
           ACTION_ITEM(MSG_MEDIA_RELEASED, nullptr);
135 139
         #endif
136 140
       }
141
+
137 142
     #endif // !HAS_ENCODER_WHEEL && SDSUPPORT
138 143
 
139 144
     #if MACHINE_CAN_PAUSE
@@ -197,6 +202,9 @@ void menu_main() {
197 202
   #endif
198 203
 
199 204
   #if HAS_ENCODER_WHEEL && ENABLED(SDSUPPORT)
205
+
206
+    // *** IF THIS SECTION IS CHANGED, REPRODUCE ABOVE ***
207
+
200 208
     //
201 209
     // Autostart
202 210
     //
@@ -224,6 +232,7 @@ void menu_main() {
224 232
         ACTION_ITEM(MSG_MEDIA_RELEASED, nullptr);
225 233
       #endif
226 234
     }
235
+
227 236
   #endif // HAS_ENCODER_WHEEL && SDSUPPORT
228 237
 
229 238
   #if HAS_SERVICE_INTERVALS

+ 39
- 42
Marlin/src/lcd/ultralcd.cpp View File

@@ -200,6 +200,7 @@ millis_t MarlinUI::next_button_update_ms; // = 0
200 200
   #endif
201 201
 
202 202
   #if ENABLED(TOUCH_BUTTONS)
203
+    uint8_t MarlinUI::touch_buttons;
203 204
     uint8_t MarlinUI::repeat_delay;
204 205
   #endif
205 206
 
@@ -778,58 +779,46 @@ void MarlinUI::update() {
778 779
 
779 780
     #if ENABLED(TOUCH_BUTTONS)
780 781
 
781
-      #define TOUCH_MENU_MASK 0x80
782
-
783
-      static bool arrow_pressed; // = false
784
-
785
-      // Handle touch events which are slow to read
786
-      if (ELAPSED(ms, next_button_update_ms)) {
787
-        uint8_t touch_buttons = touch.read_buttons();
788
-        if (touch_buttons) {
789
-          RESET_STATUS_TIMEOUT();
790
-          if (touch_buttons & TOUCH_MENU_MASK) {        // Processing Menu Area touch?
791
-            if (!wait_for_unclick) {                    // If not waiting for a debounce release:
792
-              wait_for_unclick = true;                  //  - Set debounce flag to ignore continous clicks
793
-              wait_for_user = false;                    //  - Any click clears wait for user
794
-              // TODO for next PR.
795
-              //uint8_t tpos = touch_buttons & ~(TOUCH_MENU_MASK);  // Safe 7bit touched screen coordinate
796
-              next_button_update_ms = ms + 500;         // Defer next check for 1/2 second
797
-              #if HAS_LCD_MENU
798
-                refresh();
799
-              #endif
800
-            }
801
-            touch_buttons = 0;                          // Swallow the touch
802
-          }
803
-          buttons |= (touch_buttons & (EN_C | EN_D));   // Pass on Click and Back buttons
804
-          if (touch_buttons & (EN_A | EN_B)) {          // A and/or B button?
782
+      if (touch_buttons) {
783
+        RESET_STATUS_TIMEOUT();
784
+        if (buttons & (EN_A | EN_B)) {                    // Menu arrows, in priority
785
+          if (ELAPSED(ms, next_button_update_ms)) {
805 786
             encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection;
806
-            if (touch_buttons & EN_A) encoderDiff *= -1;
807
-            next_button_update_ms = ms + repeat_delay;  // Assume the repeat delay
808
-            if (!wait_for_unclick && !arrow_pressed) {  // On click prepare for repeat
809
-              next_button_update_ms += 250;             // Longer delay on first press
810
-              arrow_pressed = true;                     // Mark arrow as pressed
787
+            if (buttons & EN_A) encoderDiff *= -1;
788
+            next_button_update_ms = ms + repeat_delay;    // Assume the repeat delay
789
+            if (!wait_for_unclick) {
790
+              next_button_update_ms += 250;               // Longer delay on first press
791
+              wait_for_unclick = true;                    // Avoid Back/Select click while repeating
811 792
               #if HAS_BUZZER
812 793
                 buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
813 794
               #endif
814 795
             }
815 796
           }
816 797
         }
817
-        if (!(touch_buttons & (EN_A | EN_B))) arrow_pressed = false;
798
+        else if (!wait_for_unclick && (buttons & EN_C)) { // OK button, if not waiting for a debounce release:
799
+          wait_for_unclick = true;                        //  - Set debounce flag to ignore continous clicks
800
+          lcd_clicked = !wait_for_user && !no_reentry;    //  - Keep the click if not waiting for a user-click
801
+          wait_for_user = false;                          //  - Any click clears wait for user
802
+          quick_feedback();                               //  - Always make a click sound
803
+        }
818 804
       }
805
+      else // keep wait_for_unclick value
819 806
 
820 807
     #endif // TOUCH_BUTTONS
821 808
 
822
-    // Integrated LCD click handling via button_pressed
823
-    if (!external_control && button_pressed()) {
824
-      if (!wait_for_unclick) {                        // If not waiting for a debounce release:
825
-        wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
826
-        lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
827
-        wait_for_user = false;                        //  - Any click clears wait for user
828
-        quick_feedback();                             //  - Always make a click sound
809
+      {
810
+        // Integrated LCD click handling via button_pressed
811
+        if (!external_control && button_pressed()) {
812
+          if (!wait_for_unclick) {                        // If not waiting for a debounce release:
813
+            wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
814
+            lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
815
+            wait_for_user = false;                        //  - Any click clears wait for user
816
+            quick_feedback();                             //  - Always make a click sound
817
+          }
818
+        }
819
+        else
820
+          wait_for_unclick = false;
829 821
       }
830
-    }
831
-    else
832
-      wait_for_unclick = false;
833 822
 
834 823
     if (LCD_BACK_CLICKED()) {
835 824
       quick_feedback();
@@ -894,8 +883,13 @@ void MarlinUI::update() {
894 883
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
895 884
 
896 885
     #if ENABLED(TOUCH_BUTTONS)
897
-      if (on_status_screen())
898
-        next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
886
+
887
+      if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
888
+
889
+      #if HAS_ENCODER_ACTION
890
+        touch_buttons = touch.read_buttons();
891
+      #endif
892
+
899 893
     #endif
900 894
 
901 895
     #if ENABLED(LCD_HAS_STATUS_INDICATORS)
@@ -1249,6 +1243,9 @@ void MarlinUI::update() {
1249 1243
           #if HAS_SLOW_BUTTONS
1250 1244
             | slow_buttons
1251 1245
           #endif
1246
+          #if ENABLED(TOUCH_BUTTONS) && HAS_ENCODER_ACTION
1247
+            | touch_buttons
1248
+          #endif
1252 1249
         );
1253 1250
 
1254 1251
       #elif HAS_ADC_BUTTONS

+ 4
- 3
Marlin/src/lcd/ultralcd.h View File

@@ -27,10 +27,10 @@
27 27
   #include "../libs/buzzer.h"
28 28
 #endif
29 29
 
30
-#define HAS_DIGITAL_BUTTONS (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL) || BUTTON_EXISTS(EN1, EN2) || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT))
31
-#define HAS_SHIFT_ENCODER   (!HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL))))
32
-#define HAS_ENCODER_WHEEL  ((!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || BUTTON_EXISTS(EN1, EN2))
33 30
 #define HAS_ENCODER_ACTION (HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY))
31
+#define HAS_ENCODER_WHEEL  ((!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || BUTTON_EXISTS(EN1, EN2))
32
+#define HAS_DIGITAL_BUTTONS (HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT))
33
+#define HAS_SHIFT_ENCODER   (!HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL))))
34 34
 
35 35
 // I2C buttons must be read in the main thread
36 36
 #define HAS_SLOW_BUTTONS EITHER(LCD_I2C_VIKI, LCD_I2C_PANELOLU2)
@@ -425,6 +425,7 @@ public:
425 425
   #if HAS_LCD_MENU
426 426
 
427 427
     #if ENABLED(TOUCH_BUTTONS)
428
+      static uint8_t touch_buttons;
428 429
       static uint8_t repeat_delay;
429 430
     #endif
430 431
 

+ 1
- 1
config/examples/Alfawise/U20-bltouch/Configuration.h View File

@@ -2139,7 +2139,7 @@
2139 2139
 #if ENABLED(TOUCH_BUTTONS)
2140 2140
   #define TOUCH_CALIBRATION // Include user calibration widget in menus (Alfawise)
2141 2141
 
2142
-  #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2142
+  #define BUTTON_DELAY_EDIT  75 // (ms) Button repeat delay for edit screens
2143 2143
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2144 2144
 
2145 2145
   #if ENABLED(TS_V11)

+ 1
- 1
config/examples/Alfawise/U20/Configuration.h View File

@@ -2138,7 +2138,7 @@
2138 2138
 #if ENABLED(TOUCH_BUTTONS)
2139 2139
   #define TOUCH_CALIBRATION // Include user calibration widget in menus (Alfawise)
2140 2140
 
2141
-  #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2141
+  #define BUTTON_DELAY_EDIT  75 // (ms) Button repeat delay for edit screens
2142 2142
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2143 2143
 
2144 2144
   #if ENABLED(TS_V11)

+ 2
- 2
config/examples/Mks/Robin/Configuration.h View File

@@ -2059,8 +2059,8 @@
2059 2059
 //
2060 2060
 #define TOUCH_BUTTONS
2061 2061
 #if ENABLED(TOUCH_BUTTONS)
2062
-  #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2063
-  #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
2062
+  #define BUTTON_DELAY_EDIT  75 // (ms) Button repeat delay for edit screens
2063
+  #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2064 2064
 
2065 2065
   /* MKS Robin TFT v2.0 */
2066 2066
   #define XPT2046_X_CALIBRATION    12013

Loading…
Cancel
Save