diff --git a/sketch/obd2_gauge/config.h b/sketch/obd2_gauge/config.h index b552ff6..942377d 100644 --- a/sketch/obd2_gauge/config.h +++ b/sketch/obd2_gauge/config.h @@ -2915,7 +2915,9 @@ void configMenu() { tft.fillScreen(TFT_BLACK); drawConfigHeader(); listMenu(select, scrollOffset); - waitForTouchRelease(); + + // Exigir que el usuario levante el dedo antes de registrar cualquier pulsacion en los submenues + bool requireTouchRelease = true; while (true) { if (wokeFromSleep || checkMenuTimeout()) break; @@ -2923,8 +2925,19 @@ void configMenu() { int8_t executeSelect = -1; uint16_t tx = 0, ty = 0; + bool touched = getTouch(&tx, &ty); + bool btnLow = (digitalRead(SELECTOR_PIN) == LOW); - if (getTouch(&tx, &ty)) { + // Solo habilitar interacciones cuando se haya soltado la pantalla y el boton por completo + if (!touched && !btnLow) { + requireTouchRelease = false; + } + + if (touched) { + if (requireTouchRelease) { + delay(15); + continue; + } resetMenuActivity(); int8_t touchedOpt = -1; @@ -2995,7 +3008,11 @@ void configMenu() { executeSelect = select; } } - } else if (digitalRead(SELECTOR_PIN) == LOW) { + } else if (btnLow) { + if (requireTouchRelease) { + delay(15); + continue; + } resetMenuActivity(); if (!pressed) { pressed = true; diff --git a/sketch/obd2_gauge/touchscreen.h b/sketch/obd2_gauge/touchscreen.h index 554c46b..505ca78 100644 --- a/sketch/obd2_gauge/touchscreen.h +++ b/sketch/obd2_gauge/touchscreen.h @@ -49,12 +49,12 @@ inline bool isScreenPressed() { } // Wait until both touchscreen and selector button are completely released with -// 30ms continuous debounce and 250ms maximum hardware safety timeout -inline void waitForTouchRelease() { +// 30ms continuous debounce and 4000ms maximum hardware safety timeout +inline void waitForTouchRelease(uint32_t maxWaitMs = 4000) { uint16_t dummyX, dummyY; uint8_t releaseCount = 0; uint32_t startWait = millis(); - while (releaseCount < 3 && (millis() - startWait < 250)) { + while (releaseCount < 3 && (millis() - startWait < maxWaitMs)) { if (getTouch(&dummyX, &dummyY) || (digitalRead(SELECTOR_PIN) == LOW)) { releaseCount = 0; } else {