refactor(display): improve touch handling and code formatting
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
// Klubhaus Doorbell — ESP32-S3-Touch-LCD-4.3 target
|
||||
//
|
||||
|
||||
#include <KlubhausCore.h>
|
||||
#include "DisplayDriverGFX.h"
|
||||
#include "board_config.h"
|
||||
#include "secrets.h"
|
||||
#include "DisplayDriverGFX.h"
|
||||
|
||||
#include <KlubhausCore.h>
|
||||
|
||||
DisplayDriverGFX gfxDriver;
|
||||
DisplayManager display(&gfxDriver);
|
||||
DoorbellLogic logic(&display);
|
||||
DisplayManager display(&gfxDriver);
|
||||
DoorbellLogic logic(&display);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@@ -19,36 +20,52 @@ void setup() {
|
||||
logic.finishBoot();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ── State machine tick ──
|
||||
logic.update();
|
||||
// void loop() {
|
||||
TouchEvent evt = display.readTouch();
|
||||
|
||||
// ── Render current screen ──
|
||||
display.render(logic.getScreenState());
|
||||
logic.update();
|
||||
display.render(logic.getScreenState());
|
||||
|
||||
// ── Touch handling ──
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
|
||||
if (st.deviceState == DeviceState::ALERTING) {
|
||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||
if (h.completed) {
|
||||
logic.silenceAlert();
|
||||
}
|
||||
if (!h.active) {
|
||||
display.updateHint();
|
||||
}
|
||||
} else {
|
||||
TouchEvent evt = display.readTouch();
|
||||
if (evt.pressed && st.screen == ScreenID::DASHBOARD) {
|
||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||
if (tile >= 0) Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
}
|
||||
if(st.deviceState == DeviceState::ALERTING) {
|
||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||
if(h.completed) {
|
||||
logic.silenceAlert();
|
||||
}
|
||||
|
||||
// ── Serial console ──
|
||||
if (Serial.available()) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
if (cmd.length() > 0) logic.onSerialCommand(cmd);
|
||||
if(!h.active) {
|
||||
display.updateHint();
|
||||
}
|
||||
} else if(evt.pressed) {
|
||||
if(st.screen == ScreenID::OFF) {
|
||||
// Tap in OFF mode → wake to DASHBOARD
|
||||
Serial.println("[TOUCH] OFF → DASHBOARD");
|
||||
logic.setScreen(ScreenID::DASHBOARD);
|
||||
display.setBacklight(true);
|
||||
} else if(st.screen == ScreenID::DASHBOARD) {
|
||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||
if(tile >= 0) {
|
||||
Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
// TODO: Handle tile actions
|
||||
}
|
||||
} else if(st.screen == ScreenID::ALERT) {
|
||||
// Tap in ALERT mode → could dismiss or show more info
|
||||
Serial.println("[TOUCH] ALERT tap");
|
||||
// For now, let's make tap do nothing (hold to silence only)
|
||||
// Or: logic.dismissAlert();
|
||||
}
|
||||
}
|
||||
|
||||
// Serial console (unchanged)
|
||||
if(Serial.available()) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
// ── Serial console ──
|
||||
if(Serial.available()) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
if(cmd.length() > 0)
|
||||
logic.onSerialCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user