This commit is contained in:
2026-02-16 03:07:23 -08:00
parent 3e62c7d481
commit 850275ee03
2 changed files with 81 additions and 10 deletions

View File

@@ -94,14 +94,16 @@ void DisplayManager::drawDashboard(const ScreenState& s) {
// ----- Helpers -----
void DisplayManager::drawCentered(const char* txt, int y, int sz, uint16_t col) {
_tft.setTextFont(1); // ← ADDED: force GLCD font
_tft.setTextSize(sz);
_tft.setTextColor(col);
int w = strlen(txt) * 6 * sz;
int w = _tft.textWidth(txt); // ← use TFT_eSPI's own width calc
_tft.setCursor(max(0, (SCREEN_WIDTH - w) / 2), y);
_tft.print(txt);
}
void DisplayManager::drawInfoLine(int x, int y, uint16_t col, const char* text) {
_tft.setTextFont(1); // ← ADDED
_tft.setTextSize(1);
_tft.setTextColor(col);
_tft.setCursor(x, y);
@@ -109,16 +111,16 @@ void DisplayManager::drawInfoLine(int x, int y, uint16_t col, const char* text)
}
void DisplayManager::drawHeaderBar(uint16_t col, const char* label, const char* timeStr) {
_tft.setTextFont(1); // ← ADDED
_tft.setTextSize(2);
_tft.setTextColor(col);
_tft.setCursor(8, 8);
_tft.print(label);
int tw = strlen(timeStr) * 12;
int tw = _tft.textWidth(timeStr); // ← proper width calc
_tft.setCursor(SCREEN_WIDTH - tw - 8, 8);
_tft.print(timeStr);
}
// ----- Screens -----
void DisplayManager::drawBootSplash(const ScreenState& s) {
@@ -235,3 +237,51 @@ void DisplayManager::drawStatusScreen(const ScreenState& s) {
drawCentered("tap to dismiss", SCREEN_HEIGHT - 18, 1, COL_DARK_GRAY);
}
HoldState DisplayManager::updateHold(unsigned long requiredMs) {
HoldState h;
h.targetMs = requiredMs;
uint16_t tx, ty;
bool touching = _tft.getTouch(&tx, &ty);
if (touching) {
if (!_holdActive) {
_holdActive = true;
_holdStartMs = millis();
_holdX = tx;
_holdY = ty;
}
h.active = true;
h.x = _holdX;
h.y = _holdY;
h.holdMs = millis() - _holdStartMs;
if (h.holdMs >= requiredMs) {
h.completed = true;
_holdActive = false;
}
} else {
_holdActive = false;
}
return h;
}
void DisplayManager::drawSilenceProgress(float progress) {
int barY = SCREEN_HEIGHT - 30;
int barH = 20;
int barW = (int)(SCREEN_WIDTH * progress);
_tft.fillRect(0, barY, SCREEN_WIDTH, barH, COL_BLACK);
_tft.fillRect(0, barY, barW, barH, COL_GREEN);
_tft.drawRect(0, barY, SCREEN_WIDTH, barH, COL_WHITE);
_tft.setTextFont(1);
_tft.setTextSize(2);
_tft.setTextColor(progress < 1.0f ? COL_WHITE : COL_BLACK);
_tft.setTextDatum(MC_DATUM);
_tft.drawString(
progress < 1.0f ? "HOLD TO SILENCE" : "SILENCED",
SCREEN_WIDTH / 2, barY + barH / 2);
}

View File

@@ -3,6 +3,16 @@
#include "ScreenData.h"
#include "Dashboard.h"
// Hold gesture result
struct HoldState {
bool active = false; // finger currently down
bool completed = false; // hold duration met
uint16_t x = 0;
uint16_t y = 0;
unsigned long holdMs = 0; // how long held so far
unsigned long targetMs = 0; // required hold duration
};
class DisplayManager {
public:
DisplayManager();
@@ -14,16 +24,27 @@ public:
// Dashboard tile touch — returns TileID or -1
int dashboardTouch(uint16_t x, uint16_t y);
private:
TFT_eSPI _tft;
Dashboard _dash;
// Hold detection — call each loop iteration
HoldState updateHold(unsigned long requiredMs);
ScreenID _lastScreen = ScreenID::BOOT_SPLASH;
bool _needsFullRedraw = true;
bool _lastBlink = false;
bool _dashSpriteReady = false;
// Draw hold-to-silence progress bar on alert screen
void drawSilenceProgress(float progress);
private:
TFT_eSPI _tft;
Dashboard _dash;
ScreenID _lastScreen = ScreenID::BOOT_SPLASH;
bool _needsFullRedraw = true;
bool _lastBlink = false;
bool _dashSpriteReady = false;
unsigned long _lastDashRefresh = 0;
// Hold tracking state
bool _holdActive = false;
unsigned long _holdStartMs = 0;
uint16_t _holdX = 0;
uint16_t _holdY = 0;
// Colors
static constexpr uint16_t COL_NEON_TEAL = 0x07D7;
static constexpr uint16_t COL_HOT_FUCHSIA = 0xF81F;