refactor: parameterize Dashboard for multi-target

- TFT_eSPI / TFT_eSprite -> Gfx / GfxSprite typedefs
- Hard-coded 480x320 -> SCREEN_WIDTH / SCREEN_HEIGHT from BoardConfig
- Top bar, WiFi bars, time position all scale to any resolution
- Zero behavioral change on E32R35T (Gfx = TFT_eSPI typedef)
This commit is contained in:
2026-02-16 12:38:14 -08:00
parent 259a26e79e
commit d0ab4a8da7
2 changed files with 63 additions and 61 deletions

View File

@@ -18,7 +18,7 @@ static const uint16_t tileFG[] = {
COL_WHITE, COL_WHITE, 0x0000, COL_WHITE, COL_WHITE, COL_WHITE
};
Dashboard::Dashboard(TFT_eSPI& tft)
Dashboard::Dashboard(Gfx& tft)
: _tft(tft), _sprite(&tft)
{
_tiles[TILE_LAST_ALERT] = { "!", "LAST ALERT", "none", "", 0, 0, true };
@@ -59,9 +59,9 @@ void Dashboard::drawTile(TileID id) {
int tx, ty;
tilePosition(id, tx, ty);
_sprite.fillSprite(COL_BG); // screen bg in corners
_sprite.fillRoundRect(0, 0, TILE_W, TILE_H, 8, t.bgColor); // rounded tile fill
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY); // border
_sprite.fillSprite(COL_BG);
_sprite.fillRoundRect(0, 0, TILE_W, TILE_H, 8, t.bgColor);
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY);
_sprite.setTextColor(t.fgColor, t.bgColor);
_sprite.setTextFont(4);
@@ -89,7 +89,7 @@ void Dashboard::drawTile(TileID id) {
}
void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
_tft.fillRect(0, 0, 480, DASH_TOP_BAR, COL_BAR);
_tft.fillRect(0, 0, SCREEN_WIDTH, DASH_TOP_BAR, COL_BAR);
_tft.setTextColor(COL_WHITE, COL_BAR);
_tft.setTextFont(4);
_tft.setTextSize(1);
@@ -98,7 +98,7 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
_tft.drawString("KLUBHAUS ALERT", DASH_MARGIN, DASH_TOP_BAR / 2);
_tft.setTextDatum(MR_DATUM);
_tft.drawString(time, 470, DASH_TOP_BAR / 2);
_tft.drawString(time, SCREEN_WIDTH - 10, DASH_TOP_BAR / 2);
int bars = 0;
if (wifiOk) {
@@ -107,7 +107,7 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
else if (rssi > -70) bars = 2;
else bars = 1;
}
int barX = 370, barW = 6, barGap = 3;
int barX = SCREEN_WIDTH - 110, barW = 6, barGap = 3;
for (int i = 0; i < 4; i++) {
int barH = 6 + i * 5;
int barY = DASH_TOP_BAR - 8 - barH;
@@ -126,8 +126,12 @@ void Dashboard::updateTile(TileID id, const char* value, const char* sub) {
if (sub && strcmp(t.sub, sub) != 0) changed = true;
if (!changed && !t.dirty) return;
strncpy(t.value, value, 31); t.value[31] = '\0';
if (sub) { strncpy(t.sub, sub, 31); t.sub[31] = '\0'; }
strncpy(t.value, value, 31);
t.value[31] = '\0';
if (sub) {
strncpy(t.sub, sub, 31);
t.sub[31] = '\0';
}
t.dirty = true;
drawTile(id);
}
@@ -136,23 +140,21 @@ int Dashboard::handleTouch(int x, int y) {
for (int i = 0; i < TILE_COUNT; i++) {
int tx, ty;
tilePosition((TileID)i, tx, ty);
if (x >= tx && x < tx + TILE_W && y >= ty && y < ty + TILE_H)
return i;
if (x >= tx && x < tx + TILE_W && y >= ty && y < ty + TILE_H) return i;
}
return -1;
}
void Dashboard::refreshFromState(const ScreenState& state) {
bool barChanged = (strcmp(_barTime, state.timeString) != 0) ||
(_barRSSI != state.wifiRSSI) ||
(_barWifiOk != state.wifiConnected);
bool barChanged = (strcmp(_barTime, state.timeString) != 0)
|| (_barRSSI != state.wifiRSSI)
|| (_barWifiOk != state.wifiConnected);
if (barChanged) {
drawTopBar(state.timeString, state.wifiRSSI, state.wifiConnected);
}
if (state.alertHistoryCount > 0) {
updateTile(TILE_LAST_ALERT,
state.alertHistory[0].message,
updateTile(TILE_LAST_ALERT, state.alertHistory[0].message,
state.alertHistory[0].timestamp);
} else {
updateTile(TILE_LAST_ALERT, "none", "");
@@ -192,4 +194,3 @@ void Dashboard::refreshFromState(const ScreenState& state) {
snprintf(uptimeBuf, sizeof(uptimeBuf), "up %lum", state.uptimeMinutes);
updateTile(TILE_SYSTEM, heapBuf, uptimeBuf);
}

View File

@@ -1,13 +1,15 @@
#pragma once
#include <TFT_eSPI.h>
#include "DisplayDriver.h"
#include "ScreenData.h"
#define DASH_COLS 3
#define DASH_ROWS 2
#define DASH_MARGIN 8
#define DASH_TOP_BAR 40
#define TILE_W ((480 - (DASH_COLS + 1) * DASH_MARGIN) / DASH_COLS)
#define TILE_H ((320 - DASH_TOP_BAR - (DASH_ROWS + 1) * DASH_MARGIN) / DASH_ROWS)
#define TILE_W ((SCREEN_WIDTH - (DASH_COLS + 1) * DASH_MARGIN) / DASH_COLS)
#define TILE_H ((SCREEN_HEIGHT - DASH_TOP_BAR - (DASH_ROWS + 1) * DASH_MARGIN) / DASH_ROWS)
enum TileID : uint8_t {
TILE_LAST_ALERT = 0,
@@ -31,7 +33,7 @@ struct TileData {
class Dashboard {
public:
Dashboard(TFT_eSPI& tft);
Dashboard(Gfx& tft);
void begin();
void drawAll();
@@ -41,8 +43,8 @@ public:
void refreshFromState(const ScreenState& state);
private:
TFT_eSPI& _tft;
TFT_eSprite _sprite;
Gfx& _tft;
GfxSprite _sprite;
TileData _tiles[TILE_COUNT];
char _barTime[12] = "";
@@ -52,4 +54,3 @@ private:
void drawTile(TileID id);
void tilePosition(TileID id, int& x, int& y);
};