From c4adb38576505558e068559791b726019dbaf43d Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 17 Feb 2026 05:03:41 -0800 Subject: [PATCH] feat(display): add active state parameter to hint animation 1. **Added `active` parameter to hint animation** - `updateHint()` now accepts a boolean `active` parameter across both display drivers (TFT and GFX) - When `active=true`: faster pulse animation (500ms period) during active hold - When `active=false`: slower pulse animation (2000ms period) during idle state 2. **Improved animation calculations** - Replaced modulo operator with `fmodf()` for cleaner float calculations - Standardized to `static_cast()` for type conversions - Fixed GFX driver to use `color565()` method instead of manual bit shifting 3. **Updated hint display logic** - Now differentiates between "holding" state (fast pulse) and "idle" state (slow pulse) - Hint draws at both states when `holdStartX >= 0` (touch position captured) 4. **Added code formatter task** - New `mise.toml` task for running clang-format across all source files - Users get **visual feedback differentiation**: fast pulsing during active hold vs. slow pulsing when idle - More intuitive UI that clearly indicates whether a long-press is in progress or just waiting - Cleaner, more maintainable code with standardized calculations and type conversions --- boards/esp32-32e/DisplayDriverTFT.cpp | 8 ++++---- boards/esp32-32e/esp32-32e.ino | 5 +++-- boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp | 12 ++++++------ boards/esp32-s3-lcd-43/esp32-s3-lcd-43.ino | 12 +++++++----- libraries/KlubhausCore/src/IDisplayDriver.h | 4 ++-- mise.toml | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/boards/esp32-32e/DisplayDriverTFT.cpp b/boards/esp32-32e/DisplayDriverTFT.cpp index 29b3cbd..acb22c5 100644 --- a/boards/esp32-32e/DisplayDriverTFT.cpp +++ b/boards/esp32-32e/DisplayDriverTFT.cpp @@ -169,10 +169,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) { return h; } -void DisplayDriverTFT::updateHint(int x, int y) { - float t = (millis() % 2000) / 2000.0f; - uint8_t v = (uint8_t)(30.0f + 30.0f * sinf(t * 2 * PI)); +void DisplayDriverTFT::updateHint(int x, int y, bool active) { + float period = active ? 500.0f : 2000.0f; + float t = fmodf(millis(), period) / period; + uint8_t v = static_cast(30.0f + 30.0f * sinf(t * 2.0f * PI)); uint16_t col = _tft.color565(v, v, v); - // Draw at touch position instead of center _tft.drawRect(x - 40, y - 20, 80, 40, col); } diff --git a/boards/esp32-32e/esp32-32e.ino b/boards/esp32-32e/esp32-32e.ino index 0241647..74835b8 100644 --- a/boards/esp32-32e/esp32-32e.ino +++ b/boards/esp32-32e/esp32-32e.ino @@ -44,8 +44,9 @@ void loop() { holdStartX = t.x; holdStartY = t.y; } - if(!h.active && holdStartX >= 0) { - display.updateHint(holdStartX, holdStartY); + // Fix for esp32-32e.ino + if(holdStartX >= 0) { + display.updateHint(holdStartX, holdStartY, h.active); } } else { holdStartX = -1; diff --git a/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp b/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp index f76f08f..9394ca2 100644 --- a/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp +++ b/boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp @@ -239,21 +239,21 @@ void DisplayDriverGFX::drawDashboard(const ScreenState& state) { } } -void DisplayDriverGFX::updateHint(int x, int y) { +void DisplayDriverGFX::updateHint(int x, int y, bool active) { if(!_gfx) return; static uint32_t lastTime = 0; uint32_t now = millis(); - // Fixed: throttle to 100ms instead of 50ms if(now - lastTime < 100) return; lastTime = now; - float t = (now % 2000) / 2000.0f; - uint8_t v = static_cast(30.0f + 30.0f * sinf(t * 2 * 3.14159f)); - uint16_t col = ((v >> 3) << 11) | ((v >> 2) << 5) | (v >> 3); + // active=true: faster pulse (500ms), active=false: slower pulse (2000ms) + float period = active ? 500.0f : 2000.0f; + float t = fmodf(now, period) / period; + uint8_t v = static_cast(30.0f + 30.0f * sinf(t * 2.0f * 3.14159f)); + uint16_t col = _gfx->color565(v, v, v); - // Draw at touch position instead of center _gfx->drawCircle(x, y, 50, col); } diff --git a/boards/esp32-s3-lcd-43/esp32-s3-lcd-43.ino b/boards/esp32-s3-lcd-43/esp32-s3-lcd-43.ino index 03b1da0..ea2cfb6 100644 --- a/boards/esp32-s3-lcd-43/esp32-s3-lcd-43.ino +++ b/boards/esp32-s3-lcd-43/esp32-s3-lcd-43.ino @@ -40,19 +40,21 @@ void loop() { holdStartY = -1; } if(h.started) { - // Capture initial touch position holdStartX = evt.x; holdStartY = evt.y; } - if(!h.active && holdStartX >= 0) { - display.updateHint(holdStartX, holdStartY); + // Draw hint during hold (ACTIVE) or idle (IDLE) + if(holdStartX >= 0) { + if(h.active) { + display.updateHint(holdStartX, holdStartY, true); + } else { + display.updateHint(holdStartX, holdStartY, false); + } } } else { - // Reset when not alerting holdStartX = -1; holdStartY = -1; } - if(evt.pressed) { if(st.screen == ScreenID::OFF) { // Tap in OFF mode → wake to DASHBOARD diff --git a/libraries/KlubhausCore/src/IDisplayDriver.h b/libraries/KlubhausCore/src/IDisplayDriver.h index aad8e37..978dd8b 100644 --- a/libraries/KlubhausCore/src/IDisplayDriver.h +++ b/libraries/KlubhausCore/src/IDisplayDriver.h @@ -32,8 +32,8 @@ public: /// Track a long-press gesture; returns progress/completion. virtual HoldState updateHold(unsigned long holdMs) = 0; /// Idle hint animation (e.g. pulsing ring) while alert is showing. - virtual void updateHint(int x, int y) = 0; - + /// @param active If true, show "holding" animation; if false, show "idle" animation. + virtual void updateHint(int x, int y, bool active) = 0; virtual int width() = 0; virtual int height() = 0; }; diff --git a/mise.toml b/mise.toml index 1425462..92c41c5 100644 --- a/mise.toml +++ b/mise.toml @@ -139,3 +139,17 @@ rm -rf boards/esp32-32e/build rm -rf boards/esp32-s3-lcd-43/build echo "[OK] Build artifacts cleaned" """ + +[tasks.format] +run = """ +clang-format -i --style=file \ + boards/esp32-32e/*.cpp \ + boards/esp32-32e/*.h \ + boards/esp32-32e/*.ino \ + boards/esp32-s3-lcd-43/*.cpp \ + boards/esp32-s3-lcd-43/*.h \ + boards/esp32-s3-lcd-43/*.ino \ + libraries/KlubhausCore/src/*.cpp \ + libraries/KlubhausCore/src/*.h \ + libraries/KlubhausCore/*.properties +"""