refactor(DisplayDriverTFT): simplify alert rendering logic for better performance
This commit is contained in:
@@ -193,22 +193,32 @@ void DisplayDriverTFT::drawBoot(const ScreenState& st) {
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::drawAlert(const ScreenState& st) {
|
||||
// Throttle redraws to ~24fps to prevent tearing
|
||||
uint32_t now = millis();
|
||||
if(now - _lastAlertDrawMs < ALERT_DRAW_INTERVAL_MS) {
|
||||
return;
|
||||
}
|
||||
_lastAlertDrawMs = now;
|
||||
|
||||
// Static 2-color pulse - alternate every ~2 seconds
|
||||
uint32_t elapsed = millis() - st.alertStartMs;
|
||||
// Slower pulse - divide by 1500 for ~9.4 second cycle (was 300 for ~1.9s)
|
||||
uint8_t pulse = 180 + (uint8_t)(75.0f * sinf(elapsed / 1500.0f));
|
||||
uint16_t bg = _tft.color565(pulse, 0, 0);
|
||||
bool brightPhase = (elapsed / 2000) % 2 == 0;
|
||||
|
||||
// Only redraw when phase changes (timer-based, not every frame)
|
||||
if(brightPhase != _lastAlertPhase) {
|
||||
_lastAlertPhase = brightPhase;
|
||||
uint16_t bg = brightPhase ? TFT_RED : _tft.color565(180, 0, 0);
|
||||
|
||||
_tft.fillScreen(bg);
|
||||
_tft.setTextColor(TFT_WHITE, bg);
|
||||
|
||||
// Progressive fill hint - draws dark overlay from bottom rising up
|
||||
setTitleFont();
|
||||
_tft.setCursor(10, 28);
|
||||
_tft.print(st.alertTitle.length() > 0 ? st.alertTitle : "ALERT");
|
||||
|
||||
setBodyFont();
|
||||
_tft.setCursor(10, 70);
|
||||
_tft.print(st.alertBody);
|
||||
|
||||
setLabelFont();
|
||||
_tft.setCursor(10, _tft.height() - 10);
|
||||
_tft.print("Hold to silence...");
|
||||
}
|
||||
|
||||
// Progressive fill hint - only redraw when touch state changes
|
||||
if(_alertTouchDown) {
|
||||
uint32_t touchElapsed = millis() - _alertTouchStartMs;
|
||||
float progress = (float)touchElapsed / (float)ALERT_FILL_DURATION_MS;
|
||||
@@ -218,23 +228,10 @@ void DisplayDriverTFT::drawAlert(const ScreenState& st) {
|
||||
int dispH = _tft.height();
|
||||
int fillHeight = (int)(dispH * progress);
|
||||
if(fillHeight > 0) {
|
||||
// Draw dark overlay from bottom
|
||||
uint16_t overlay = _tft.color565(80, 0, 0); // Dark red
|
||||
uint16_t overlay = _tft.color565(80, 0, 0);
|
||||
_tft.fillRect(0, dispH - fillHeight, _tft.width(), fillHeight, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
setTitleFont();
|
||||
_tft.setCursor(10, 28); // y=28 baseline for ~18px font
|
||||
_tft.print(st.alertTitle.length() > 0 ? st.alertTitle : "ALERT");
|
||||
|
||||
setBodyFont();
|
||||
_tft.setCursor(10, 70); // y adjusted for ~12px body font
|
||||
_tft.print(st.alertBody);
|
||||
|
||||
setLabelFont();
|
||||
_tft.setCursor(10, _tft.height() - 10); // y adjusted for ~9px label font
|
||||
_tft.print("Hold to silence...");
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
|
||||
|
||||
@@ -44,9 +44,8 @@ private:
|
||||
// Touch hint for alert - progressive fill from bottom
|
||||
bool _alertTouchDown = false;
|
||||
uint32_t _alertTouchStartMs = 0;
|
||||
uint32_t _lastAlertDrawMs = 0;
|
||||
bool _lastAlertPhase = false; // tracks bright/dark phase for 2-color alert
|
||||
static constexpr uint32_t ALERT_FILL_DURATION_MS = 3000;
|
||||
static constexpr uint32_t ALERT_DRAW_INTERVAL_MS = 333; // ~3fps
|
||||
|
||||
// Touch tracking for press/release detection
|
||||
bool _touchWasPressed = false;
|
||||
|
||||
Reference in New Issue
Block a user