浏览代码

Allow TOUCH_BUTTONS to be swapped (#15100)

Robby Candra 5 年前
父节点
当前提交
6b05d5d65d

+ 5
- 1
Marlin/src/inc/Conditionals_LCD.h 查看文件

@@ -288,7 +288,11 @@
288 288
 #endif
289 289
 
290 290
 #ifndef STD_ENCODER_PULSES_PER_STEP
291
-  #define STD_ENCODER_PULSES_PER_STEP 5
291
+  #if ENABLED(TOUCH_BUTTONS)
292
+    #define STD_ENCODER_PULSES_PER_STEP 1
293
+  #else
294
+    #define STD_ENCODER_PULSES_PER_STEP 5
295
+  #endif
292 296
 #endif
293 297
 #ifndef STD_ENCODER_STEPS_PER_MENU_ITEM
294 298
   #define STD_ENCODER_STEPS_PER_MENU_ITEM 1

+ 3
- 3
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp 查看文件

@@ -371,8 +371,8 @@ bool MarlinUI::detected() {
371 371
 #if HAS_SLOW_BUTTONS
372 372
   uint8_t MarlinUI::read_slow_buttons() {
373 373
     #if ENABLED(LCD_I2C_TYPE_MCP23017)
374
-      // Reading these buttons this is likely to be too slow to call inside interrupt context
375
-      // so they are called during normal lcd_update
374
+      // Reading these buttons is too slow for interrupt context
375
+      // so they are read during LCD update in the main loop.
376 376
       uint8_t slow_bits = lcd.readButtons()
377 377
         #if !BUTTON_EXISTS(ENC)
378 378
           << B_I2C_BTN_OFFSET
@@ -381,7 +381,7 @@ bool MarlinUI::detected() {
381 381
       #if ENABLED(LCD_I2C_VIKI)
382 382
         if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
383 383
           slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
384
-      #endif // LCD_I2C_VIKI
384
+      #endif
385 385
       return slow_bits;
386 386
     #endif // LCD_I2C_TYPE_MCP23017
387 387
   }

+ 97
- 49
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp 查看文件

@@ -267,51 +267,102 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341
267 267
     B01111111,B11111111,B11111111,B11111110,
268 268
   };
269 269
 
270
-  static const uint8_t buttonA[] = {
271
-    B01111111,B11111111,B11111111,B11111110,
272
-    B10000000,B00000000,B00000000,B00000001,
273
-    B10000000,B00000000,B00000000,B00000001,
274
-    B10000000,B00000000,B00000000,B00000001,
275
-    B10000000,B00000000,B00000000,B00000001,
276
-    B10000000,B01000000,B00000000,B00000001,
277
-    B10000000,B11100000,B00000000,B00000001,
278
-    B10000001,B11110000,B00000000,B00000001,
279
-    B10000011,B11111000,B00000000,B00000001,
280
-    B10000111,B11111100,B00111111,B11100001,
281
-    B10000000,B11100000,B00111111,B11100001,
282
-    B10000000,B11100000,B00000000,B00000001,
283
-    B10000000,B11100000,B00000000,B00000001,
284
-    B10000000,B11100000,B00000000,B00000001,
285
-    B10000000,B11100000,B00000000,B00000001,
286
-    B10000000,B00000000,B00000000,B00000001,
287
-    B10000000,B00000000,B00000000,B00000001,
288
-    B10000000,B00000000,B00000000,B00000001,
289
-    B10000000,B00000000,B00000000,B00000001,
290
-    B01111111,B11111111,B11111111,B11111110,
291
-  };
270
+  #if ENABLED(REVERSE_MENU_DIRECTION)
271
+
272
+    static const uint8_t buttonA[] = {
273
+      B01111111,B11111111,B11111111,B11111110,
274
+      B10000000,B00000000,B00000000,B00000001,
275
+      B10000000,B00000000,B00000000,B00000001,
276
+      B10000000,B00000000,B00000000,B00000001,
277
+      B10000000,B00000000,B00000000,B00000001,
278
+      B10000000,B11100000,B00000000,B00000001,
279
+      B10000000,B11100000,B00000000,B00000001,
280
+      B10000000,B11100000,B00000000,B00000001,
281
+      B10000000,B11100000,B00000000,B00000001,
282
+      B10000000,B11100000,B00111111,B11100001,
283
+      B10000111,B11111100,B00111111,B11100001,
284
+      B10000011,B11111000,B00000000,B00000001,
285
+      B10000001,B11110000,B00000000,B00000001,
286
+      B10000000,B11100000,B00000000,B00000001,
287
+      B10000000,B01000000,B00000000,B00000001,
288
+      B10000000,B00000000,B00000000,B00000001,
289
+      B10000000,B00000000,B00000000,B00000001,
290
+      B10000000,B00000000,B00000000,B00000001,
291
+      B10000000,B00000000,B00000000,B00000001,
292
+      B01111111,B11111111,B11111111,B11111110,
293
+    };
294
+    static const uint8_t buttonB[] = {
295
+      B01111111,B11111111,B11111111,B11111110,
296
+      B10000000,B00000000,B00000000,B00000001,
297
+      B10000000,B00000000,B00000000,B00000001,
298
+      B10000000,B00000000,B00000000,B00000001,
299
+      B10000000,B00000000,B00000000,B00000001,
300
+      B10000000,B01100000,B00000010,B00000001,
301
+      B10000000,B01100000,B00000111,B00000001,
302
+      B10000000,B01100000,B00001111,B10000001,
303
+      B10000000,B01100000,B00011111,B11000001,
304
+      B10000111,B11111110,B00111111,B11100001,
305
+      B10000111,B11111110,B00000111,B00000001,
306
+      B10000000,B01100000,B00000111,B00000001,
307
+      B10000000,B01100000,B00000111,B00000001,
308
+      B10000000,B01100000,B00000111,B00000001,
309
+      B10000000,B01100000,B00000111,B00000001,
310
+      B10000000,B00000000,B00000000,B00000001,
311
+      B10000000,B00000000,B00000000,B00000001,
312
+      B10000000,B00000000,B00000000,B00000001,
313
+      B10000000,B00000000,B00000000,B00000001,
314
+      B01111111,B11111111,B11111111,B11111110,
315
+    };
292 316
 
293
-  static const uint8_t buttonB[] = {
294
-    B01111111,B11111111,B11111111,B11111110,
295
-    B10000000,B00000000,B00000000,B00000001,
296
-    B10000000,B00000000,B00000000,B00000001,
297
-    B10000000,B00000000,B00000000,B00000001,
298
-    B10000000,B00000000,B00000000,B00000001,
299
-    B10000000,B01100000,B00000111,B00000001,
300
-    B10000000,B01100000,B00000111,B00000001,
301
-    B10000000,B01100000,B00000111,B00000001,
302
-    B10000000,B01100000,B00000111,B00000001,
303
-    B10000111,B11111110,B00000111,B00000001,
304
-    B10000111,B11111110,B00111111,B11100001,
305
-    B10000000,B01100000,B00011111,B11000001,
306
-    B10000000,B01100000,B00001111,B10000001,
307
-    B10000000,B01100000,B00000111,B00000001,
308
-    B10000000,B01100000,B00000010,B00000001,
309
-    B10000000,B00000000,B00000000,B00000001,
310
-    B10000000,B00000000,B00000000,B00000001,
311
-    B10000000,B00000000,B00000000,B00000001,
312
-    B10000000,B00000000,B00000000,B00000001,
313
-    B01111111,B11111111,B11111111,B11111110,
314
-  };
317
+  #else
318
+
319
+    static const uint8_t buttonA[] = {
320
+      B01111111,B11111111,B11111111,B11111110,
321
+      B10000000,B00000000,B00000000,B00000001,
322
+      B10000000,B00000000,B00000000,B00000001,
323
+      B10000000,B00000000,B00000000,B00000001,
324
+      B10000000,B00000000,B00000000,B00000001,
325
+      B10000000,B01000000,B00000000,B00000001,
326
+      B10000000,B11100000,B00000000,B00000001,
327
+      B10000001,B11110000,B00000000,B00000001,
328
+      B10000011,B11111000,B00000000,B00000001,
329
+      B10000111,B11111100,B00111111,B11100001,
330
+      B10000000,B11100000,B00111111,B11100001,
331
+      B10000000,B11100000,B00000000,B00000001,
332
+      B10000000,B11100000,B00000000,B00000001,
333
+      B10000000,B11100000,B00000000,B00000001,
334
+      B10000000,B11100000,B00000000,B00000001,
335
+      B10000000,B00000000,B00000000,B00000001,
336
+      B10000000,B00000000,B00000000,B00000001,
337
+      B10000000,B00000000,B00000000,B00000001,
338
+      B10000000,B00000000,B00000000,B00000001,
339
+      B01111111,B11111111,B11111111,B11111110,
340
+    };
341
+
342
+    static const uint8_t buttonB[] = {
343
+      B01111111,B11111111,B11111111,B11111110,
344
+      B10000000,B00000000,B00000000,B00000001,
345
+      B10000000,B00000000,B00000000,B00000001,
346
+      B10000000,B00000000,B00000000,B00000001,
347
+      B10000000,B00000000,B00000000,B00000001,
348
+      B10000000,B01100000,B00000111,B00000001,
349
+      B10000000,B01100000,B00000111,B00000001,
350
+      B10000000,B01100000,B00000111,B00000001,
351
+      B10000000,B01100000,B00000111,B00000001,
352
+      B10000111,B11111110,B00000111,B00000001,
353
+      B10000111,B11111110,B00111111,B11100001,
354
+      B10000000,B01100000,B00011111,B11000001,
355
+      B10000000,B01100000,B00001111,B10000001,
356
+      B10000000,B01100000,B00000111,B00000001,
357
+      B10000000,B01100000,B00000010,B00000001,
358
+      B10000000,B00000000,B00000000,B00000001,
359
+      B10000000,B00000000,B00000000,B00000001,
360
+      B10000000,B00000000,B00000000,B00000001,
361
+      B10000000,B00000000,B00000000,B00000001,
362
+      B01111111,B11111111,B11111111,B11111110,
363
+    };
364
+
365
+  #endif
315 366
 
316 367
   static const uint8_t buttonC[] = {
317 368
     B01111111,B11111111,B11111111,B11111110,
@@ -369,11 +420,8 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341
369 420
 
370 421
 // Used to fill RGB565 (16bits) background
371 422
 inline void memset2(const void *ptr, uint16_t fill, size_t cnt) {
372
-  uint16_t* wptr = (uint16_t*) ptr;
373
-  for (size_t i = 0; i < cnt; i += 2) {
374
-     *wptr = fill;
375
-     wptr++;
376
-  }
423
+  uint16_t* wptr = (uint16_t*)ptr;
424
+  for (size_t i = 0; i < cnt; i += 2) { *wptr = fill; wptr++; }
377 425
 }
378 426
 
379 427
 static bool preinit = true;

+ 64
- 72
Marlin/src/lcd/ultralcd.cpp 查看文件

@@ -116,8 +116,6 @@
116 116
   #endif
117 117
   #if ENABLED(TOUCH_BUTTONS)
118 118
     #include "../feature/touch/xpt2046.h"
119
-    volatile uint8_t MarlinUI::touch_buttons;
120
-    uint8_t MarlinUI::read_touch_buttons() { return touch.read_buttons(); }
121 119
   #endif
122 120
 #endif
123 121
 
@@ -135,7 +133,7 @@ uint8_t MarlinUI::lcd_status_update_delay = 1; // First update one loop delayed
135 133
   millis_t MarlinUI::next_filament_display; // = 0
136 134
 #endif
137 135
 
138
-millis_t next_button_update_ms;
136
+millis_t MarlinUI::next_button_update_ms; // = 0
139 137
 
140 138
 #if HAS_GRAPHICAL_LCD
141 139
   bool MarlinUI::drawing_screen, MarlinUI::first_page; // = false
@@ -345,9 +343,6 @@ void MarlinUI::init() {
345 343
     #if HAS_SLOW_BUTTONS
346 344
       slow_buttons = 0;
347 345
     #endif
348
-    #if ENABLED(TOUCH_BUTTONS)
349
-      touch_buttons = 0;
350
-    #endif
351 346
   #endif
352 347
 
353 348
   update_buttons();
@@ -746,16 +741,19 @@ void MarlinUI::update() {
746 741
   static millis_t next_lcd_update_ms;
747 742
   millis_t ms = millis();
748 743
 
744
+  #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
745
+    static millis_t return_to_status_ms = 0;
746
+    #define RESET_STATUS_TIMEOUT() (return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS)
747
+  #else
748
+    #define RESET_STATUS_TIMEOUT() NOOP
749
+  #endif
750
+
749 751
   #ifdef LED_BACKLIGHT_TIMEOUT
750 752
     leds.update_timeout(powersupply_on);
751 753
   #endif
752 754
 
753 755
   #if HAS_LCD_MENU
754 756
 
755
-    #if LCD_TIMEOUT_TO_STATUS
756
-      static millis_t return_to_status_ms = 0;
757
-    #endif
758
-
759 757
     // Handle any queued Move Axis motion
760 758
     manage_manual_move();
761 759
 
@@ -764,54 +762,67 @@ void MarlinUI::update() {
764 762
     update_buttons();
765 763
 
766 764
     // If the action button is pressed...
767
-    static bool wait_for_unclick; // = 0
768
-    auto generate_click = [&]() {
769
-      if (!wait_for_unclick) {                        // If not waiting for a debounce release:
770
-        wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
771
-        lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
772
-        wait_for_user = false;                        //  - Any click clears wait for user
773
-        quick_feedback();                             //  - Always make a click sound
774
-      }
775
-    };
765
+    static bool wait_for_unclick; // = false
776 766
 
777 767
     #if ENABLED(TOUCH_BUTTONS)
778
-      if (touch_buttons) {
779
-        if (buttons & EN_C)
780
-          generate_click();
781
-        else if (buttons & (EN_A | EN_B)) {             // Ignore the encoder if clicked, to prevent "slippage"
782
-          const millis_t ms = millis();
783
-          if (ELAPSED(ms, next_button_update_ms)) {
784
-            next_button_update_ms = ms + 50;
785
-            encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP);
786
-            if (buttons & EN_A) encoderDiff *= -1;
787
-            if (!wait_for_unclick) {
788
-              next_button_update_ms += 250;
768
+
769
+      #define TOUCH_MENU_MASK 0x80
770
+
771
+      static bool arrow_pressed; // = false
772
+
773
+      // Handle touch events which are slow to read
774
+      if (ELAPSED(ms, next_button_update_ms)) {
775
+        uint8_t touch_buttons = touch.read_buttons();
776
+        if (touch_buttons) {
777
+          RESET_STATUS_TIMEOUT();
778
+          if (touch_buttons & TOUCH_MENU_MASK) {        // Processing Menu Area touch?
779
+            if (!wait_for_unclick) {                    // If not waiting for a debounce release:
780
+              wait_for_unclick = true;                  //  - Set debounce flag to ignore continous clicks
781
+              wait_for_user = false;                    //  - Any click clears wait for user
782
+              // TODO for next PR.
783
+              //uint8_t tpos = touch_buttons & ~(TOUCH_MENU_MASK);  // Safe 7bit touched screen coordinate
784
+              next_button_update_ms = ms + 500;         // Defer next check for 1/2 second
785
+              #if HAS_LCD_MENU
786
+                refresh();
787
+              #endif
788
+            }
789
+            touch_buttons = 0;                          // Swallow the touch
790
+          }
791
+          buttons |= (touch_buttons & (EN_C | EN_D));   // Pass on Click and Back buttons
792
+          if (touch_buttons & (EN_A | EN_B)) {          // A and/or B button?
793
+            encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection;
794
+            if (touch_buttons & EN_A) encoderDiff *= -1;
795
+            next_button_update_ms = ms + 50;            // Assume the repeat delay
796
+            if (!wait_for_unclick && !arrow_pressed) {  // On click prepare for repeat
797
+              next_button_update_ms += 250;             // Longer delay on first press
798
+              arrow_pressed = true;                     // Mark arrow as pressed
789 799
               #if HAS_BUZZER
790 800
                 buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
791 801
               #endif
792
-              wait_for_unclick = true;                  //  - Set debounce flag to ignore continous clicks
793 802
             }
794 803
           }
795 804
         }
805
+        if (!(touch_buttons & (EN_A | EN_B))) arrow_pressed = false;
796 806
       }
797
-      else
807
+
798 808
     #endif // TOUCH_BUTTONS
799
-      {
800
-        //
801
-        // Integrated LCD click handling via button_pressed()
802
-        //
803
-        if (!external_control && button_pressed())
804
-          generate_click();
805
-        else
806
-          wait_for_unclick = false;
807
-      }
808 809
 
809
-    #if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS))
810
-      if (LCD_BACK_CLICKED()) {
811
-        quick_feedback();
812
-        goto_previous_screen();
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
813 817
       }
814
-    #endif
818
+    }
819
+    else
820
+      wait_for_unclick = false;
821
+
822
+    if (LCD_BACK_CLICKED()) {
823
+      quick_feedback();
824
+      goto_previous_screen();
825
+    }
815 826
 
816 827
   #endif // HAS_LCD_MENU
817 828
 
@@ -885,23 +896,8 @@ void MarlinUI::update() {
885 896
         slow_buttons = read_slow_buttons(); // Buttons that take too long to read in interrupt context
886 897
       #endif
887 898
 
888
-      #if ENABLED(TOUCH_BUTTONS)
889
-        touch_buttons = read_touch_buttons();
890
-        if (touch_buttons) {
891
-          #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
892
-            return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
893
-          #endif
894
-        }
895
-      #endif
896
-
897 899
       #if ENABLED(REPRAPWORLD_KEYPAD)
898
-
899
-        if (handle_keypad()) {
900
-          #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
901
-            return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
902
-          #endif
903
-        }
904
-
900
+        if (handle_keypad()) RESET_STATUS_TIMEOUT();
905 901
       #endif
906 902
 
907 903
       const float abs_diff = ABS(encoderDiff);
@@ -947,9 +943,7 @@ void MarlinUI::update() {
947 943
           encoderDiff = 0;
948 944
         }
949 945
 
950
-        #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
951
-          return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
952
-        #endif
946
+        RESET_STATUS_TIMEOUT();
953 947
 
954 948
         refresh(LCDVIEW_REDRAW_NOW);
955 949
 
@@ -982,9 +976,7 @@ void MarlinUI::update() {
982 976
           lcd_status_update_delay = 12;
983 977
         }
984 978
         refresh(LCDVIEW_REDRAW_NOW);
985
-        #if LCD_TIMEOUT_TO_STATUS
986
-          return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
987
-        #endif
979
+        RESET_STATUS_TIMEOUT();
988 980
       }
989 981
     #endif
990 982
 
@@ -1058,7 +1050,7 @@ void MarlinUI::update() {
1058 1050
     #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
1059 1051
       // Return to Status Screen after a timeout
1060 1052
       if (on_status_screen() || defer_return_to_status)
1061
-        return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1053
+        RESET_STATUS_TIMEOUT();
1062 1054
       else if (ELAPSED(ms, return_to_status_ms))
1063 1055
         return_to_status();
1064 1056
     #endif
@@ -1241,12 +1233,12 @@ void MarlinUI::update() {
1241 1233
           #if HAS_SLOW_BUTTONS
1242 1234
             | slow_buttons
1243 1235
           #endif
1244
-          #if ENABLED(TOUCH_BUTTONS)
1245
-            | touch_buttons
1246
-          #endif
1247 1236
         ;
1237
+
1248 1238
       #elif HAS_ADC_BUTTONS
1239
+
1249 1240
         buttons = 0;
1241
+
1250 1242
       #endif
1251 1243
 
1252 1244
       #if HAS_ADC_BUTTONS

+ 2
- 4
Marlin/src/lcd/ultralcd.h 查看文件

@@ -306,6 +306,8 @@ public:
306 306
 
307 307
     #if HAS_SPI_LCD
308 308
 
309
+      static millis_t next_button_update_ms;
310
+
309 311
       static bool detected();
310 312
 
311 313
       static LCDViewAction lcdDrawUpdate;
@@ -531,10 +533,6 @@ public:
531 533
       static volatile uint8_t slow_buttons;
532 534
       static uint8_t read_slow_buttons();
533 535
     #endif
534
-    #if ENABLED(TOUCH_BUTTONS)
535
-      static volatile uint8_t touch_buttons;
536
-      static uint8_t read_touch_buttons();
537
-    #endif
538 536
 
539 537
     static void update_buttons();
540 538
     static inline bool button_pressed() { return BUTTON_CLICK(); }

正在加载...
取消
保存