snapshot
This commit is contained in:
@@ -9,10 +9,12 @@ DisplayManager::DisplayManager()
|
||||
void DisplayManager::begin() {
|
||||
pinMode(PIN_LCD_BL, OUTPUT);
|
||||
setBacklight(true);
|
||||
|
||||
_tft.init();
|
||||
_tft.setRotation(1); // landscape: 480x320
|
||||
_tft.setRotation(1);
|
||||
_tft.fillScreen(COL_BLACK);
|
||||
|
||||
uint16_t calData[5] = { 300, 3600, 300, 3600, 1 };
|
||||
_tft.setTouch(calData);
|
||||
}
|
||||
|
||||
void DisplayManager::setBacklight(bool on) {
|
||||
@@ -35,10 +37,53 @@ int DisplayManager::dashboardTouch(uint16_t x, uint16_t y) {
|
||||
return _dash.handleTouch(x, y);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Hold detection
|
||||
// =====================================================================
|
||||
HoldState DisplayManager::updateHold(unsigned long requiredMs) {
|
||||
HoldState h;
|
||||
h.targetMs = requiredMs;
|
||||
|
||||
uint16_t tx, ty;
|
||||
bool touching = _tft.getTouch(&tx, &ty);
|
||||
|
||||
if (touching) {
|
||||
if (!_holdActive) {
|
||||
_holdActive = true;
|
||||
_holdStartMs = millis();
|
||||
_holdX = tx;
|
||||
_holdY = ty;
|
||||
}
|
||||
h.active = true;
|
||||
h.x = _holdX;
|
||||
h.y = _holdY;
|
||||
h.holdMs = millis() - _holdStartMs;
|
||||
_holdProgress = min((float)h.holdMs / (float)requiredMs, 1.0f);
|
||||
|
||||
if (h.holdMs >= requiredMs) {
|
||||
h.completed = true;
|
||||
_holdActive = false;
|
||||
_holdProgress = 0.0f;
|
||||
}
|
||||
} else {
|
||||
_holdActive = false;
|
||||
_holdProgress = 0.0f;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Render
|
||||
// =====================================================================
|
||||
void DisplayManager::render(const ScreenState& state) {
|
||||
// Detect screen change → force full redraw
|
||||
if (state.screen != _lastScreen) {
|
||||
_needsFullRedraw = true;
|
||||
if (state.screen == ScreenID::OFF) {
|
||||
setBacklight(false);
|
||||
} else if (_lastScreen == ScreenID::OFF) {
|
||||
setBacklight(true);
|
||||
}
|
||||
_lastScreen = state.screen;
|
||||
}
|
||||
|
||||
@@ -60,6 +105,9 @@ void DisplayManager::render(const ScreenState& state) {
|
||||
drawAlertScreen(state);
|
||||
_lastBlink = state.blinkPhase;
|
||||
}
|
||||
if (_holdProgress > 0.0f) {
|
||||
drawSilenceProgress(_holdProgress);
|
||||
}
|
||||
break;
|
||||
case ScreenID::STATUS:
|
||||
if (_needsFullRedraw) drawStatusScreen(state);
|
||||
@@ -68,42 +116,76 @@ void DisplayManager::render(const ScreenState& state) {
|
||||
drawDashboard(state);
|
||||
break;
|
||||
case ScreenID::OFF:
|
||||
if (_needsFullRedraw) {
|
||||
_tft.fillScreen(COL_BLACK);
|
||||
_dashSpriteReady = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
_needsFullRedraw = false;
|
||||
}
|
||||
|
||||
// ----- Dashboard -----
|
||||
|
||||
// =====================================================================
|
||||
// Dashboard
|
||||
// =====================================================================
|
||||
void DisplayManager::drawDashboard(const ScreenState& s) {
|
||||
if (_needsFullRedraw) {
|
||||
if (!_dashSpriteReady) {
|
||||
_dash.begin(); // create sprite (once)
|
||||
_dash.begin();
|
||||
_dashSpriteReady = true;
|
||||
}
|
||||
_dash.drawAll(); // fill screen + draw all tiles
|
||||
_dash.refreshFromState(s); // update with real data
|
||||
_dash.drawAll();
|
||||
_dash.refreshFromState(s);
|
||||
_lastDashRefresh = millis();
|
||||
} else if (millis() - _lastDashRefresh > 2000) {
|
||||
_lastDashRefresh = millis();
|
||||
_dash.refreshFromState(s); // only redraws changed tiles
|
||||
_dash.refreshFromState(s);
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Helpers -----
|
||||
// =====================================================================
|
||||
// Silence progress bar
|
||||
// =====================================================================
|
||||
void DisplayManager::drawSilenceProgress(float progress) {
|
||||
int barX = 10;
|
||||
int barY = SCREEN_HEIGHT - 35;
|
||||
int barW = SCREEN_WIDTH - 20;
|
||||
int barH = 25;
|
||||
int fillW = (int)(barW * progress);
|
||||
|
||||
_tft.fillRect(barX, barY, barW, barH, COL_BLACK);
|
||||
if (fillW > 0) {
|
||||
_tft.fillRect(barX, barY, fillW, barH, COL_GREEN);
|
||||
}
|
||||
_tft.drawRect(barX, barY, barW, barH, COL_WHITE);
|
||||
|
||||
_tft.setTextFont(1);
|
||||
_tft.setTextSize(2);
|
||||
_tft.setTextDatum(MC_DATUM);
|
||||
if (progress >= 1.0f) {
|
||||
_tft.setTextColor(COL_BLACK);
|
||||
_tft.drawString("SILENCED", SCREEN_WIDTH / 2, barY + barH / 2);
|
||||
} else {
|
||||
_tft.setTextColor(COL_WHITE);
|
||||
_tft.drawString("HOLD TO SILENCE", SCREEN_WIDTH / 2, barY + barH / 2);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Helpers
|
||||
// =====================================================================
|
||||
void DisplayManager::drawCentered(const char* txt, int y, int sz, uint16_t col) {
|
||||
_tft.setTextFont(1); // ← ADDED: force GLCD font
|
||||
_tft.setTextFont(1);
|
||||
_tft.setTextSize(sz);
|
||||
_tft.setTextColor(col);
|
||||
int w = _tft.textWidth(txt); // ← use TFT_eSPI's own width calc
|
||||
int w = _tft.textWidth(txt);
|
||||
_tft.setCursor(max(0, (SCREEN_WIDTH - w) / 2), y);
|
||||
_tft.print(txt);
|
||||
}
|
||||
|
||||
void DisplayManager::drawInfoLine(int x, int y, uint16_t col, const char* text) {
|
||||
_tft.setTextFont(1); // ← ADDED
|
||||
_tft.setTextFont(1);
|
||||
_tft.setTextSize(1);
|
||||
_tft.setTextColor(col);
|
||||
_tft.setCursor(x, y);
|
||||
@@ -111,23 +193,24 @@ void DisplayManager::drawInfoLine(int x, int y, uint16_t col, const char* text)
|
||||
}
|
||||
|
||||
void DisplayManager::drawHeaderBar(uint16_t col, const char* label, const char* timeStr) {
|
||||
_tft.setTextFont(1); // ← ADDED
|
||||
_tft.setTextFont(1);
|
||||
_tft.setTextSize(2);
|
||||
_tft.setTextColor(col);
|
||||
_tft.setCursor(8, 8);
|
||||
_tft.print(label);
|
||||
|
||||
int tw = _tft.textWidth(timeStr); // ← proper width calc
|
||||
int tw = _tft.textWidth(timeStr);
|
||||
_tft.setCursor(SCREEN_WIDTH - tw - 8, 8);
|
||||
_tft.print(timeStr);
|
||||
}
|
||||
// ----- Screens -----
|
||||
|
||||
// =====================================================================
|
||||
// Screens
|
||||
// =====================================================================
|
||||
void DisplayManager::drawBootSplash(const ScreenState& s) {
|
||||
_tft.fillScreen(COL_BLACK);
|
||||
drawCentered("KLUBHAUS", 60, 4, COL_NEON_TEAL);
|
||||
drawCentered("ALERT", 110, 4, COL_HOT_FUCHSIA);
|
||||
drawCentered("v5.0 E32R35T", 180, 2, COL_DARK_GRAY);
|
||||
drawCentered("v5.1 E32R35T", 180, 2, COL_DARK_GRAY);
|
||||
if (s.debugMode) {
|
||||
drawCentered("DEBUG MODE", 210, 2, COL_YELLOW);
|
||||
}
|
||||
@@ -179,26 +262,25 @@ void DisplayManager::drawAlertScreen(const ScreenState& s) {
|
||||
drawCentered(s.alertMessage, (SCREEN_HEIGHT - 8 * sz) / 2, sz, fg);
|
||||
}
|
||||
|
||||
drawCentered("TAP TO SILENCE", SCREEN_HEIGHT - 25, 2, fg);
|
||||
// Only show hint text if not currently holding
|
||||
if (_holdProgress == 0.0f) {
|
||||
drawCentered("HOLD TO SILENCE", SCREEN_HEIGHT - 25, 2, fg);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::drawStatusScreen(const ScreenState& s) {
|
||||
_tft.fillScreen(COL_BLACK);
|
||||
drawHeaderBar(COL_MINT, "KLUBHAUS", s.timeString);
|
||||
|
||||
drawCentered("MONITORING", 60, 3, COL_WHITE);
|
||||
|
||||
char buf[80];
|
||||
int y = 110;
|
||||
int sp = 22;
|
||||
int x = 20;
|
||||
int y = 110, sp = 22, x = 20;
|
||||
|
||||
snprintf(buf, sizeof(buf), "WiFi: %s (%ddBm)",
|
||||
s.wifiConnected ? s.wifiSSID : "DOWN", s.wifiRSSI);
|
||||
drawInfoLine(x, y, COL_WHITE, buf); y += sp;
|
||||
|
||||
snprintf(buf, sizeof(buf), "IP: %s",
|
||||
s.wifiConnected ? s.wifiIP : "---");
|
||||
snprintf(buf, sizeof(buf), "IP: %s", s.wifiConnected ? s.wifiIP : "---");
|
||||
drawInfoLine(x, y, COL_WHITE, buf); y += sp;
|
||||
|
||||
snprintf(buf, sizeof(buf), "Up: %lu min Heap: %lu KB",
|
||||
@@ -222,66 +304,13 @@ void DisplayManager::drawStatusScreen(const ScreenState& s) {
|
||||
for (int i = 0; i < s.alertHistoryCount; i++) {
|
||||
uint16_t col = (i == 0) ? COL_YELLOW : COL_DARK_GRAY;
|
||||
snprintf(buf, sizeof(buf), "%s %.35s",
|
||||
s.alertHistory[i].timestamp,
|
||||
s.alertHistory[i].message);
|
||||
s.alertHistory[i].timestamp, s.alertHistory[i].message);
|
||||
drawInfoLine(x, y, col, buf); y += sp;
|
||||
}
|
||||
} else {
|
||||
drawInfoLine(x, y, COL_DARK_GRAY, "No alerts yet"); y += sp;
|
||||
}
|
||||
|
||||
if (s.debugMode) {
|
||||
drawInfoLine(x, y, COL_YELLOW, "DEBUG MODE - _test topics");
|
||||
}
|
||||
|
||||
drawCentered("tap to dismiss", SCREEN_HEIGHT - 18, 1, COL_DARK_GRAY);
|
||||
}
|
||||
|
||||
HoldState DisplayManager::updateHold(unsigned long requiredMs) {
|
||||
HoldState h;
|
||||
h.targetMs = requiredMs;
|
||||
|
||||
uint16_t tx, ty;
|
||||
bool touching = _tft.getTouch(&tx, &ty);
|
||||
|
||||
if (touching) {
|
||||
if (!_holdActive) {
|
||||
_holdActive = true;
|
||||
_holdStartMs = millis();
|
||||
_holdX = tx;
|
||||
_holdY = ty;
|
||||
}
|
||||
h.active = true;
|
||||
h.x = _holdX;
|
||||
h.y = _holdY;
|
||||
h.holdMs = millis() - _holdStartMs;
|
||||
|
||||
if (h.holdMs >= requiredMs) {
|
||||
h.completed = true;
|
||||
_holdActive = false;
|
||||
}
|
||||
} else {
|
||||
_holdActive = false;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
void DisplayManager::drawSilenceProgress(float progress) {
|
||||
int barY = SCREEN_HEIGHT - 30;
|
||||
int barH = 20;
|
||||
int barW = (int)(SCREEN_WIDTH * progress);
|
||||
|
||||
_tft.fillRect(0, barY, SCREEN_WIDTH, barH, COL_BLACK);
|
||||
_tft.fillRect(0, barY, barW, barH, COL_GREEN);
|
||||
_tft.drawRect(0, barY, SCREEN_WIDTH, barH, COL_WHITE);
|
||||
|
||||
_tft.setTextFont(1);
|
||||
_tft.setTextSize(2);
|
||||
_tft.setTextColor(progress < 1.0f ? COL_WHITE : COL_BLACK);
|
||||
_tft.setTextDatum(MC_DATUM);
|
||||
_tft.drawString(
|
||||
progress < 1.0f ? "HOLD TO SILENCE" : "SILENCED",
|
||||
SCREEN_WIDTH / 2, barY + barH / 2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user