From 30f2117e307659b3916b08e61887e2907a9de255 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Mon, 16 Feb 2026 22:11:40 -0800 Subject: [PATCH] refactor(doorbell): unify 2x2 grid touch logic and add progress bar --- .../boards/esp32-32e/DisplayDriverTFT.cpp | 19 +++++++++++---- .../esp32-s3-lcd-43/DisplayDriverGFX.cpp | 23 +++++++++++-------- .../boards/esp32-s3-lcd-43/board_config.h | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/sketches/doorbell-touch/boards/esp32-32e/DisplayDriverTFT.cpp b/sketches/doorbell-touch/boards/esp32-32e/DisplayDriverTFT.cpp index 93dcd24..982a7ca 100644 --- a/sketches/doorbell-touch/boards/esp32-32e/DisplayDriverTFT.cpp +++ b/sketches/doorbell-touch/boards/esp32-32e/DisplayDriverTFT.cpp @@ -116,11 +116,16 @@ TouchEvent DisplayDriverTFT::readTouch() { } int DisplayDriverTFT::dashboardTouch(int x, int y) { - // 2-column, 4-row - int col = x / (DISPLAY_WIDTH / 2); - int row = (y - 30) / 40; - if (row < 0 || row > 3) return -1; - return row * 2 + col; + // Unified 2x2 grid (matching GFX) + int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1 + int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1 + + // Adjust for header offset (y starts at 30 in drawDashboard) + if (y < 30) return -1; + row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30); + if (row < 0 || row > 1) return -1; + + return row * 2 + col; // 0, 1, 2, or 3 } HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) { @@ -142,6 +147,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) { _tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE); _tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY); } else { + if (_ // Clear theholdActive) { + progress bar when released + _tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY); + } _holdActive = false; } return h; diff --git a/sketches/doorbell-touch/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp b/sketches/doorbell-touch/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp index 32bc76e..a186ab7 100644 --- a/sketches/doorbell-touch/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp +++ b/sketches/doorbell-touch/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp @@ -110,31 +110,35 @@ TouchEvent DisplayDriverGFX::readTouch() { } int DisplayDriverGFX::dashboardTouch(int x, int y) { - // Simple 2x2 grid: 4 tiles - int col = (x < DISPLAY_WIDTH / 2) ? 0 : 1; - int row = (y < DISPLAY_HEIGHT / 2) ? 0 : 1; - return row * 2 + col; + // Unified 2x2 grid + int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1 + int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1 + return row * 2 + col; // 0, 1, 2, or 3 } HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) { TouchEvent ev = readTouch(); + if (ev.pressed) { if (!_lastTouched) { _holdStart = millis(); _lastTouched = true; } unsigned long elapsed = millis() - _holdStart; + float progress = constrain((float)elapsed / holdMs, 0.0f, 1.0f); + if (elapsed >= holdMs) { - return {false, true}; + _lastTouched = false; + _holdStart = 0; + return {false, true, 1.0f}; } - return {true, false}; + return {true, false, progress}; } else { _lastTouched = false; _holdStart = 0; - return {false, false}; + return {false, false, 0.0f}; } } - void DisplayDriverGFX::updateHint() { // placeholder for idle hint animation } @@ -240,7 +244,8 @@ void DisplayDriverGFX::drawAlert(const ScreenState& state) { _gfx->println("DOORBELL!"); _gfx->setTextSize(3); _gfx->setCursor(100, 280); - _gfx->println(state.alertBody ? state.alertBody : "Someone is at the door"); + const char* body = state.alertBody.c_str(); + _gfx->println(state.alertBody.length() ? body : "Someone is at the door"); } void DisplayDriverGFX::drawOff() { diff --git a/sketches/doorbell-touch/boards/esp32-s3-lcd-43/board_config.h b/sketches/doorbell-touch/boards/esp32-s3-lcd-43/board_config.h index a1ad825..a712663 100644 --- a/sketches/doorbell-touch/boards/esp32-s3-lcd-43/board_config.h +++ b/sketches/doorbell-touch/boards/esp32-s3-lcd-43/board_config.h @@ -31,7 +31,7 @@ #define LCD_B4 10 // ── I2C bus (shared: CH422G + GT911) ── -#define I2C_MASTER_NUM 0 +#define I2C_MASTER_NUM ((i2c_port_t)0) #define I2C_MASTER_SDA 8 #define I2C_MASTER_SCL 9