Преглед изворни кода

Clean up Touch pins. Better up/down touch response. (#14900)

Robby Candra пре 5 година
родитељ
комит
d2d71caa3b

+ 4
- 8
Marlin/src/feature/touch/xpt2046.cpp Прегледај датотеку

@@ -63,10 +63,6 @@ void XPT2046::init(void) {
63 63
 uint8_t XPT2046::read_buttons() {
64 64
   int16_t tsoffsets[4] = { 0 };
65 65
 
66
-  static uint32_t touchtimeout = 0;
67
-  if (PENDING(millis(), touchtimeout)) return 0;
68
-  touchtimeout = millis() + 80; // ideally want to set this lower for the games... 30 or 40.
69
-
70 66
   if (tsoffsets[0] + tsoffsets[1] == 0) {
71 67
     // Not yet set, so use defines as fallback...
72 68
     tsoffsets[0] = XPT2046_X_CALIBRATION;
@@ -84,10 +80,10 @@ uint8_t XPT2046::read_buttons() {
84 80
 
85 81
   if (y < 175 || y > 234) return 0;
86 82
 
87
-       if (WITHIN(x,  11, 109)) encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * ENCODER_PULSES_PER_STEP;
88
-  else if (WITHIN(x, 111, 209)) encoderDiff =   ENCODER_STEPS_PER_MENU_ITEM  * ENCODER_PULSES_PER_STEP;
89
-  else if (WITHIN(x, 211, 309)) return EN_C;
90
-  return 0;
83
+  return WITHIN(x,  11, 109) ? EN_A
84
+       : WITHIN(x, 111, 209) ? EN_B
85
+       : WITHIN(x, 211, 309) ? EN_C
86
+       : 0;
91 87
 }
92 88
 
93 89
 bool XPT2046::isTouched() {

+ 39
- 7
Marlin/src/lcd/ultralcd.cpp Прегледај датотеку

@@ -764,12 +764,42 @@ void MarlinUI::update() {
764 764
 
765 765
     // If the action button is pressed...
766 766
     static bool wait_for_unclick; // = 0
767
-    if (!external_control && button_pressed()) {
768
-      if (!wait_for_unclick) {                        // If not waiting for a debounce release:
769
-        wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
770
-        lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
771
-        wait_for_user = false;                        //  - Any click clears wait for user
772
-        quick_feedback();                             //  - Always make a click sound
767
+    if (touch_buttons) {
768
+      if (buttons & EN_C) {
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
+      }
776
+      else if (buttons & (EN_A | EN_B)) {               // Ignore the encoder if clicked, to prevent "slippage"
777
+        const millis_t ms = millis();
778
+        if (ELAPSED(ms, next_button_update_ms)) {
779
+          next_button_update_ms = ms + 50;
780
+          encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP);
781
+          if (buttons & EN_A) encoderDiff *= -1;
782
+          if (!wait_for_unclick) {
783
+            next_button_update_ms += 250;
784
+            #if HAS_BUZZER
785
+              buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
786
+            #endif
787
+            wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
788
+          }
789
+        }
790
+      }
791
+    }
792
+    else {
793
+      //
794
+      // Integrated LCD click handling via button_pressed()
795
+      //
796
+      if (!external_control && button_pressed()) {
797
+        if (!wait_for_unclick) {                        // If not waiting for a debounce release:
798
+          wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
799
+          lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
800
+          wait_for_user = false;                        //  - Any click clears wait for user
801
+          quick_feedback();                             //  - Always make a click sound
802
+        }
773 803
       }
774 804
     }
775 805
     else wait_for_unclick = false;
@@ -784,7 +814,9 @@ void MarlinUI::update() {
784 814
   #endif // HAS_LCD_MENU
785 815
 
786 816
   #if ENABLED(INIT_SDCARD_ON_BOOT)
787
-
817
+    //
818
+    // SPI SD Card detection (and first card init when the LCD is present)
819
+    //
788 820
     const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
789 821
     if (sd_status != lcd_sd_status && detected()) {
790 822
 

+ 1
- 1
Marlin/src/lcd/ultralcd.h Прегледај датотеку

@@ -151,7 +151,7 @@
151 151
 
152 152
   #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
153 153
 
154
-  #if BUTTON_EXISTS(ENC)
154
+  #if BUTTON_EXISTS(ENC) || ENABLED(TOUCH_BUTTONS)
155 155
     #define BLEN_C 2
156 156
     #define EN_C _BV(BLEN_C)
157 157
   #endif

+ 0
- 1
Marlin/src/pins/stm32/pins_JGAURORA_A5S_A1.h Прегледај датотеку

@@ -122,7 +122,6 @@
122 122
 // Touch support
123 123
 //
124 124
 #if ENABLED(TOUCH_BUTTONS)
125
-  #define BTN_ENC          PA11   // Real pin needed to enable encoder's push button functionality used by touch screen. PA11 gives stable value.
126 125
   #define TOUCH_CS_PIN     PA4
127 126
   #define TOUCH_INT_PIN    PC4
128 127
 #endif

+ 0
- 4
Marlin/src/pins/stm32/pins_LONGER3D_LK.h Прегледај датотеку

@@ -136,10 +136,6 @@
136 136
   #define TOUCH_MOSI_PIN   PB14  // pin 53
137 137
   #define TOUCH_MISO_PIN   PB15  // pin 54
138 138
   #define TOUCH_INT_PIN    PC6   // pin 63 (PenIRQ coming from ADS7843)
139
-
140
-  #define BTN_ENC          PB0   // pin 35 unconnected pin on Alfawise. (PC13 to try)
141
-  #define BTN_EN1          -1    // Real pin is needed to enable encoder's push button
142
-  #define BTN_EN2          -1    // functionality used by touch screen
143 139
 #endif
144 140
 
145 141
 //

+ 1
- 2
Marlin/src/pins/stm32/pins_MKS_ROBIN_MINI.h Прегледај датотеку

@@ -125,7 +125,6 @@
125 125
   #define LCD_BACKLIGHT_PIN PD13
126 126
 
127 127
   #if ENABLED(TOUCH_BUTTONS)
128
-    #define BTN_ENC        PB3    // Not connected. TODO: Replace this hack to enable button code
129 128
     #define TOUCH_CS_PIN   PC2
130 129
   #endif
131 130
 #endif
@@ -134,7 +133,7 @@
134 133
 #define MOTOR_CURRENT_PWM_XY_PIN   PA6
135 134
 #define MOTOR_CURRENT_PWM_Z_PIN    PA7
136 135
 #define MOTOR_CURRENT_PWM_E_PIN    PB0
137
-#define MOTOR_CURRENT_PWM_RANGE    65535 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
136
+#define MOTOR_CURRENT_PWM_RANGE    1500 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
138 137
 #define DEFAULT_PWM_MOTOR_CURRENT  { 1030, 1030, 1030 } // 1.05Amp per driver, here is XY, Z and E. This values determined empirically.
139 138
 
140 139
 // This is a kind of workaround in case native marlin "digipot" interface won't work.

+ 0
- 1
Marlin/src/pins/stm32/pins_MKS_ROBIN_NANO.h Прегледај датотеку

@@ -129,7 +129,6 @@
129 129
   #define LCD_BACKLIGHT_PIN  PD13
130 130
 
131 131
   #if ENABLED(TOUCH_BUTTONS)
132
-    #define BTN_ENC          PC13   // Not connected. TODO: Replace this hack to enable button code
133 132
     #define TOUCH_CS_PIN     PA7
134 133
   #endif
135 134
 #endif

Loading…
Откажи
Сачувај