refactor: improve touch handling and UI element detection

This commit is contained in:
2026-02-20 00:36:29 -08:00
parent 6d51234f21
commit 9c8f67dccb
5 changed files with 153 additions and 40 deletions

View File

@@ -90,7 +90,8 @@ void DisplayDriverTFT::begin() {
_tft.setRotation(DISPLAY_ROTATION);
_tft.fillScreen(TFT_BLACK);
Serial.printf("[GFX] Display OK: %dx%d\n", DISPLAY_WIDTH, DISPLAY_HEIGHT);
Serial.printf("[GFX] Display OK: const %dx%d, tft %dx%d\n", DISPLAY_WIDTH, DISPLAY_HEIGHT,
_tft.width(), _tft.height());
Serial.flush();
// Debug: check if touch controller is responding
@@ -153,16 +154,16 @@ void DisplayDriverTFT::drawBoot(const ScreenState& st) {
_tft.setTextColor(TFT_WHITE, TFT_BLACK);
setTitleFont();
_tft.setCursor(10, 10);
_tft.setCursor(10, 28); // y=28 baseline accounts for ~18px font height above baseline
_tft.print("KLUBHAUS");
setBodyFont();
_tft.setCursor(10, 40);
_tft.setCursor(10, 55); // y adjusted for ~12px font
_tft.print(BOARD_NAME);
// Show boot stage status
setLabelFont();
_tft.setCursor(10, 70);
_tft.setCursor(10, 85); // y adjusted for ~9px label font
switch(stage) {
case BootStage::SPLASH:
_tft.print("Initializing...");
@@ -194,30 +195,34 @@ void DisplayDriverTFT::drawAlert(const ScreenState& st) {
_tft.setTextColor(TFT_WHITE, bg);
setTitleFont();
_tft.setCursor(10, 20);
_tft.setCursor(10, 28); // y=28 baseline for ~18px font
_tft.print(st.alertTitle.length() > 0 ? st.alertTitle : "ALERT");
setBodyFont();
_tft.setCursor(10, 80);
_tft.setCursor(10, 70); // y adjusted for ~12px body font
_tft.print(st.alertBody);
setLabelFont();
_tft.setCursor(10, DISPLAY_HEIGHT - 20);
_tft.setCursor(10, _tft.height() - 10); // y adjusted for ~9px label font
_tft.print("Hold to silence...");
}
void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
_tft.fillScreen(TFT_BLACK);
// Use actual display dimensions (after rotation)
int dispW = _tft.width();
int dispH = _tft.height();
// Header - using standard bitmap font for reliable positioning
_tft.fillRect(0, 0, DISPLAY_WIDTH, 30, 0x1A1A); // Dark gray header
_tft.fillRect(0, 0, dispW, STYLE_HEADER_HEIGHT, 0x1A1A); // Dark gray header
_tft.setTextSize(1);
_tft.setTextColor(TFT_WHITE);
_tft.setCursor(5, 20); // y=28 is baseline, text sits above this
_tft.print("KLUBHAUS");
// WiFi indicator
_tft.setCursor(DISPLAY_WIDTH - 60, 20);
// WiFi indicator - right aligned in header
_tft.setCursor(dispW - 50, 20);
_tft.print(st.wifiSsid.length() > 0 ? "WiFi:ON" : "WiFi:OFF");
// Get tile layouts from library helper
@@ -336,13 +341,15 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
h.completed = (held >= holdMs);
// Simple progress bar at bottom of screen
int barW = (int)(DISPLAY_WIDTH * h.progress);
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
int dispW = _tft.width();
int dispH = _tft.height();
int barW = (int)(dispW * h.progress);
_tft.fillRect(0, dispH - 8, barW, 8, TFT_WHITE);
_tft.fillRect(barW, dispH - 8, dispW - barW, 8, TFT_DARKGREY);
} else {
if(_holdActive) {
// Clear the progress bar when released
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
_tft.fillRect(0, _tft.height() - 8, _tft.width(), 8, TFT_DARKGREY);
}
_holdActive = false;
}