From b68d36bb851840686a88d46bd9f6ff8435493325 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Fri, 20 Feb 2026 02:41:04 -0800 Subject: [PATCH] perf(DisplayDriverTFT): Throttle alert redraws to prevent tearing --- boards/esp32-32e-4/DisplayDriverTFT.cpp | 10 +++++++++- boards/esp32-32e-4/DisplayDriverTFT.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/boards/esp32-32e-4/DisplayDriverTFT.cpp b/boards/esp32-32e-4/DisplayDriverTFT.cpp index cc6f521..726615a 100644 --- a/boards/esp32-32e-4/DisplayDriverTFT.cpp +++ b/boards/esp32-32e-4/DisplayDriverTFT.cpp @@ -193,8 +193,16 @@ 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; + uint32_t elapsed = millis() - st.alertStartMs; - uint8_t pulse = 180 + (uint8_t)(75.0f * sinf(elapsed / 300.0f)); + // 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); _tft.fillScreen(bg); diff --git a/boards/esp32-32e-4/DisplayDriverTFT.h b/boards/esp32-32e-4/DisplayDriverTFT.h index e4f9e2f..c225406 100644 --- a/boards/esp32-32e-4/DisplayDriverTFT.h +++ b/boards/esp32-32e-4/DisplayDriverTFT.h @@ -44,7 +44,9 @@ private: // Touch hint for alert - progressive fill from bottom bool _alertTouchDown = false; uint32_t _alertTouchStartMs = 0; + uint32_t _lastAlertDrawMs = 0; 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;