Browse Source

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

Robby Candra 5 years ago
parent
commit
d2d71caa3b

+ 4
- 8
Marlin/src/feature/touch/xpt2046.cpp View File

63
 uint8_t XPT2046::read_buttons() {
63
 uint8_t XPT2046::read_buttons() {
64
   int16_t tsoffsets[4] = { 0 };
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
   if (tsoffsets[0] + tsoffsets[1] == 0) {
66
   if (tsoffsets[0] + tsoffsets[1] == 0) {
71
     // Not yet set, so use defines as fallback...
67
     // Not yet set, so use defines as fallback...
72
     tsoffsets[0] = XPT2046_X_CALIBRATION;
68
     tsoffsets[0] = XPT2046_X_CALIBRATION;
84
 
80
 
85
   if (y < 175 || y > 234) return 0;
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
 bool XPT2046::isTouched() {
89
 bool XPT2046::isTouched() {

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

764
 
764
 
765
     // If the action button is pressed...
765
     // If the action button is pressed...
766
     static bool wait_for_unclick; // = 0
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
     else wait_for_unclick = false;
805
     else wait_for_unclick = false;
784
   #endif // HAS_LCD_MENU
814
   #endif // HAS_LCD_MENU
785
 
815
 
786
   #if ENABLED(INIT_SDCARD_ON_BOOT)
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
     const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
820
     const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
789
     if (sd_status != lcd_sd_status && detected()) {
821
     if (sd_status != lcd_sd_status && detected()) {
790
 
822
 

+ 1
- 1
Marlin/src/lcd/ultralcd.h View File

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

+ 0
- 1
Marlin/src/pins/stm32/pins_JGAURORA_A5S_A1.h View File

122
 // Touch support
122
 // Touch support
123
 //
123
 //
124
 #if ENABLED(TOUCH_BUTTONS)
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
   #define TOUCH_CS_PIN     PA4
125
   #define TOUCH_CS_PIN     PA4
127
   #define TOUCH_INT_PIN    PC4
126
   #define TOUCH_INT_PIN    PC4
128
 #endif
127
 #endif

+ 0
- 4
Marlin/src/pins/stm32/pins_LONGER3D_LK.h View File

136
   #define TOUCH_MOSI_PIN   PB14  // pin 53
136
   #define TOUCH_MOSI_PIN   PB14  // pin 53
137
   #define TOUCH_MISO_PIN   PB15  // pin 54
137
   #define TOUCH_MISO_PIN   PB15  // pin 54
138
   #define TOUCH_INT_PIN    PC6   // pin 63 (PenIRQ coming from ADS7843)
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
 #endif
139
 #endif
144
 
140
 
145
 //
141
 //

+ 1
- 2
Marlin/src/pins/stm32/pins_MKS_ROBIN_MINI.h View File

125
   #define LCD_BACKLIGHT_PIN PD13
125
   #define LCD_BACKLIGHT_PIN PD13
126
 
126
 
127
   #if ENABLED(TOUCH_BUTTONS)
127
   #if ENABLED(TOUCH_BUTTONS)
128
-    #define BTN_ENC        PB3    // Not connected. TODO: Replace this hack to enable button code
129
     #define TOUCH_CS_PIN   PC2
128
     #define TOUCH_CS_PIN   PC2
130
   #endif
129
   #endif
131
 #endif
130
 #endif
134
 #define MOTOR_CURRENT_PWM_XY_PIN   PA6
133
 #define MOTOR_CURRENT_PWM_XY_PIN   PA6
135
 #define MOTOR_CURRENT_PWM_Z_PIN    PA7
134
 #define MOTOR_CURRENT_PWM_Z_PIN    PA7
136
 #define MOTOR_CURRENT_PWM_E_PIN    PB0
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
 #define DEFAULT_PWM_MOTOR_CURRENT  { 1030, 1030, 1030 } // 1.05Amp per driver, here is XY, Z and E. This values determined empirically.
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
 // This is a kind of workaround in case native marlin "digipot" interface won't work.
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 View File

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

Loading…
Cancel
Save