diff --git a/boards/esp32-32e/DisplayDriverTFT.cpp b/boards/esp32-32e/DisplayDriverTFT.cpp index 16ba2b1..29b3cbd 100644 --- a/boards/esp32-32e/DisplayDriverTFT.cpp +++ b/boards/esp32-32e/DisplayDriverTFT.cpp @@ -17,31 +17,39 @@ void DisplayDriverTFT::begin() { Serial.println("[GFX] Backlight ON"); } -void DisplayDriverTFT::setBacklight(bool on) { - digitalWrite(PIN_LCD_BL, on ? HIGH : LOW); -} +void DisplayDriverTFT::setBacklight(bool on) { digitalWrite(PIN_LCD_BL, on ? HIGH : LOW); } // ── Rendering ─────────────────────────────────────────────── void DisplayDriverTFT::render(const ScreenState& st) { - if (st.screen != _lastScreen) { + if(st.screen != _lastScreen) { _needsRedraw = true; _lastScreen = st.screen; } - switch (st.screen) { - case ScreenID::BOOT: - if (_needsRedraw) { drawBoot(); _needsRedraw = false; } - break; - case ScreenID::ALERT: - drawAlert(st); - break; - case ScreenID::DASHBOARD: - if (_needsRedraw) { drawDashboard(st); _needsRedraw = false; } - break; - case ScreenID::OFF: - if (_needsRedraw) { _tft.fillScreen(TFT_BLACK); _needsRedraw = false; } - break; + switch(st.screen) { + case ScreenID::BOOT: + if(_needsRedraw) { + drawBoot(); + _needsRedraw = false; + } + break; + case ScreenID::ALERT: + drawAlert(st); + break; + + case ScreenID::DASHBOARD: + if(_needsRedraw) { + drawDashboard(st); + _needsRedraw = false; + } + break; + case ScreenID::OFF: + if(_needsRedraw) { + _tft.fillScreen(TFT_BLACK); + _needsRedraw = false; + } + break; } } @@ -88,18 +96,21 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) { _tft.printf("KLUBHAUS — %s", deviceStateStr(st.deviceState)); int y = 30; - _tft.setCursor(5, y); y += 18; + _tft.setCursor(5, y); + y += 18; _tft.printf("WiFi: %s %ddBm", st.wifiSsid.c_str(), st.wifiRssi); - _tft.setCursor(5, y); y += 18; + _tft.setCursor(5, y); + y += 18; _tft.printf("IP: %s", st.ipAddr.c_str()); - _tft.setCursor(5, y); y += 18; + _tft.setCursor(5, y); + y += 18; _tft.printf("Up: %lus Heap: %d", st.uptimeMs / 1000, ESP.getFreeHeap()); - _tft.setCursor(5, y); y += 18; - _tft.printf("Last poll: %lus ago", - st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0); + _tft.setCursor(5, y); + y += 18; + _tft.printf("Last poll: %lus ago", st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0); } // ── Touch ─────────────────────────────────────────────────── @@ -107,7 +118,7 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) { TouchEvent DisplayDriverTFT::readTouch() { TouchEvent evt; uint16_t tx, ty; - if (_tft.getTouch(&tx, &ty)) { + if(_tft.getTouch(&tx, &ty)) { evt.pressed = true; evt.x = tx; evt.y = ty; @@ -116,30 +127,31 @@ TouchEvent DisplayDriverTFT::readTouch() { } int DisplayDriverTFT::dashboardTouch(int x, int y) { - // 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 + // 2x2 grid, accounting for 30px header + if(y < 30) + return -1; + + int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1 + int row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30); // 0 or 1 + + if(col < 0 || col > 1 || row < 0 || row > 1) + return -1; + + return row * 2 + col; // 0, 1, 2, or 3 } HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) { HoldState h; TouchEvent t = readTouch(); - if (t.pressed) { - if (!_holdActive) { - _holdActive = true; + if(t.pressed) { + if(!_holdActive) { + _holdActive = true; _holdStartMs = millis(); h.started = true; } uint32_t held = millis() - _holdStartMs; - h.active = true; + h.active = true; h.progress = constrain((float)held / (float)holdMs, 0.0f, 1.0f); h.completed = (held >= holdMs); @@ -148,7 +160,7 @@ 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 (_holdActive) { + if(_holdActive) { // Clear the progress bar when released _tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY); } diff --git a/boards/esp32-32e/tft_user_setup.h b/boards/esp32-32e/tft_user_setup.h index e299e0a..ff824e8 100644 --- a/boards/esp32-32e/tft_user_setup.h +++ b/boards/esp32-32e/tft_user_setup.h @@ -2,20 +2,17 @@ // TFT_eSPI User_Setup for ESP32-32E target // This file is copied over vendor/esp32-32e/TFT_eSPI/User_Setup.h // by the install-libs-32e task. -// -// TODO: Change the driver, pins, and dimensions to match your display. // ═══════════════════════════════════════════════════════════ #define USER_SETUP_ID 200 // ── Driver ── #define ILI9341_DRIVER -// #define ST7789_DRIVER -// #define ILI9488_DRIVER // ── Resolution ── -#define TFT_WIDTH 240 -#define TFT_HEIGHT 320 +// FIXED: Match board_config.h (320x240 landscape) +#define TFT_WIDTH 320 +#define TFT_HEIGHT 240 // ── SPI Pins ── #define TFT_MOSI 23 diff --git a/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp b/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp index 18fe613..53ee92a 100644 --- a/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp +++ b/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp @@ -154,7 +154,11 @@ void DisplayDriverGFX::render(const ScreenState& state) { break; case ScreenID::ALERT: - drawAlert(state); + // Only redraw on first entry or screen change + if(_needsRedraw) { + drawAlert(state); + _needsRedraw = false; + } break; case ScreenID::DASHBOARD: @@ -167,8 +171,9 @@ void DisplayDriverGFX::render(const ScreenState& state) { } void DisplayDriverGFX::drawAlert(const ScreenState& state) { + // Always redraw background for animation uint32_t elapsed = millis() - state.alertStartMs; - uint8_t pulse = static_cast(180.0f + 75.0f * sinf(elapsed / 300.0f)); + uint8_cast(180.0f + 75.0f * sinf(elapsed / 300.0f)); uint16_t bg = _gfx->color565(pulse, 0, 0); _gfx->fillScreen(bg);