refactor(touch): centralize touch handling in DoorbellLogic

This commit is contained in:
2026-02-17 23:35:59 -08:00
parent 4f389ac0fe
commit 46289b9d40
6 changed files with 91 additions and 53 deletions

View File

@@ -21,14 +21,20 @@ void setup() {
}
void loop() {
// ── Read touch ──
TouchEvent evt = display.readTouch();
// ── State machine tick ──
logic.update();
// ── Render current screen ──
display.render(logic.getScreenState());
// ── Touch handling ──
// ── Touch handling (tap gestures) ──
const ScreenState& st = logic.getScreenState();
int tile = logic.handleTouch(evt);
// ── Hold gesture (for silencing alerts) ──
static int holdStartX = -1;
static int holdStartY = -1;
@@ -40,11 +46,9 @@ void loop() {
holdStartY = -1;
}
if(h.started) {
TouchEvent t = display.readTouch();
holdStartX = t.x;
holdStartY = t.y;
holdStartX = evt.x;
holdStartY = evt.y;
}
// Fix for esp32-32e.ino
if(holdStartX >= 0) {
display.updateHint(holdStartX, holdStartY, h.active);
}
@@ -53,15 +57,6 @@ void loop() {
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');