style(esp32-32e): reformat code and fix display dimensions

This commit is contained in:
2026-02-17 04:10:03 -08:00
parent 0ace263324
commit f39364f67f
3 changed files with 61 additions and 47 deletions

View File

@@ -17,31 +17,39 @@ void DisplayDriverTFT::begin() {
Serial.println("[GFX] Backlight ON"); Serial.println("[GFX] Backlight ON");
} }
void DisplayDriverTFT::setBacklight(bool on) { void DisplayDriverTFT::setBacklight(bool on) { digitalWrite(PIN_LCD_BL, on ? HIGH : LOW); }
digitalWrite(PIN_LCD_BL, on ? HIGH : LOW);
}
// ── Rendering ─────────────────────────────────────────────── // ── Rendering ───────────────────────────────────────────────
void DisplayDriverTFT::render(const ScreenState& st) { void DisplayDriverTFT::render(const ScreenState& st) {
if (st.screen != _lastScreen) { if(st.screen != _lastScreen) {
_needsRedraw = true; _needsRedraw = true;
_lastScreen = st.screen; _lastScreen = st.screen;
} }
switch (st.screen) { switch(st.screen) {
case ScreenID::BOOT: case ScreenID::BOOT:
if (_needsRedraw) { drawBoot(); _needsRedraw = false; } if(_needsRedraw) {
break; drawBoot();
case ScreenID::ALERT: _needsRedraw = false;
drawAlert(st); }
break; break;
case ScreenID::DASHBOARD: case ScreenID::ALERT:
if (_needsRedraw) { drawDashboard(st); _needsRedraw = false; } drawAlert(st);
break; break;
case ScreenID::OFF:
if (_needsRedraw) { _tft.fillScreen(TFT_BLACK); _needsRedraw = false; } case ScreenID::DASHBOARD:
break; 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)); _tft.printf("KLUBHAUS — %s", deviceStateStr(st.deviceState));
int y = 30; 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.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.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.printf("Up: %lus Heap: %d", st.uptimeMs / 1000, ESP.getFreeHeap());
_tft.setCursor(5, y); y += 18; _tft.setCursor(5, y);
_tft.printf("Last poll: %lus ago", y += 18;
st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0); _tft.printf("Last poll: %lus ago", st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0);
} }
// ── Touch ─────────────────────────────────────────────────── // ── Touch ───────────────────────────────────────────────────
@@ -107,7 +118,7 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
TouchEvent DisplayDriverTFT::readTouch() { TouchEvent DisplayDriverTFT::readTouch() {
TouchEvent evt; TouchEvent evt;
uint16_t tx, ty; uint16_t tx, ty;
if (_tft.getTouch(&tx, &ty)) { if(_tft.getTouch(&tx, &ty)) {
evt.pressed = true; evt.pressed = true;
evt.x = tx; evt.x = tx;
evt.y = ty; evt.y = ty;
@@ -116,30 +127,31 @@ TouchEvent DisplayDriverTFT::readTouch() {
} }
int DisplayDriverTFT::dashboardTouch(int x, int y) { int DisplayDriverTFT::dashboardTouch(int x, int y) {
// Unified 2x2 grid (matching GFX) // 2x2 grid, accounting for 30px header
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1 if(y < 30)
int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1 return -1;
// Adjust for header offset (y starts at 30 in drawDashboard) int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
if (y < 30) return -1; int row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30); // 0 or 1
row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30);
if (row < 0 || row > 1) return -1; if(col < 0 || col > 1 || row < 0 || row > 1)
return -1;
return row * 2 + col; // 0, 1, 2, or 3
return row * 2 + col; // 0, 1, 2, or 3
} }
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) { HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
HoldState h; HoldState h;
TouchEvent t = readTouch(); TouchEvent t = readTouch();
if (t.pressed) { if(t.pressed) {
if (!_holdActive) { if(!_holdActive) {
_holdActive = true; _holdActive = true;
_holdStartMs = millis(); _holdStartMs = millis();
h.started = true; h.started = true;
} }
uint32_t held = millis() - _holdStartMs; uint32_t held = millis() - _holdStartMs;
h.active = true; h.active = true;
h.progress = constrain((float)held / (float)holdMs, 0.0f, 1.0f); h.progress = constrain((float)held / (float)holdMs, 0.0f, 1.0f);
h.completed = (held >= holdMs); 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(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY); _tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
} else { } else {
if (_holdActive) { if(_holdActive) {
// Clear the progress bar when released // Clear the progress bar when released
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY); _tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
} }

View File

@@ -2,20 +2,17 @@
// TFT_eSPI User_Setup for ESP32-32E target // TFT_eSPI User_Setup for ESP32-32E target
// This file is copied over vendor/esp32-32e/TFT_eSPI/User_Setup.h // This file is copied over vendor/esp32-32e/TFT_eSPI/User_Setup.h
// by the install-libs-32e task. // by the install-libs-32e task.
//
// TODO: Change the driver, pins, and dimensions to match your display.
// ═══════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════
#define USER_SETUP_ID 200 #define USER_SETUP_ID 200
// ── Driver ── // ── Driver ──
#define ILI9341_DRIVER #define ILI9341_DRIVER
// #define ST7789_DRIVER
// #define ILI9488_DRIVER
// ── Resolution ── // ── Resolution ──
#define TFT_WIDTH 240 // FIXED: Match board_config.h (320x240 landscape)
#define TFT_HEIGHT 320 #define TFT_WIDTH 320
#define TFT_HEIGHT 240
// ── SPI Pins ── // ── SPI Pins ──
#define TFT_MOSI 23 #define TFT_MOSI 23

View File

@@ -154,7 +154,11 @@ void DisplayDriverGFX::render(const ScreenState& state) {
break; break;
case ScreenID::ALERT: case ScreenID::ALERT:
drawAlert(state); // Only redraw on first entry or screen change
if(_needsRedraw) {
drawAlert(state);
_needsRedraw = false;
}
break; break;
case ScreenID::DASHBOARD: case ScreenID::DASHBOARD:
@@ -167,8 +171,9 @@ void DisplayDriverGFX::render(const ScreenState& state) {
} }
void DisplayDriverGFX::drawAlert(const ScreenState& state) { void DisplayDriverGFX::drawAlert(const ScreenState& state) {
// Always redraw background for animation
uint32_t elapsed = millis() - state.alertStartMs; uint32_t elapsed = millis() - state.alertStartMs;
uint8_t pulse = static_cast<uint8_t>(180.0f + 75.0f * sinf(elapsed / 300.0f)); uint8_cast<uint8_t_t pulse = static>(180.0f + 75.0f * sinf(elapsed / 300.0f));
uint16_t bg = _gfx->color565(pulse, 0, 0); uint16_t bg = _gfx->color565(pulse, 0, 0);
_gfx->fillScreen(bg); _gfx->fillScreen(bg);