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:
@@ -1,15 +1,15 @@
|
|||||||
#include "Dashboard.h"
|
#include "Dashboard.h"
|
||||||
|
|
||||||
#define COL_BG 0x1082
|
#define COL_BG 0x1082
|
||||||
#define COL_BAR 0x2104
|
#define COL_BAR 0x2104
|
||||||
#define COL_RED 0xF800
|
#define COL_RED 0xF800
|
||||||
#define COL_ORANGE 0xFBE0
|
#define COL_ORANGE 0xFBE0
|
||||||
#define COL_GREEN 0x07E0
|
#define COL_GREEN 0x07E0
|
||||||
#define COL_CYAN 0x07FF
|
#define COL_CYAN 0x07FF
|
||||||
#define COL_PURPLE 0x780F
|
#define COL_PURPLE 0x780F
|
||||||
#define COL_WHITE 0xFFFF
|
#define COL_WHITE 0xFFFF
|
||||||
#define COL_GRAY 0x8410
|
#define COL_GRAY 0x8410
|
||||||
#define COL_DARK_TILE 0x18E3
|
#define COL_DARK_TILE 0x18E3
|
||||||
|
|
||||||
static const uint16_t tileBG[] = {
|
static const uint16_t tileBG[] = {
|
||||||
COL_RED, COL_ORANGE, COL_CYAN, COL_PURPLE, COL_DARK_TILE, COL_DARK_TILE
|
COL_RED, COL_ORANGE, COL_CYAN, COL_PURPLE, COL_DARK_TILE, COL_DARK_TILE
|
||||||
@@ -18,15 +18,15 @@ static const uint16_t tileFG[] = {
|
|||||||
COL_WHITE, COL_WHITE, 0x0000, COL_WHITE, COL_WHITE, COL_WHITE
|
COL_WHITE, COL_WHITE, 0x0000, COL_WHITE, COL_WHITE, COL_WHITE
|
||||||
};
|
};
|
||||||
|
|
||||||
Dashboard::Dashboard(TFT_eSPI& tft)
|
Dashboard::Dashboard(Gfx& tft)
|
||||||
: _tft(tft), _sprite(&tft)
|
: _tft(tft), _sprite(&tft)
|
||||||
{
|
{
|
||||||
_tiles[TILE_LAST_ALERT] = { "!", "LAST ALERT", "none", "", 0, 0, true };
|
_tiles[TILE_LAST_ALERT] = { "!", "LAST ALERT", "none", "", 0, 0, true };
|
||||||
_tiles[TILE_STATS] = { "#", "TODAY", "0 alerts", "", 0, 0, true };
|
_tiles[TILE_STATS] = { "#", "TODAY", "0 alerts", "", 0, 0, true };
|
||||||
_tiles[TILE_NETWORK] = { "~", "NETWORK", "---", "", 0, 0, true };
|
_tiles[TILE_NETWORK] = { "~", "NETWORK", "---", "", 0, 0, true };
|
||||||
_tiles[TILE_MUTE] = { "M", "MUTE", "OFF", "", 0, 0, true };
|
_tiles[TILE_MUTE] = { "M", "MUTE", "OFF", "", 0, 0, true };
|
||||||
_tiles[TILE_HISTORY] = { ">", "HISTORY", "tap to view", "", 0, 0, true };
|
_tiles[TILE_HISTORY] = { ">", "HISTORY", "tap to view", "", 0, 0, true };
|
||||||
_tiles[TILE_SYSTEM] = { "*", "SYSTEM", "---", "", 0, 0, true };
|
_tiles[TILE_SYSTEM] = { "*", "SYSTEM", "---", "", 0, 0, true };
|
||||||
|
|
||||||
for (int i = 0; i < TILE_COUNT; i++) {
|
for (int i = 0; i < TILE_COUNT; i++) {
|
||||||
_tiles[i].bgColor = tileBG[i];
|
_tiles[i].bgColor = tileBG[i];
|
||||||
@@ -59,9 +59,9 @@ void Dashboard::drawTile(TileID id) {
|
|||||||
int tx, ty;
|
int tx, ty;
|
||||||
tilePosition(id, tx, ty);
|
tilePosition(id, tx, ty);
|
||||||
|
|
||||||
_sprite.fillSprite(COL_BG); // screen bg in corners
|
_sprite.fillSprite(COL_BG);
|
||||||
_sprite.fillRoundRect(0, 0, TILE_W, TILE_H, 8, t.bgColor); // rounded tile fill
|
_sprite.fillRoundRect(0, 0, TILE_W, TILE_H, 8, t.bgColor);
|
||||||
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY); // border
|
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY);
|
||||||
|
|
||||||
_sprite.setTextColor(t.fgColor, t.bgColor);
|
_sprite.setTextColor(t.fgColor, t.bgColor);
|
||||||
_sprite.setTextFont(4);
|
_sprite.setTextFont(4);
|
||||||
@@ -89,7 +89,7 @@ void Dashboard::drawTile(TileID id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
|
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.setTextColor(COL_WHITE, COL_BAR);
|
||||||
_tft.setTextFont(4);
|
_tft.setTextFont(4);
|
||||||
_tft.setTextSize(1);
|
_tft.setTextSize(1);
|
||||||
@@ -98,16 +98,16 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
|
|||||||
_tft.drawString("KLUBHAUS ALERT", DASH_MARGIN, DASH_TOP_BAR / 2);
|
_tft.drawString("KLUBHAUS ALERT", DASH_MARGIN, DASH_TOP_BAR / 2);
|
||||||
|
|
||||||
_tft.setTextDatum(MR_DATUM);
|
_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;
|
int bars = 0;
|
||||||
if (wifiOk) {
|
if (wifiOk) {
|
||||||
if (rssi > -50) bars = 4;
|
if (rssi > -50) bars = 4;
|
||||||
else if (rssi > -60) bars = 3;
|
else if (rssi > -60) bars = 3;
|
||||||
else if (rssi > -70) bars = 2;
|
else if (rssi > -70) bars = 2;
|
||||||
else bars = 1;
|
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++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int barH = 6 + i * 5;
|
int barH = 6 + i * 5;
|
||||||
int barY = DASH_TOP_BAR - 8 - barH;
|
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 (sub && strcmp(t.sub, sub) != 0) changed = true;
|
||||||
if (!changed && !t.dirty) return;
|
if (!changed && !t.dirty) return;
|
||||||
|
|
||||||
strncpy(t.value, value, 31); t.value[31] = '\0';
|
strncpy(t.value, value, 31);
|
||||||
if (sub) { strncpy(t.sub, sub, 31); t.sub[31] = '\0'; }
|
t.value[31] = '\0';
|
||||||
|
if (sub) {
|
||||||
|
strncpy(t.sub, sub, 31);
|
||||||
|
t.sub[31] = '\0';
|
||||||
|
}
|
||||||
t.dirty = true;
|
t.dirty = true;
|
||||||
drawTile(id);
|
drawTile(id);
|
||||||
}
|
}
|
||||||
@@ -136,32 +140,30 @@ int Dashboard::handleTouch(int x, int y) {
|
|||||||
for (int i = 0; i < TILE_COUNT; i++) {
|
for (int i = 0; i < TILE_COUNT; i++) {
|
||||||
int tx, ty;
|
int tx, ty;
|
||||||
tilePosition((TileID)i, 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 i;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dashboard::refreshFromState(const ScreenState& state) {
|
void Dashboard::refreshFromState(const ScreenState& state) {
|
||||||
bool barChanged = (strcmp(_barTime, state.timeString) != 0) ||
|
bool barChanged = (strcmp(_barTime, state.timeString) != 0)
|
||||||
(_barRSSI != state.wifiRSSI) ||
|
|| (_barRSSI != state.wifiRSSI)
|
||||||
(_barWifiOk != state.wifiConnected);
|
|| (_barWifiOk != state.wifiConnected);
|
||||||
if (barChanged) {
|
if (barChanged) {
|
||||||
drawTopBar(state.timeString, state.wifiRSSI, state.wifiConnected);
|
drawTopBar(state.timeString, state.wifiRSSI, state.wifiConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.alertHistoryCount > 0) {
|
if (state.alertHistoryCount > 0) {
|
||||||
updateTile(TILE_LAST_ALERT,
|
updateTile(TILE_LAST_ALERT, state.alertHistory[0].message,
|
||||||
state.alertHistory[0].message,
|
state.alertHistory[0].timestamp);
|
||||||
state.alertHistory[0].timestamp);
|
|
||||||
} else {
|
} else {
|
||||||
updateTile(TILE_LAST_ALERT, "none", "");
|
updateTile(TILE_LAST_ALERT, "none", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
char statsBuf[32];
|
char statsBuf[32];
|
||||||
snprintf(statsBuf, sizeof(statsBuf), "%d alert%s",
|
snprintf(statsBuf, sizeof(statsBuf), "%d alert%s",
|
||||||
state.alertHistoryCount,
|
state.alertHistoryCount,
|
||||||
state.alertHistoryCount == 1 ? "" : "s");
|
state.alertHistoryCount == 1 ? "" : "s");
|
||||||
updateTile(TILE_STATS, statsBuf, "this session");
|
updateTile(TILE_STATS, statsBuf, "this session");
|
||||||
|
|
||||||
if (state.wifiConnected) {
|
if (state.wifiConnected) {
|
||||||
@@ -177,10 +179,10 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
|||||||
if (state.alertHistoryCount > 1) {
|
if (state.alertHistoryCount > 1) {
|
||||||
char histBuf[48];
|
char histBuf[48];
|
||||||
snprintf(histBuf, sizeof(histBuf), "%s %.20s",
|
snprintf(histBuf, sizeof(histBuf), "%s %.20s",
|
||||||
state.alertHistory[1].timestamp,
|
state.alertHistory[1].timestamp,
|
||||||
state.alertHistory[1].message);
|
state.alertHistory[1].message);
|
||||||
const char* sub = (state.alertHistoryCount > 2)
|
const char* sub = (state.alertHistoryCount > 2)
|
||||||
? state.alertHistory[2].message : "";
|
? state.alertHistory[2].message : "";
|
||||||
updateTile(TILE_HISTORY, histBuf, sub);
|
updateTile(TILE_HISTORY, histBuf, sub);
|
||||||
} else {
|
} else {
|
||||||
updateTile(TILE_HISTORY, "no history", "");
|
updateTile(TILE_HISTORY, "no history", "");
|
||||||
@@ -192,4 +194,3 @@ void Dashboard::refreshFromState(const ScreenState& state) {
|
|||||||
snprintf(uptimeBuf, sizeof(uptimeBuf), "up %lum", state.uptimeMinutes);
|
snprintf(uptimeBuf, sizeof(uptimeBuf), "up %lum", state.uptimeMinutes);
|
||||||
updateTile(TILE_SYSTEM, heapBuf, uptimeBuf);
|
updateTile(TILE_SYSTEM, heapBuf, uptimeBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <TFT_eSPI.h>
|
|
||||||
|
#include "DisplayDriver.h"
|
||||||
#include "ScreenData.h"
|
#include "ScreenData.h"
|
||||||
|
|
||||||
#define DASH_COLS 3
|
#define DASH_COLS 3
|
||||||
#define DASH_ROWS 2
|
#define DASH_ROWS 2
|
||||||
#define DASH_MARGIN 8
|
#define DASH_MARGIN 8
|
||||||
#define DASH_TOP_BAR 40
|
#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 {
|
enum TileID : uint8_t {
|
||||||
TILE_LAST_ALERT = 0,
|
TILE_LAST_ALERT = 0,
|
||||||
@@ -22,16 +24,16 @@ enum TileID : uint8_t {
|
|||||||
struct TileData {
|
struct TileData {
|
||||||
const char* icon;
|
const char* icon;
|
||||||
const char* label;
|
const char* label;
|
||||||
char value[32];
|
char value[32];
|
||||||
char sub[32];
|
char sub[32];
|
||||||
uint16_t bgColor;
|
uint16_t bgColor;
|
||||||
uint16_t fgColor;
|
uint16_t fgColor;
|
||||||
bool dirty;
|
bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Dashboard {
|
class Dashboard {
|
||||||
public:
|
public:
|
||||||
Dashboard(TFT_eSPI& tft);
|
Dashboard(Gfx& tft);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void drawAll();
|
void drawAll();
|
||||||
@@ -41,15 +43,14 @@ public:
|
|||||||
void refreshFromState(const ScreenState& state);
|
void refreshFromState(const ScreenState& state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TFT_eSPI& _tft;
|
Gfx& _tft;
|
||||||
TFT_eSprite _sprite;
|
GfxSprite _sprite;
|
||||||
TileData _tiles[TILE_COUNT];
|
TileData _tiles[TILE_COUNT];
|
||||||
|
|
||||||
char _barTime[12] = "";
|
char _barTime[12] = "";
|
||||||
int _barRSSI = 0;
|
int _barRSSI = 0;
|
||||||
bool _barWifiOk = false;
|
bool _barWifiOk = false;
|
||||||
|
|
||||||
void drawTile(TileID id);
|
void drawTile(TileID id);
|
||||||
void tilePosition(TileID id, int& x, int& y);
|
void tilePosition(TileID id, int& x, int& y);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user