feat(doorbell): add staged boot sequence and refactor main loop
This commit is contained in:
@@ -21,55 +21,29 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ── Read touch ──
|
||||
// Read touch
|
||||
TouchEvent evt = display.readTouch();
|
||||
|
||||
// ── Touch debug ──
|
||||
// Touch debug (useful for new boards)
|
||||
if(evt.pressed) {
|
||||
Serial.printf("[TOUCH] pressed: x=%d, y=%d\n", evt.x, evt.y);
|
||||
}
|
||||
|
||||
// ── State machine tick ──
|
||||
// State machine tick
|
||||
logic.update();
|
||||
|
||||
// ── Render current screen ──
|
||||
// Render current screen
|
||||
display.render(logic.getScreenState());
|
||||
|
||||
// ── Touch handling (tap gestures) ──
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
int tile = logic.handleTouch(evt);
|
||||
// Handle tap gestures
|
||||
logic.handleTouch(evt);
|
||||
|
||||
// ── Hold gesture (for silencing alerts) ──
|
||||
static int holdStartX = -1;
|
||||
static int holdStartY = -1;
|
||||
// Handle hold-to-silence gesture
|
||||
logic.updateHold(evt);
|
||||
|
||||
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) {
|
||||
holdStartX = evt.x;
|
||||
holdStartY = evt.y;
|
||||
}
|
||||
if(holdStartX >= 0) {
|
||||
display.updateHint(holdStartX, holdStartY, h.active);
|
||||
}
|
||||
} else {
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
// Serial console
|
||||
logic.processSerial();
|
||||
|
||||
// ── Serial console ──
|
||||
if(Serial.available()) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
if(cmd.length() > 0)
|
||||
logic.onSerialCommand(cmd);
|
||||
}
|
||||
|
||||
// Yield to WiFi/BT stack (prevents Task Watchdog timeout)
|
||||
delay(10);
|
||||
}
|
||||
// Yield to WiFi/BT stack
|
||||
delay(LOOP_YIELD_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user