Files
klubhaus-doorbell/boards/esp32-32e/esp32-32e.ino
David Gwilliam c4adb38576 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<uint8_t>()` 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
2026-02-17 05:11:02 -08:00

73 lines
1.8 KiB
C++

//
// Klubhaus Doorbell — ESP32-32E target
//
#include "DisplayDriverTFT.h"
#include "board_config.h"
#include "secrets.h"
#include <KlubhausCore.h>
DisplayDriverTFT tftDriver;
DisplayManager display(&tftDriver);
DoorbellLogic logic(&display);
void setup() {
Serial.begin(115200);
delay(500);
logic.begin(FW_VERSION, BOARD_NAME, wifiNetworks, wifiNetworkCount);
logic.finishBoot();
}
void loop() {
// ── State machine tick ──
logic.update();
// ── Render current screen ──
display.render(logic.getScreenState());
// ── Touch handling ──
const ScreenState& st = logic.getScreenState();
static int holdStartX = -1;
static int holdStartY = -1;
if(st.deviceState == DeviceState::ALERTING) {
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
if(h.completed) {
logic.silenceAlert();
holdStartX = -1;
holdStartY = -1;
}
if(h.started) {
TouchEvent t = display.readTouch();
holdStartX = t.x;
holdStartY = t.y;
}
// Fix for esp32-32e.ino
if(holdStartX >= 0) {
display.updateHint(holdStartX, holdStartY, h.active);
}
} else {
holdStartX = -1;
holdStartY = -1;
}
if(st.screen == ScreenID::DASHBOARD) {
TouchEvent evt = display.readTouch();
if(evt.pressed) {
int tile = display.dashboardTouch(evt.x, evt.y);
if(tile >= 0)
Serial.printf("[DASH] Tile %d tapped\n", tile);
}
}
// ── Serial console ──
if(Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if(cmd.length() > 0)
logic.onSerialCommand(cmd);
}
}