From 24f69e85895793f2d3af4daa7b7503edf896328e Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Mon, 16 Feb 2026 02:01:27 -0800 Subject: [PATCH] snapshot --- sketches/doorbell-touch-esp32-32e/Config.h | 2 +- .../DisplayManager.cpp | 32 ++++++++++++++++-- .../DoorbellLogic.cpp | 26 +++++++++++---- .../doorbell-touch-esp32-32e/ScreenData.h | 12 +++++++ .../doorbell-touch-esp32-32e/User_Setup.h | 33 ------------------- .../doorbell-touch-esp32-32e.ino | 10 ++++++ 6 files changed, 72 insertions(+), 43 deletions(-) delete mode 100644 sketches/doorbell-touch-esp32-32e/User_Setup.h diff --git a/sketches/doorbell-touch-esp32-32e/Config.h b/sketches/doorbell-touch-esp32-32e/Config.h index 3e3d021..40e49a9 100644 --- a/sketches/doorbell-touch-esp32-32e/Config.h +++ b/sketches/doorbell-touch-esp32-32e/Config.h @@ -11,7 +11,7 @@ struct WiFiCred { const char *ssid; const char *pass; }; static WiFiCred wifiNetworks[] = { { "Dobro Veče", "goodnight" }, - { "berylpunk", "dhgwilliam" }, + { "iot-2GHz", "lesson-greater" }, }; static const int NUM_WIFI = sizeof(wifiNetworks) / sizeof(wifiNetworks[0]); diff --git a/sketches/doorbell-touch-esp32-32e/DisplayManager.cpp b/sketches/doorbell-touch-esp32-32e/DisplayManager.cpp index 5d58a40..8c800d3 100644 --- a/sketches/doorbell-touch-esp32-32e/DisplayManager.cpp +++ b/sketches/doorbell-touch-esp32-32e/DisplayManager.cpp @@ -7,6 +7,23 @@ void DisplayManager::begin() { _tft.init(); _tft.setRotation(1); // landscape: 480x320 + + // === DIAGNOSTIC: most basic text rendering === + _tft.fillScreen(TFT_BLUE); + _tft.setTextColor(TFT_WHITE); // no background color arg + _tft.setTextFont(1); // explicitly set GLCD font + _tft.setTextSize(3); + _tft.setCursor(10, 10); // absolute position, no datum + _tft.print("HELLO"); + _tft.setCursor(10, 60); + _tft.print("W:"); + _tft.print(_tft.width()); + _tft.setCursor(10, 110); + _tft.print("H:"); + _tft.print(_tft.height()); + delay(5000); + // === END DIAGNOSTIC === + _tft.fillScreen(COL_BLACK); } @@ -188,10 +205,19 @@ void DisplayManager::drawStatusScreen(const ScreenState& s) { s.deviceState == DeviceState::SILENT ? COL_GREEN : COL_NEON_TEAL; drawInfoLine(x, y, stCol, buf); y += sp; - if (strlen(s.alertMessage) > 0) { - snprintf(buf, sizeof(buf), "Last: %.40s", s.alertMessage); - drawInfoLine(x, y, COL_DARK_GRAY, buf); y += sp; +// Recent alerts +if (s.alertHistoryCount > 0) { + drawInfoLine(x, y, COL_MINT, "Recent Alerts:"); y += sp; + for (int i = 0; i < s.alertHistoryCount; i++) { + uint16_t col = (i == 0) ? COL_YELLOW : COL_DARK_GRAY; + snprintf(buf, sizeof(buf), "%s %.35s", + s.alertHistory[i].timestamp, + s.alertHistory[i].message); + drawInfoLine(x, y, col, buf); y += sp; } +} else { + drawInfoLine(x, y, COL_DARK_GRAY, "No alerts yet"); y += sp; +} if (s.debugMode) { drawInfoLine(x, y, COL_YELLOW, "DEBUG MODE - _test topics"); diff --git a/sketches/doorbell-touch-esp32-32e/DoorbellLogic.cpp b/sketches/doorbell-touch-esp32-32e/DoorbellLogic.cpp index 9f62af2..3fb6b05 100644 --- a/sketches/doorbell-touch-esp32-32e/DoorbellLogic.cpp +++ b/sketches/doorbell-touch-esp32-32e/DoorbellLogic.cpp @@ -117,11 +117,11 @@ void DoorbellLogic::update() { switch (_state) { case DeviceState::ALERTING: - if (now - _alertStart > ALERT_TIMEOUT_MS) { - Serial.println("[ALERT] Timeout — auto-silencing"); - handleSilence("timeout"); - break; - } + // if (now - _alertStart > ALERT_TIMEOUT_MS) { + // Serial.println("[ALERT] Timeout — auto-silencing"); + // handleSilence("timeout"); + // break; + // } if (now - _lastBlink >= BLINK_INTERVAL_MS) { _lastBlink = now; _blinkState = !_blinkState; @@ -251,7 +251,21 @@ void DoorbellLogic::transitionTo(DeviceState newState) { void DoorbellLogic::handleAlert(const String& msg) { if (_state == DeviceState::ALERTING && _currentMessage == msg) return; _currentMessage = msg; - _alertMsgEpoch = _lastParsedMsgEpoch; // store ntfy server time of this alert + _alertMsgEpoch = _lastParsedMsgEpoch; + + // Push into history (shift older entries down) + for (int i = ALERT_HISTORY_SIZE - 1; i > 0; i--) { + _screen.alertHistory[i] = _screen.alertHistory[i - 1]; + } + strncpy(_screen.alertHistory[0].message, msg.c_str(), 63); + _screen.alertHistory[0].message[63] = '\0'; + strncpy(_screen.alertHistory[0].timestamp, + _ntpSynced ? _timeClient->getFormattedTime().c_str() : "??:??:??", 11); + _screen.alertHistory[0].timestamp[11] = '\0'; + + if (_screen.alertHistoryCount < ALERT_HISTORY_SIZE) + _screen.alertHistoryCount++; + Serial.printf("[ALERT] Accepted. ntfy time=%ld\n", (long)_alertMsgEpoch); transitionTo(DeviceState::ALERTING); queueStatus("ALERTING", msg); diff --git a/sketches/doorbell-touch-esp32-32e/ScreenData.h b/sketches/doorbell-touch-esp32-32e/ScreenData.h index 6f2ce34..c2ecfb0 100644 --- a/sketches/doorbell-touch-esp32-32e/ScreenData.h +++ b/sketches/doorbell-touch-esp32-32e/ScreenData.h @@ -21,6 +21,13 @@ enum class ScreenID : uint8_t { OFF // backlight off, nothing to draw }; +#define ALERT_HISTORY_SIZE 3 + +struct AlertRecord { + char message[64] = ""; + char timestamp[12] = ""; // "HH:MM:SS" +}; + // Everything the display needs to render any screen struct ScreenState { ScreenID screen = ScreenID::BOOT_SPLASH; @@ -47,6 +54,11 @@ struct ScreenState { // Debug bool debugMode = false; + + // Alert history (newest first) + AlertRecord alertHistory[ALERT_HISTORY_SIZE] = {}; + int alertHistoryCount = 0; + }; // Touch event passed from display to logic diff --git a/sketches/doorbell-touch-esp32-32e/User_Setup.h b/sketches/doorbell-touch-esp32-32e/User_Setup.h deleted file mode 100644 index 6d35eef..0000000 --- a/sketches/doorbell-touch-esp32-32e/User_Setup.h +++ /dev/null @@ -1,33 +0,0 @@ -// ===== User_Setup.h for E32R35T (ESP32-32E 3.5" Display) ===== -#define USER_SETUP_LOADED - -#define ST7796_DRIVER - -#define TFT_WIDTH 320 -#define TFT_HEIGHT 480 - -// LCD pins (HSPI bus) -#define TFT_CS 15 -#define TFT_DC 2 // Called "TFT_RS" on the board -#define TFT_RST -1 // RST is tied to EN (ESP32 reset pin), not a GPIO -#define TFT_MOSI 13 -#define TFT_SCLK 14 -#define TFT_MISO 12 - -// Backlight -#define TFT_BL 27 -#define TFT_BACKLIGHT_ON HIGH - -// Touch (XPT2046, shares HSPI bus with LCD) -#define TOUCH_CS 33 - -// Use HSPI port (not default VSPI) -#define USE_HSPI_PORT - -// SPI Frequencies -#define SPI_FREQUENCY 27000000 -#define SPI_READ_FREQUENCY 20000000 -#define SPI_TOUCH_FREQUENCY 2500000 - -#define SUPPORT_TRANSACTIONS - diff --git a/sketches/doorbell-touch-esp32-32e/doorbell-touch-esp32-32e.ino b/sketches/doorbell-touch-esp32-32e/doorbell-touch-esp32-32e.ino index 316f3a3..af4ec3d 100644 --- a/sketches/doorbell-touch-esp32-32e/doorbell-touch-esp32-32e.ino +++ b/sketches/doorbell-touch-esp32-32e/doorbell-touch-esp32-32e.ino @@ -16,6 +16,16 @@ DisplayManager display; DoorbellLogic logic; +#include + +#ifndef LOAD_GLCD + #error "LOAD_GLCD is NOT defined — fonts missing!" +#endif + +#ifndef ST7796_DRIVER + #error "ST7796_DRIVER is NOT defined — wrong setup!" +#endif + void setup() { Serial.begin(115200); unsigned long t = millis();