snapshot
This commit is contained in:
@@ -1,29 +1,19 @@
|
||||
#include "Dashboard.h"
|
||||
|
||||
// 16-bit color helpers
|
||||
#define COL_BG 0x1082 // dark charcoal
|
||||
#define COL_BAR 0x2104 // slightly lighter
|
||||
#define COL_BG 0x1082
|
||||
#define COL_BAR 0x2104
|
||||
#define COL_RED 0xF800
|
||||
#define COL_ORANGE 0xFBE0
|
||||
#define COL_GREEN 0x07E0
|
||||
#define COL_CYAN 0x07FF
|
||||
#define COL_BLUE 0x001F
|
||||
#define COL_PURPLE 0x780F
|
||||
#define COL_YELLOW 0xFFE0
|
||||
#define COL_WHITE 0xFFFF
|
||||
#define COL_GRAY 0x8410
|
||||
#define COL_DARK_TILE 0x18E3
|
||||
|
||||
// Tile color themes
|
||||
static const uint16_t tileBG[] = {
|
||||
COL_RED, // LAST_ALERT
|
||||
COL_ORANGE, // STATS
|
||||
COL_CYAN, // NETWORK
|
||||
COL_PURPLE, // MUTE
|
||||
COL_DARK_TILE, // HISTORY
|
||||
COL_DARK_TILE // SYSTEM
|
||||
COL_RED, COL_ORANGE, COL_CYAN, COL_PURPLE, COL_DARK_TILE, COL_DARK_TILE
|
||||
};
|
||||
|
||||
static const uint16_t tileFG[] = {
|
||||
COL_WHITE, COL_WHITE, 0x0000, COL_WHITE, COL_WHITE, COL_WHITE
|
||||
};
|
||||
@@ -31,12 +21,12 @@ static const uint16_t tileFG[] = {
|
||||
Dashboard::Dashboard(TFT_eSPI& tft)
|
||||
: _tft(tft), _sprite(&tft)
|
||||
{
|
||||
_tiles[TILE_LAST_ALERT] = { "!", "LAST ALERT", "none", "", 0, 0, true };
|
||||
_tiles[TILE_STATS] = { "#", "TODAY", "0 alerts", "", 0, 0, true };
|
||||
_tiles[TILE_NETWORK] = { "~", "NETWORK", "---", "", 0, 0, true };
|
||||
_tiles[TILE_MUTE] = { "M", "MUTE", "OFF", "", 0, 0, true };
|
||||
_tiles[TILE_HISTORY] = { ">", "HISTORY", "tap to view","", 0, 0, true };
|
||||
_tiles[TILE_SYSTEM] = { "*", "SYSTEM", "---", "", 0, 0, true };
|
||||
_tiles[TILE_LAST_ALERT] = { "!", "LAST ALERT", "none", "", 0, 0, true };
|
||||
_tiles[TILE_STATS] = { "#", "TODAY", "0 alerts", "", 0, 0, true };
|
||||
_tiles[TILE_NETWORK] = { "~", "NETWORK", "---", "", 0, 0, true };
|
||||
_tiles[TILE_MUTE] = { "M", "MUTE", "OFF", "", 0, 0, true };
|
||||
_tiles[TILE_HISTORY] = { ">", "HISTORY", "tap to view", "", 0, 0, true };
|
||||
_tiles[TILE_SYSTEM] = { "*", "SYSTEM", "---", "", 0, 0, true };
|
||||
|
||||
for (int i = 0; i < TILE_COUNT; i++) {
|
||||
_tiles[i].bgColor = tileBG[i];
|
||||
@@ -72,25 +62,21 @@ void Dashboard::drawTile(TileID id) {
|
||||
_sprite.fillSprite(t.bgColor);
|
||||
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY);
|
||||
|
||||
// Icon — large character at top
|
||||
_sprite.setTextColor(t.fgColor, t.bgColor);
|
||||
_sprite.setTextFont(4);
|
||||
_sprite.setTextSize(2);
|
||||
_sprite.setTextDatum(TC_DATUM);
|
||||
_sprite.drawString(t.icon, TILE_W / 2, 8);
|
||||
|
||||
// Label
|
||||
_sprite.setTextSize(1);
|
||||
_sprite.setTextFont(2);
|
||||
_sprite.setTextDatum(MC_DATUM);
|
||||
_sprite.drawString(t.label, TILE_W / 2, TILE_H / 2 + 5);
|
||||
|
||||
// Value
|
||||
_sprite.setTextFont(2);
|
||||
_sprite.setTextDatum(BC_DATUM);
|
||||
_sprite.drawString(t.value, TILE_W / 2, TILE_H - 25);
|
||||
|
||||
// Sub text
|
||||
if (strlen(t.sub) > 0) {
|
||||
_sprite.setTextFont(1);
|
||||
_sprite.setTextDatum(BC_DATUM);
|
||||
@@ -103,7 +89,6 @@ 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.setTextColor(COL_WHITE, COL_BAR);
|
||||
_tft.setTextFont(4);
|
||||
_tft.setTextSize(1);
|
||||
@@ -114,7 +99,6 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
|
||||
_tft.setTextDatum(MR_DATUM);
|
||||
_tft.drawString(time, 470, DASH_TOP_BAR / 2);
|
||||
|
||||
// WiFi signal bars
|
||||
int bars = 0;
|
||||
if (wifiOk) {
|
||||
if (rssi > -50) bars = 4;
|
||||
@@ -122,7 +106,6 @@ 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;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int barH = 6 + i * 5;
|
||||
@@ -131,26 +114,19 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
|
||||
_tft.fillRect(barX + i * (barW + barGap), barY, barW, barH, col);
|
||||
}
|
||||
|
||||
// Cache values
|
||||
strncpy(_barTime, time, sizeof(_barTime) - 1);
|
||||
_barRSSI = rssi;
|
||||
_barRSSI = rssi;
|
||||
_barWifiOk = wifiOk;
|
||||
}
|
||||
|
||||
void Dashboard::updateTile(TileID id, const char* value, const char* sub) {
|
||||
TileData& t = _tiles[id];
|
||||
|
||||
// Dirty check — skip redraw if nothing changed
|
||||
bool changed = (strcmp(t.value, value) != 0);
|
||||
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);
|
||||
}
|
||||
@@ -159,19 +135,13 @@ 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) {
|
||||
if (x >= tx && x < tx + TILE_W && y >= ty && y < ty + TILE_H)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Refresh all tiles from ScreenState — only redraws changed tiles
|
||||
// =====================================================================
|
||||
void Dashboard::refreshFromState(const ScreenState& state) {
|
||||
// Top bar — only redraw if changed
|
||||
bool barChanged = (strcmp(_barTime, state.timeString) != 0) ||
|
||||
(_barRSSI != state.wifiRSSI) ||
|
||||
(_barWifiOk != state.wifiConnected);
|
||||
@@ -179,7 +149,6 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
||||
drawTopBar(state.timeString, state.wifiRSSI, state.wifiConnected);
|
||||
}
|
||||
|
||||
// LAST ALERT tile
|
||||
if (state.alertHistoryCount > 0) {
|
||||
updateTile(TILE_LAST_ALERT,
|
||||
state.alertHistory[0].message,
|
||||
@@ -188,14 +157,12 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
||||
updateTile(TILE_LAST_ALERT, "none", "");
|
||||
}
|
||||
|
||||
// STATS tile
|
||||
char statsBuf[32];
|
||||
snprintf(statsBuf, sizeof(statsBuf), "%d alert%s",
|
||||
state.alertHistoryCount,
|
||||
state.alertHistoryCount == 1 ? "" : "s");
|
||||
updateTile(TILE_STATS, statsBuf, "this session");
|
||||
|
||||
// NETWORK tile
|
||||
if (state.wifiConnected) {
|
||||
char rssiBuf[16];
|
||||
snprintf(rssiBuf, sizeof(rssiBuf), "%d dBm", state.wifiRSSI);
|
||||
@@ -204,10 +171,8 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
||||
updateTile(TILE_NETWORK, "DOWN", "reconnecting...");
|
||||
}
|
||||
|
||||
// MUTE tile (placeholder)
|
||||
updateTile(TILE_MUTE, "OFF", "tap to mute");
|
||||
|
||||
// HISTORY tile — show 2nd and 3rd alerts
|
||||
if (state.alertHistoryCount > 1) {
|
||||
char histBuf[48];
|
||||
snprintf(histBuf, sizeof(histBuf), "%s %.20s",
|
||||
@@ -220,7 +185,6 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
||||
updateTile(TILE_HISTORY, "no history", "");
|
||||
}
|
||||
|
||||
// SYSTEM tile
|
||||
char heapBuf[16];
|
||||
snprintf(heapBuf, sizeof(heapBuf), "%lu KB", state.freeHeapKB);
|
||||
char uptimeBuf[20];
|
||||
|
||||
Reference in New Issue
Block a user