Clean up Touch pins. Better up/down touch response. (#14900)
This commit is contained in:
parent
8cc0b4bf5e
commit
d2d71caa3b
7 changed files with 45 additions and 24 deletions
|
@ -63,10 +63,6 @@ void XPT2046::init(void) {
|
||||||
uint8_t XPT2046::read_buttons() {
|
uint8_t XPT2046::read_buttons() {
|
||||||
int16_t tsoffsets[4] = { 0 };
|
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) {
|
if (tsoffsets[0] + tsoffsets[1] == 0) {
|
||||||
// Not yet set, so use defines as fallback...
|
// Not yet set, so use defines as fallback...
|
||||||
tsoffsets[0] = XPT2046_X_CALIBRATION;
|
tsoffsets[0] = XPT2046_X_CALIBRATION;
|
||||||
|
@ -84,10 +80,10 @@ uint8_t XPT2046::read_buttons() {
|
||||||
|
|
||||||
if (y < 175 || y > 234) return 0;
|
if (y < 175 || y > 234) return 0;
|
||||||
|
|
||||||
if (WITHIN(x, 11, 109)) encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM) * ENCODER_PULSES_PER_STEP;
|
return WITHIN(x, 11, 109) ? EN_A
|
||||||
else if (WITHIN(x, 111, 209)) encoderDiff = ENCODER_STEPS_PER_MENU_ITEM * ENCODER_PULSES_PER_STEP;
|
: WITHIN(x, 111, 209) ? EN_B
|
||||||
else if (WITHIN(x, 211, 309)) return EN_C;
|
: WITHIN(x, 211, 309) ? EN_C
|
||||||
return 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XPT2046::isTouched() {
|
bool XPT2046::isTouched() {
|
||||||
|
|
|
@ -764,6 +764,35 @@ void MarlinUI::update() {
|
||||||
|
|
||||||
// If the action button is pressed...
|
// If the action button is pressed...
|
||||||
static bool wait_for_unclick; // = 0
|
static bool wait_for_unclick; // = 0
|
||||||
|
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);
|
||||||
|
#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 (!external_control && button_pressed()) {
|
||||||
if (!wait_for_unclick) { // If not waiting for a debounce release:
|
if (!wait_for_unclick) { // If not waiting for a debounce release:
|
||||||
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
|
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
|
||||||
|
@ -772,6 +801,7 @@ void MarlinUI::update() {
|
||||||
quick_feedback(); // - Always make a click sound
|
quick_feedback(); // - Always make a click sound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else wait_for_unclick = false;
|
else wait_for_unclick = false;
|
||||||
|
|
||||||
#if HAS_DIGITAL_BUTTONS && BUTTON_EXISTS(BACK)
|
#if HAS_DIGITAL_BUTTONS && BUTTON_EXISTS(BACK)
|
||||||
|
@ -784,7 +814,9 @@ void MarlinUI::update() {
|
||||||
#endif // HAS_LCD_MENU
|
#endif // HAS_LCD_MENU
|
||||||
|
|
||||||
#if ENABLED(INIT_SDCARD_ON_BOOT)
|
#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();
|
const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
|
||||||
if (sd_status != lcd_sd_status && detected()) {
|
if (sd_status != lcd_sd_status && detected()) {
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@
|
||||||
|
|
||||||
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
|
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
|
||||||
|
|
||||||
#if BUTTON_EXISTS(ENC)
|
#if BUTTON_EXISTS(ENC) || ENABLED(TOUCH_BUTTONS)
|
||||||
#define BLEN_C 2
|
#define BLEN_C 2
|
||||||
#define EN_C _BV(BLEN_C)
|
#define EN_C _BV(BLEN_C)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -122,7 +122,6 @@
|
||||||
// Touch support
|
// Touch support
|
||||||
//
|
//
|
||||||
#if ENABLED(TOUCH_BUTTONS)
|
#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 TOUCH_CS_PIN PA4
|
#define TOUCH_CS_PIN PA4
|
||||||
#define TOUCH_INT_PIN PC4
|
#define TOUCH_INT_PIN PC4
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -136,10 +136,6 @@
|
||||||
#define TOUCH_MOSI_PIN PB14 // pin 53
|
#define TOUCH_MOSI_PIN PB14 // pin 53
|
||||||
#define TOUCH_MISO_PIN PB15 // pin 54
|
#define TOUCH_MISO_PIN PB15 // pin 54
|
||||||
#define TOUCH_INT_PIN PC6 // pin 63 (PenIRQ coming from ADS7843)
|
#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_EN1 -1 // Real pin is needed to enable encoder's push button
|
|
||||||
#define BTN_EN2 -1 // functionality used by touch screen
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
#define LCD_BACKLIGHT_PIN PD13
|
#define LCD_BACKLIGHT_PIN PD13
|
||||||
|
|
||||||
#if ENABLED(TOUCH_BUTTONS)
|
#if ENABLED(TOUCH_BUTTONS)
|
||||||
#define BTN_ENC PB3 // Not connected. TODO: Replace this hack to enable button code
|
|
||||||
#define TOUCH_CS_PIN PC2
|
#define TOUCH_CS_PIN PC2
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -134,7 +133,7 @@
|
||||||
#define MOTOR_CURRENT_PWM_XY_PIN PA6
|
#define MOTOR_CURRENT_PWM_XY_PIN PA6
|
||||||
#define MOTOR_CURRENT_PWM_Z_PIN PA7
|
#define MOTOR_CURRENT_PWM_Z_PIN PA7
|
||||||
#define MOTOR_CURRENT_PWM_E_PIN PB0
|
#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.
|
#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.
|
// This is a kind of workaround in case native marlin "digipot" interface won't work.
|
||||||
|
|
|
@ -129,7 +129,6 @@
|
||||||
#define LCD_BACKLIGHT_PIN PD13
|
#define LCD_BACKLIGHT_PIN PD13
|
||||||
|
|
||||||
#if ENABLED(TOUCH_BUTTONS)
|
#if ENABLED(TOUCH_BUTTONS)
|
||||||
#define BTN_ENC PC13 // Not connected. TODO: Replace this hack to enable button code
|
|
||||||
#define TOUCH_CS_PIN PA7
|
#define TOUCH_CS_PIN PA7
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
Reference in a new issue