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

This commit is contained in:
Robby Candra
2019-08-10 13:42:52 +07:00
committed by Scott Lahteine
parent 8cc0b4bf5e
commit d2d71caa3b
7 changed files with 45 additions and 24 deletions

View File

@ -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);
#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;
@ -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()) {

View File

@ -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