From 4f389ac0fef571a31b7bcc18e102991d144479f9 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 17 Feb 2026 23:20:42 -0800 Subject: [PATCH] feat(touch): add continuous touch polling and debug logging --- boards/esp32-32e-4/DisplayDriverTFT.cpp | 7 +++++++ boards/esp32-32e-4/DisplayDriverTFT.h | 1 + boards/esp32-32e-4/esp32-32e-4.ino | 17 +++++++++++++++++ boards/esp32-32e-4/tft_user_setup.h | 1 + 4 files changed, 26 insertions(+) diff --git a/boards/esp32-32e-4/DisplayDriverTFT.cpp b/boards/esp32-32e-4/DisplayDriverTFT.cpp index 928fe16..92147a2 100644 --- a/boards/esp32-32e-4/DisplayDriverTFT.cpp +++ b/boards/esp32-32e-4/DisplayDriverTFT.cpp @@ -10,15 +10,18 @@ void DisplayDriverTFT::begin() { _tft.fillScreen(TFT_BLACK); Serial.printf("[GFX] Display OK: %dx%d\n", DISPLAY_WIDTH, DISPLAY_HEIGHT); + Serial.flush(); // Debug: check if touch controller is responding uint16_t z = _tft.getTouchRawZ(); Serial.printf("[TOUCH] Raw Z=%d (non-zero = controller detected)\n", z); + Serial.flush(); drawBoot(); digitalWrite(PIN_LCD_BL, HIGH); Serial.println("[GFX] Backlight ON"); + Serial.flush(); } void DisplayDriverTFT::setBacklight(bool on) { digitalWrite(PIN_LCD_BL, on ? HIGH : LOW); } @@ -132,6 +135,10 @@ TouchEvent DisplayDriverTFT::readTouch() { return evt; } +uint16_t DisplayDriverTFT::getRawTouchZ() { + return _tft.getTouchRawZ(); +} + int DisplayDriverTFT::dashboardTouch(int x, int y) { // 2x2 grid, accounting for 30px header if(y < 30) diff --git a/boards/esp32-32e-4/DisplayDriverTFT.h b/boards/esp32-32e-4/DisplayDriverTFT.h index c8e1c18..5c388e5 100644 --- a/boards/esp32-32e-4/DisplayDriverTFT.h +++ b/boards/esp32-32e-4/DisplayDriverTFT.h @@ -11,6 +11,7 @@ public: void setBacklight(bool on) override; void render(const ScreenState& state) override; TouchEvent readTouch() override; + uint16_t getRawTouchZ(); int dashboardTouch(int x, int y) override; HoldState updateHold(unsigned long holdMs) override; void updateHint(int x, int y, bool active) override; diff --git a/boards/esp32-32e-4/esp32-32e-4.ino b/boards/esp32-32e-4/esp32-32e-4.ino index 56f0cb4..8b72e6a 100644 --- a/boards/esp32-32e-4/esp32-32e-4.ino +++ b/boards/esp32-32e-4/esp32-32e-4.ino @@ -21,6 +21,20 @@ void setup() { } void loop() { + // ── Touch debug: poll continuously ── + TouchEvent evt = display.readTouch(); + if(evt.pressed) { + Serial.printf("[TOUCH] pressed: x=%d, y=%d\n", evt.x, evt.y); + } else { + // Debug: print raw Z even when not touched, to see controller state + static uint32_t lastDebug = 0; + if(millis() - lastDebug > 2000) { + lastDebug = millis(); + uint16_t z = tftDriver.getRawTouchZ(); + Serial.printf("[TOUCH] Raw Z=%d\n", z); + } + } + // ── State machine tick ── logic.update(); @@ -68,4 +82,7 @@ void loop() { if(cmd.length() > 0) logic.onSerialCommand(cmd); } + + // Yield to WiFi/BT stack (prevents Task Watchdog timeout) + delay(10); } \ No newline at end of file diff --git a/boards/esp32-32e-4/tft_user_setup.h b/boards/esp32-32e-4/tft_user_setup.h index 6964a53..8f5665c 100644 --- a/boards/esp32-32e-4/tft_user_setup.h +++ b/boards/esp32-32e-4/tft_user_setup.h @@ -27,6 +27,7 @@ // ── Touch (XPT2046 resistive) ── #define TOUCH_CS 33 +#define TOUCH_IRQ 36 // ── SPI speed ── #define SPI_FREQUENCY 40000000