style(esp32-32e): reformat code and fix display dimensions
This commit is contained in:
@@ -17,30 +17,38 @@ 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) {
|
||||
switch(st.screen) {
|
||||
case ScreenID::BOOT:
|
||||
if (_needsRedraw) { drawBoot(); _needsRedraw = false; }
|
||||
if(_needsRedraw) {
|
||||
drawBoot();
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
case ScreenID::ALERT:
|
||||
drawAlert(st);
|
||||
break;
|
||||
|
||||
case ScreenID::DASHBOARD:
|
||||
if (_needsRedraw) { drawDashboard(st); _needsRedraw = false; }
|
||||
if(_needsRedraw) {
|
||||
drawDashboard(st);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
case ScreenID::OFF:
|
||||
if (_needsRedraw) { _tft.fillScreen(TFT_BLACK); _needsRedraw = false; }
|
||||
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,14 +127,15 @@ 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
|
||||
// 2x2 grid, accounting for 30px header
|
||||
if(y < 30)
|
||||
return -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;
|
||||
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
|
||||
}
|
||||
@@ -132,8 +144,8 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
HoldState h;
|
||||
TouchEvent t = readTouch();
|
||||
|
||||
if (t.pressed) {
|
||||
if (!_holdActive) {
|
||||
if(t.pressed) {
|
||||
if(!_holdActive) {
|
||||
_holdActive = true;
|
||||
_holdStartMs = millis();
|
||||
h.started = true;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -154,7 +154,11 @@ void DisplayDriverGFX::render(const ScreenState& state) {
|
||||
break;
|
||||
|
||||
case ScreenID::ALERT:
|
||||
// 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<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);
|
||||
|
||||
_gfx->fillScreen(bg);
|
||||
|
||||
Reference in New Issue
Block a user