120 lines
3.2 KiB
C
120 lines
3.2 KiB
C
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
enum class DeviceState { BOOTED, SILENT, ALERTING, SILENCED };
|
|
|
|
enum class ScreenID { BOOT, OFF, ALERT, DASHBOARD, STATUS };
|
|
|
|
enum class BootStage { SPLASH, INIT_DISPLAY, INIT_NETWORK, CONNECTING_WIFI, READY, DONE };
|
|
|
|
/// Dashboard tile action handlers
|
|
enum class TileAction {
|
|
NONE,
|
|
ALERT, // Trigger alert
|
|
SILENCE, // Silence alert
|
|
DISMISS, // Dismiss alert and return to dashboard
|
|
STATUS, // Send heartbeat/status
|
|
REBOOT, // Reboot device
|
|
};
|
|
|
|
/// Dashboard tile layout constraints for flexible grid
|
|
struct TileConstraint {
|
|
uint8_t minCols = 1; // minimum columns this tile needs
|
|
uint8_t minRows = 1; // minimum rows this tile needs
|
|
uint8_t weight = 1; // priority for growing/shrinking (higher = more flexible)
|
|
};
|
|
|
|
/// Computed tile position in the grid
|
|
struct TileLayout {
|
|
int x, y; // pixel position
|
|
int w, h; // pixel size
|
|
int col, row; // grid position
|
|
int cols, rows; // grid span
|
|
};
|
|
|
|
/// Dashboard tile definitions — shared across all boards
|
|
struct DashboardTile {
|
|
const char* label;
|
|
uint16_t bgColor; // RGB565
|
|
TileAction action;
|
|
TileConstraint constraint;
|
|
};
|
|
|
|
/// Standard dashboard tiles (auto-gridded based on count and constraints)
|
|
static constexpr DashboardTile DASHBOARD_TILES[] = {
|
|
{ "Alert", 0x0280, TileAction::ALERT, { 1, 1, 1 } },
|
|
{ "Silent", 0x0400, TileAction::SILENCE, { 1, 1, 1 } },
|
|
{ "Status", 0x0440, TileAction::STATUS, { 1, 1, 1 } },
|
|
{ "Reboot", 0x0100, TileAction::REBOOT, { 1, 1, 1 } },
|
|
};
|
|
static constexpr int DASHBOARD_TILE_COUNT = sizeof(DASHBOARD_TILES) / sizeof(DASHBOARD_TILES[0]);
|
|
|
|
struct ScreenState {
|
|
DeviceState deviceState = DeviceState::BOOTED;
|
|
ScreenID screen = ScreenID::BOOT;
|
|
BootStage bootStage = BootStage::SPLASH;
|
|
|
|
String alertTitle;
|
|
String alertBody;
|
|
uint32_t alertStartMs = 0;
|
|
uint32_t silenceStartMs = 0;
|
|
|
|
bool backlightOn = false;
|
|
int wifiRssi = 0;
|
|
String wifiSsid;
|
|
String ipAddr;
|
|
uint32_t uptimeMs = 0;
|
|
uint32_t lastPollMs = 0;
|
|
uint32_t lastHeartbeatMs = 0;
|
|
|
|
bool showDashboard = false;
|
|
};
|
|
|
|
inline const char* deviceStateStr(DeviceState s) {
|
|
switch(s) {
|
|
case DeviceState::BOOTED:
|
|
return "BOOTED";
|
|
case DeviceState::SILENT:
|
|
return "SILENT";
|
|
case DeviceState::ALERTING:
|
|
return "ALERTING";
|
|
case DeviceState::SILENCED:
|
|
return "SILENCED";
|
|
}
|
|
return "?";
|
|
}
|
|
|
|
inline const char* screenIdStr(ScreenID s) {
|
|
switch(s) {
|
|
case ScreenID::BOOT:
|
|
return "BOOT";
|
|
case ScreenID::OFF:
|
|
return "OFF";
|
|
case ScreenID::ALERT:
|
|
return "ALERT";
|
|
case ScreenID::DASHBOARD:
|
|
return "DASHBOARD";
|
|
case ScreenID::STATUS:
|
|
return "STATUS";
|
|
}
|
|
return "?";
|
|
}
|
|
|
|
inline const char* bootStageStr(BootStage s) {
|
|
switch(s) {
|
|
case BootStage::SPLASH:
|
|
return "SPLASH";
|
|
case BootStage::INIT_DISPLAY:
|
|
return "INIT_DISPLAY";
|
|
case BootStage::INIT_NETWORK:
|
|
return "INIT_NETWORK";
|
|
case BootStage::CONNECTING_WIFI:
|
|
return "CONNECTING_WIFI";
|
|
case BootStage::READY:
|
|
return "READY";
|
|
case BootStage::DONE:
|
|
return "DONE";
|
|
}
|
|
return "?";
|
|
}
|