This commit is contained in:
2026-02-15 17:42:33 -08:00
parent d3aeb6f207
commit bfa8592eec
8 changed files with 999 additions and 48 deletions

View File

@@ -1,58 +1,78 @@
#include <TFT_eSPI.h>
#include <SPI.h>
/*
* 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).
*/
TFT_eSPI tft = TFT_eSPI();
#include "Config.h"
#include "DisplayManager.h"
#include "DoorbellLogic.h"
DisplayManager display;
DoorbellLogic logic;
void setup() {
Serial.begin(115200);
delay(2000);
unsigned long t = millis();
while (!Serial && millis() - t < 3000) delay(10);
delay(500);
// Backlight ON
pinMode(27, OUTPUT);
digitalWrite(27, HIGH);
// Config verification
Serial.println("\n=== E32R35T Config ===");
#if defined(USER_SETUP_LOADED)
Serial.println("User_Setup: LOADED");
#else
Serial.println("User_Setup: DEFAULT (BAD!)");
Serial.println("\n========================================");
Serial.println(" KLUBHAUS ALERT v5.0 — E32R35T");
#if DEBUG_MODE
Serial.println(" *** DEBUG MODE — _test topics ***");
#endif
#if defined(USE_HSPI_PORT)
Serial.println("SPI Bus: HSPI");
#else
Serial.println("SPI Bus: VSPI");
#endif
Serial.printf("MOSI:%d SCLK:%d MISO:%d\n", TFT_MOSI, TFT_SCLK, TFT_MISO);
Serial.printf("CS:%d DC:%d RST:%d BL:%d\n", TFT_CS, TFT_DC, TFT_RST, TFT_BL);
Serial.printf("TOUCH_CS:%d\n", TOUCH_CS);
Serial.printf("SPI_FREQ:%d\n", SPI_FREQUENCY);
Serial.println("======================\n");
Serial.println("========================================");
tft.init();
tft.setRotation(1);
// 1. Init display hardware
display.begin();
uint16_t colors[] = {TFT_RED, TFT_GREEN, TFT_BLUE, TFT_WHITE, TFT_BLACK};
const char* names[] = {"RED", "GREEN", "BLUE", "WHITE", "BLACK"};
// 2. Init logic (sets boot splash screen state)
logic.begin();
display.render(logic.getScreenState());
delay(1500);
for (int i = 0; i < 5; i++) {
tft.fillScreen(colors[i]);
Serial.printf("Screen: %s\n", names[i]);
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());
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setTextSize(3);
tft.drawString("E32R35T Works!", 30, 100);
Serial.println("Done!");
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() {
uint16_t x, y;
if (tft.getTouch(&x, &y)) {
Serial.printf("Touch: %d, %d\n", x, y);
tft.fillCircle(x, y, 4, TFT_YELLOW);
}
}
// 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);
}