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:
@@ -18,7 +18,7 @@ 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 };
|
||||||
@@ -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,7 +98,7 @@ 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) {
|
||||||
@@ -107,7 +107,7 @@ void Dashboard::drawTopBar(const char* time, int rssi, bool wifiOk) {
|
|||||||
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,23 +140,21 @@ 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", "");
|
||||||
@@ -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,
|
||||||
@@ -31,7 +33,7 @@ struct TileData {
|
|||||||
|
|
||||||
class Dashboard {
|
class Dashboard {
|
||||||
public:
|
public:
|
||||||
Dashboard(TFT_eSPI& tft);
|
Dashboard(Gfx& tft);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void drawAll();
|
void drawAll();
|
||||||
@@ -41,8 +43,8 @@ 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] = "";
|
||||||
@@ -52,4 +54,3 @@ private:
|
|||||||
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