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");
}
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);
}