Sfoglia il codice sorgente

Improve touch buttons behavior (#16109)

Tanguy Pruvot 5 anni fa
parent
commit
ab61c09bff

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

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

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

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

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

200
   #endif
200
   #endif
201
 
201
 
202
   #if ENABLED(TOUCH_BUTTONS)
202
   #if ENABLED(TOUCH_BUTTONS)
203
+    uint8_t MarlinUI::touch_buttons;
203
     uint8_t MarlinUI::repeat_delay;
204
     uint8_t MarlinUI::repeat_delay;
204
   #endif
205
   #endif
205
 
206
 
778
 
779
 
779
     #if ENABLED(TOUCH_BUTTONS)
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
             encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection;
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
               #if HAS_BUZZER
792
               #if HAS_BUZZER
812
                 buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
793
                 buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
813
               #endif
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
     #endif // TOUCH_BUTTONS
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
     if (LCD_BACK_CLICKED()) {
823
     if (LCD_BACK_CLICKED()) {
835
       quick_feedback();
824
       quick_feedback();
894
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
883
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
895
 
884
 
896
     #if ENABLED(TOUCH_BUTTONS)
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
     #endif
893
     #endif
900
 
894
 
901
     #if ENABLED(LCD_HAS_STATUS_INDICATORS)
895
     #if ENABLED(LCD_HAS_STATUS_INDICATORS)
1249
           #if HAS_SLOW_BUTTONS
1243
           #if HAS_SLOW_BUTTONS
1250
             | slow_buttons
1244
             | slow_buttons
1251
           #endif
1245
           #endif
1246
+          #if ENABLED(TOUCH_BUTTONS) && HAS_ENCODER_ACTION
1247
+            | touch_buttons
1248
+          #endif
1252
         );
1249
         );
1253
 
1250
 
1254
       #elif HAS_ADC_BUTTONS
1251
       #elif HAS_ADC_BUTTONS

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

27
   #include "../libs/buzzer.h"
27
   #include "../libs/buzzer.h"
28
 #endif
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
 #define HAS_ENCODER_ACTION (HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY))
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
 // I2C buttons must be read in the main thread
35
 // I2C buttons must be read in the main thread
36
 #define HAS_SLOW_BUTTONS EITHER(LCD_I2C_VIKI, LCD_I2C_PANELOLU2)
36
 #define HAS_SLOW_BUTTONS EITHER(LCD_I2C_VIKI, LCD_I2C_PANELOLU2)
425
   #if HAS_LCD_MENU
425
   #if HAS_LCD_MENU
426
 
426
 
427
     #if ENABLED(TOUCH_BUTTONS)
427
     #if ENABLED(TOUCH_BUTTONS)
428
+      static uint8_t touch_buttons;
428
       static uint8_t repeat_delay;
429
       static uint8_t repeat_delay;
429
     #endif
430
     #endif
430
 
431
 

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

2139
 #if ENABLED(TOUCH_BUTTONS)
2139
 #if ENABLED(TOUCH_BUTTONS)
2140
   #define TOUCH_CALIBRATION // Include user calibration widget in menus (Alfawise)
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
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2143
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2144
 
2144
 
2145
   #if ENABLED(TS_V11)
2145
   #if ENABLED(TS_V11)

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

2138
 #if ENABLED(TOUCH_BUTTONS)
2138
 #if ENABLED(TOUCH_BUTTONS)
2139
   #define TOUCH_CALIBRATION // Include user calibration widget in menus (Alfawise)
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
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2142
   #define BUTTON_DELAY_MENU 100 // (ms) Button repeat delay for menus
2143
 
2143
 
2144
   #if ENABLED(TS_V11)
2144
   #if ENABLED(TS_V11)

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

2059
 //
2059
 //
2060
 #define TOUCH_BUTTONS
2060
 #define TOUCH_BUTTONS
2061
 #if ENABLED(TOUCH_BUTTONS)
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
   /* MKS Robin TFT v2.0 */
2065
   /* MKS Robin TFT v2.0 */
2066
   #define XPT2046_X_CALIBRATION    12013
2066
   #define XPT2046_X_CALIBRATION    12013

Loading…
Annulla
Salva