Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
10 changes: 3 additions & 7 deletions Marlin/src/feature/touch/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ void XPT2046::init(void) {
uint8_t XPT2046::read_buttons() {
int16_t tsoffsets[4] = { 0 };

static uint32_t touchtimeout = 0;
if (PENDING(millis(), touchtimeout)) return 0;
touchtimeout = millis() + 80; // ideally want to set this lower for the games... 30 or 40.

if (tsoffsets[0] + tsoffsets[1] == 0) {
// Not yet set, so use defines as fallback...
tsoffsets[0] = XPT2046_X_CALIBRATION;
Expand All @@ -84,9 +80,9 @@ uint8_t XPT2046::read_buttons() {

if (y < 175 || y > 234) return 0;

if (WITHIN(x, 11, 109)) encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * ENCODER_PULSES_PER_STEP;
else if (WITHIN(x, 111, 209)) encoderDiff = ENCODER_STEPS_PER_MENU_ITEM * ENCODER_PULSES_PER_STEP;
else if (WITHIN(x, 211, 309)) return EN_C;
if (WITHIN(x, 11, 109)) return EN_A; //encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * ENCODER_PULSES_PER_STEP;
if (WITHIN(x, 111, 209)) return EN_B; //encoderDiff = ENCODER_STEPS_PER_MENU_ITEM * ENCODER_PULSES_PER_STEP;
if (WITHIN(x, 211, 309)) return EN_C;
return 0;
}

Expand Down
46 changes: 39 additions & 7 deletions Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,42 @@ void MarlinUI::update() {

// If the action button is pressed...
static bool wait_for_unclick; // = 0
if (!external_control && button_pressed()) {
if (!wait_for_unclick) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound
if (touch_buttons) {
if (buttons & EN_C) {
if (!wait_for_unclick) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound
}
}
else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage"
const millis_t ms = millis();
if (ELAPSED(ms, next_button_update_ms)) {
next_button_update_ms = ms + 50;
encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP);
if (buttons & EN_A) encoderDiff *= -1;
if (!wait_for_unclick) {
next_button_update_ms += 250;
#if HAS_BUZZER
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#endif
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
}
}
}
}
else {
//
// Integrated LCD click handling via button_pressed()
//
if (!external_control && button_pressed()) {
if (!wait_for_unclick) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click
wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound
}
}
}
else wait_for_unclick = false;
Expand All @@ -784,7 +814,9 @@ void MarlinUI::update() {
#endif // HAS_LCD_MENU

#if ENABLED(INIT_SDCARD_ON_BOOT)

//
// SPI SD Card detection (and first card init when the LCD is present)
//
const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
if (sd_status != lcd_sd_status && detected()) {

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

#define BUTTON_PRESSED(BN) !READ(BTN_## BN)

#if BUTTON_EXISTS(ENC)
#if BUTTON_EXISTS(ENC) || ENABLED(TOUCH_BUTTONS)
#define BLEN_C 2
#define EN_C _BV(BLEN_C)
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32/pins_JGAURORA_A5S_A1.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
// Touch support
//
#if ENABLED(TOUCH_BUTTONS)
#define BTN_ENC PA11 // Real pin needed to enable encoder's push button functionality used by touch screen. PA11 gives stable value.
//#define BTN_ENC PA11 // Real pin needed to enable encoder's push button functionality used by touch screen. PA11 gives stable value.
#define TOUCH_CS_PIN PA4
#define TOUCH_INT_PIN PC4
#endif
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32/pins_LONGER3D_LK.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
#define TOUCH_MISO_PIN PB15 // pin 54
#define TOUCH_INT_PIN PC6 // pin 63 (PenIRQ coming from ADS7843)

#define BTN_ENC PB0 // pin 35 unconnected pin on Alfawise. (PC13 to try)
//#define BTN_ENC PB0 // pin 35 unconnected pin on Alfawise. (PC13 to try)
#define BTN_EN1 -1 // Real pin is needed to enable encoder's push button
#define BTN_EN2 -1 // functionality used by touch screen
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/stm32/pins_MKS_ROBIN_MINI.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
#define LCD_BACKLIGHT_PIN PD13

#if ENABLED(TOUCH_BUTTONS)
#define BTN_ENC PB3 // Not connected. TODO: Replace this hack to enable button code
//#define BTN_ENC PB3 // Not connected. TODO: Replace this hack to enable button code
#define TOUCH_CS_PIN PC2
#endif
#endif
Expand All @@ -134,7 +134,7 @@
#define MOTOR_CURRENT_PWM_XY_PIN PA6
#define MOTOR_CURRENT_PWM_Z_PIN PA7
#define MOTOR_CURRENT_PWM_E_PIN PB0
#define MOTOR_CURRENT_PWM_RANGE 65535 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
#define MOTOR_CURRENT_PWM_RANGE 1500 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp
#define DEFAULT_PWM_MOTOR_CURRENT { 1030, 1030, 1030 } // 1.05Amp per driver, here is XY, Z and E. This values determined empirically.

// This is a kind of workaround in case native marlin "digipot" interface won't work.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32/pins_MKS_ROBIN_NANO.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#define LCD_BACKLIGHT_PIN PD13

#if ENABLED(TOUCH_BUTTONS)
#define BTN_ENC PC13 // Not connected. TODO: Replace this hack to enable button code
//#define BTN_ENC PC13 // Not connected. TODO: Replace this hack to enable button code
#define TOUCH_CS_PIN PA7
#endif
#endif