79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
/*
|
|
* KLUBHAUS ALERT v5.0 — E32R35T Edition
|
|
*
|
|
* Target: LCDWiki E32R35T (ESP32-WROOM-32E + 3.5" ST7796S + XPT2046)
|
|
*
|
|
* Refactored: business logic separated from display code.
|
|
* Business logic knows nothing about TFT_eSPI.
|
|
* Display knows nothing about ntfy/WiFi/state machine.
|
|
* They communicate through ScreenState (plain struct).
|
|
*/
|
|
|
|
#include "Config.h"
|
|
#include "DisplayManager.h"
|
|
#include "DoorbellLogic.h"
|
|
|
|
DisplayManager display;
|
|
DoorbellLogic logic;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
unsigned long t = millis();
|
|
while (!Serial && millis() - t < 3000) delay(10);
|
|
delay(500);
|
|
|
|
Serial.println("\n========================================");
|
|
Serial.println(" KLUBHAUS ALERT v5.0 — E32R35T");
|
|
#if DEBUG_MODE
|
|
Serial.println(" *** DEBUG MODE — _test topics ***");
|
|
#endif
|
|
Serial.println("========================================");
|
|
|
|
// 1. Init display hardware
|
|
display.begin();
|
|
|
|
// 2. Init logic (sets boot splash screen state)
|
|
logic.begin();
|
|
display.render(logic.getScreenState());
|
|
delay(1500);
|
|
|
|
// 3. WiFi (logic updates screen state, we render each phase)
|
|
// We need a small coupling here for the blocking WiFi connect
|
|
// This could be made async later
|
|
logic.beginWiFi(); // sets screen to WIFI_CONNECTING
|
|
display.render(logic.getScreenState());
|
|
|
|
logic.connectWiFiBlocking(); // blocks, sets CONNECTED or FAILED
|
|
display.render(logic.getScreenState());
|
|
delay(1500);
|
|
|
|
// 4. Finish boot
|
|
logic.finishBoot();
|
|
display.setBacklight(false);
|
|
|
|
Serial.println("[BOOT] Ready — monitoring ntfy.sh\n");
|
|
}
|
|
|
|
void loop() {
|
|
// 1. Read touch
|
|
TouchEvent touch = display.readTouch();
|
|
logic.onTouch(touch);
|
|
|
|
// 2. Read serial commands
|
|
if (Serial.available()) {
|
|
String cmd = Serial.readStringUntil('\n');
|
|
cmd.trim();
|
|
logic.onSerialCommand(cmd);
|
|
}
|
|
|
|
// 3. Update business logic
|
|
logic.update();
|
|
|
|
// 4. Render
|
|
const ScreenState& state = logic.getScreenState();
|
|
display.setBacklight(state.screen != ScreenID::OFF);
|
|
display.render(state);
|
|
|
|
delay(20);
|
|
}
|