Compare commits
13 Commits
e3c78e266b
...
8c92487a47
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c92487a47 | |||
| 4414185891 | |||
| db668f27dd | |||
| 3b0c9c98b7 | |||
| 4d66bded22 | |||
| 853bb38c46 | |||
| 5ebbf0177a | |||
| 4876fb29b7 | |||
| 40c0a0a97e | |||
| c348de9e38 | |||
| f658b95a2b | |||
| dcc710e9b3 | |||
| 0e867a196c |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
||||
[submodule "TFT_eSPI"]
|
||||
path = TFT_eSPI
|
||||
url = https://github.com/Cincinnatu/TFT_eSPI
|
||||
[submodule "examples/Waveshare-ESP32-S3-Touch-LCD-4.3-and-Arduino"]
|
||||
path = examples/Waveshare-ESP32-S3-Touch-LCD-4.3-and-Arduino
|
||||
url = https://github.com/Westcott1/Waveshare-ESP32-S3-Touch-LCD-4.3-and-Arduino.git
|
||||
|
||||
@@ -17,9 +17,7 @@ void DisplayDriverTFT::begin() {
|
||||
Serial.println("[GFX] Backlight ON");
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::setBacklight(bool on) {
|
||||
digitalWrite(PIN_LCD_BL, on ? HIGH : LOW);
|
||||
}
|
||||
void DisplayDriverTFT::setBacklight(bool on) { digitalWrite(PIN_LCD_BL, on ? HIGH : LOW); }
|
||||
|
||||
// ── Rendering ───────────────────────────────────────────────
|
||||
|
||||
@@ -31,16 +29,26 @@ void DisplayDriverTFT::render(const ScreenState& st) {
|
||||
|
||||
switch(st.screen) {
|
||||
case ScreenID::BOOT:
|
||||
if (_needsRedraw) { drawBoot(); _needsRedraw = false; }
|
||||
if(_needsRedraw) {
|
||||
drawBoot();
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
case ScreenID::ALERT:
|
||||
drawAlert(st);
|
||||
break;
|
||||
|
||||
case ScreenID::DASHBOARD:
|
||||
if (_needsRedraw) { drawDashboard(st); _needsRedraw = false; }
|
||||
if(_needsRedraw) {
|
||||
drawDashboard(st);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
case ScreenID::OFF:
|
||||
if (_needsRedraw) { _tft.fillScreen(TFT_BLACK); _needsRedraw = false; }
|
||||
if(_needsRedraw) {
|
||||
_tft.fillScreen(TFT_BLACK);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -88,18 +96,21 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
|
||||
_tft.printf("KLUBHAUS — %s", deviceStateStr(st.deviceState));
|
||||
|
||||
int y = 30;
|
||||
_tft.setCursor(5, y); y += 18;
|
||||
_tft.setCursor(5, y);
|
||||
y += 18;
|
||||
_tft.printf("WiFi: %s %ddBm", st.wifiSsid.c_str(), st.wifiRssi);
|
||||
|
||||
_tft.setCursor(5, y); y += 18;
|
||||
_tft.setCursor(5, y);
|
||||
y += 18;
|
||||
_tft.printf("IP: %s", st.ipAddr.c_str());
|
||||
|
||||
_tft.setCursor(5, y); y += 18;
|
||||
_tft.setCursor(5, y);
|
||||
y += 18;
|
||||
_tft.printf("Up: %lus Heap: %d", st.uptimeMs / 1000, ESP.getFreeHeap());
|
||||
|
||||
_tft.setCursor(5, y); y += 18;
|
||||
_tft.printf("Last poll: %lus ago",
|
||||
st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0);
|
||||
_tft.setCursor(5, y);
|
||||
y += 18;
|
||||
_tft.printf("Last poll: %lus ago", st.lastPollMs > 0 ? (millis() - st.lastPollMs) / 1000 : 0);
|
||||
}
|
||||
|
||||
// ── Touch ───────────────────────────────────────────────────
|
||||
@@ -116,14 +127,15 @@ TouchEvent DisplayDriverTFT::readTouch() {
|
||||
}
|
||||
|
||||
int DisplayDriverTFT::dashboardTouch(int x, int y) {
|
||||
// Unified 2x2 grid (matching GFX)
|
||||
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
|
||||
int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1
|
||||
// 2x2 grid, accounting for 30px header
|
||||
if(y < 30)
|
||||
return -1;
|
||||
|
||||
// Adjust for header offset (y starts at 30 in drawDashboard)
|
||||
if (y < 30) return -1;
|
||||
row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30);
|
||||
if (row < 0 || row > 1) return -1;
|
||||
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
|
||||
int row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30); // 0 or 1
|
||||
|
||||
if(col < 0 || col > 1 || row < 0 || row > 1)
|
||||
return -1;
|
||||
|
||||
return row * 2 + col; // 0, 1, 2, or 3
|
||||
}
|
||||
@@ -136,6 +148,7 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
if(!_holdActive) {
|
||||
_holdActive = true;
|
||||
_holdStartMs = millis();
|
||||
h.started = true;
|
||||
}
|
||||
uint32_t held = millis() - _holdStartMs;
|
||||
h.active = true;
|
||||
@@ -147,8 +160,8 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
||||
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
||||
} else {
|
||||
if (_ // Clear theholdActive) {
|
||||
progress bar when released
|
||||
if(_holdActive) {
|
||||
// Clear the progress bar when released
|
||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
|
||||
}
|
||||
_holdActive = false;
|
||||
@@ -156,9 +169,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
return h;
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::updateHint() {
|
||||
float t = (millis() % 2000) / 2000.0f;
|
||||
uint8_t v = (uint8_t)(30.0f + 30.0f * sinf(t * 2 * PI));
|
||||
void DisplayDriverTFT::updateHint(int x, int y, bool active) {
|
||||
float period = active ? 500.0f : 2000.0f;
|
||||
float t = fmodf(millis(), period) / period;
|
||||
uint8_t v = static_cast<uint8_t>(30.0f + 30.0f * sinf(t * 2.0f * PI));
|
||||
uint16_t col = _tft.color565(v, v, v);
|
||||
_tft.drawRect(DISPLAY_WIDTH / 2 - 40, DISPLAY_HEIGHT / 2 + 20, 80, 40, col);
|
||||
_tft.drawRect(x - 40, y - 20, 80, 40, col);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
#include <KlubhausCore.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include "board_config.h"
|
||||
|
||||
class DisplayDriverTFT : public IDisplayDriver {
|
||||
public:
|
||||
@@ -12,7 +13,7 @@ public:
|
||||
TouchEvent readTouch() override;
|
||||
int dashboardTouch(int x, int y) override;
|
||||
HoldState updateHold(unsigned long holdMs) override;
|
||||
void updateHint() override;
|
||||
void updateHint(int x, int y, bool active) override;
|
||||
int width() override { return DISPLAY_WIDTH; }
|
||||
int height() override { return DISPLAY_HEIGHT; }
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
// Klubhaus Doorbell — ESP32-32E target
|
||||
//
|
||||
|
||||
#include <KlubhausCore.h>
|
||||
#include "DisplayDriverTFT.h"
|
||||
#include "board_config.h"
|
||||
#include "secrets.h"
|
||||
#include "DisplayDriverTFT.h"
|
||||
|
||||
#include <KlubhausCore.h>
|
||||
|
||||
DisplayDriverTFT tftDriver;
|
||||
DisplayManager display(&tftDriver);
|
||||
@@ -28,20 +29,36 @@ void loop() {
|
||||
|
||||
// ── Touch handling ──
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
static int holdStartX = -1;
|
||||
static int holdStartY = -1;
|
||||
|
||||
if(st.deviceState == DeviceState::ALERTING) {
|
||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||
if(h.completed) {
|
||||
logic.silenceAlert();
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
if (!h.active) {
|
||||
display.updateHint();
|
||||
if(h.started) {
|
||||
TouchEvent t = display.readTouch();
|
||||
holdStartX = t.x;
|
||||
holdStartY = t.y;
|
||||
}
|
||||
// Fix for esp32-32e.ino
|
||||
if(holdStartX >= 0) {
|
||||
display.updateHint(holdStartX, holdStartY, h.active);
|
||||
}
|
||||
} else {
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
|
||||
if(st.screen == ScreenID::DASHBOARD) {
|
||||
TouchEvent evt = display.readTouch();
|
||||
if (evt.pressed && st.screen == ScreenID::DASHBOARD) {
|
||||
if(evt.pressed) {
|
||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||
if (tile >= 0) Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
if(tile >= 0)
|
||||
Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +66,7 @@ void loop() {
|
||||
if(Serial.available()) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
if (cmd.length() > 0) logic.onSerialCommand(cmd);
|
||||
if(cmd.length() > 0)
|
||||
logic.onSerialCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,17 @@
|
||||
// TFT_eSPI User_Setup for ESP32-32E target
|
||||
// This file is copied over vendor/esp32-32e/TFT_eSPI/User_Setup.h
|
||||
// by the install-libs-32e task.
|
||||
//
|
||||
// TODO: Change the driver, pins, and dimensions to match your display.
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
#define USER_SETUP_ID 200
|
||||
|
||||
// ── Driver ──
|
||||
#define ILI9341_DRIVER
|
||||
// #define ST7789_DRIVER
|
||||
// #define ILI9488_DRIVER
|
||||
|
||||
// ── Resolution ──
|
||||
#define TFT_WIDTH 240
|
||||
#define TFT_HEIGHT 320
|
||||
// FIXED: Match board_config.h (320x240 landscape)
|
||||
#define TFT_WIDTH 320
|
||||
#define TFT_HEIGHT 240
|
||||
|
||||
// ── SPI Pins ──
|
||||
#define TFT_MOSI 23
|
||||
|
||||
@@ -1,75 +1,31 @@
|
||||
#include "LovyanPins.h"
|
||||
#include "board_config.h"
|
||||
#include <Arduino.h>
|
||||
#include <ESP_IOExpander_Library.h>
|
||||
|
||||
// Global display instance
|
||||
static LGFX* _gfx = nullptr;
|
||||
static ESP_IOExpander* _expander = nullptr;
|
||||
|
||||
// Forward declarations
|
||||
void initExpander();
|
||||
void initDisplay();
|
||||
|
||||
// ── Expander initialization (from Westcott) ──
|
||||
void initExpander()
|
||||
{
|
||||
Serial.println("IO expander init...");
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <ESP_IOExpander_Library.h>
|
||||
#include "LovyanPins.h"
|
||||
#include "board_config.h"
|
||||
// boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp
|
||||
#include "DisplayDriverGFX.h"
|
||||
|
||||
#include "LovyanPins.h"
|
||||
#include "board_config.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// ── Globals ──
|
||||
static LGFX* _gfx = nullptr;
|
||||
static ESP_IOExpander* _expander = nullptr;
|
||||
|
||||
// ── Forward declarations ──
|
||||
static void initExpander();
|
||||
static void initDisplay();
|
||||
|
||||
// ── Dimensions ──
|
||||
static constexpr int DISP_W = 800;
|
||||
static constexpr int DISP_H = 480;
|
||||
|
||||
// ── Expander initialization ──
|
||||
static void initExpander() {
|
||||
Serial.println("IO expander init...");
|
||||
|
||||
// Initialize I2C for expander
|
||||
Wire.begin(TOUCH_SDA, TOUCH_SCL);
|
||||
|
||||
_expander = new ESP_IOExpander_CH422G(
|
||||
(i2c_port_t)I2C_NUM_0,
|
||||
ESP_IO_EXPANDER_I2C_CH422G_ADDRESS
|
||||
);
|
||||
_expander->init();
|
||||
_expander->begin();
|
||||
|
||||
// Set all pins to output
|
||||
_expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
|
||||
|
||||
// Reset sequence
|
||||
_expander->digitalWrite(LCD_RST, LOW);
|
||||
delay(50);
|
||||
_expander->digitalWrite(LCD_RST, HIGH);
|
||||
delay(150);
|
||||
|
||||
// Turn on backlight
|
||||
_expander->digitalWrite(LCD_BL, HIGH);
|
||||
|
||||
Serial.println("IO expander ready");
|
||||
}
|
||||
|
||||
// ── Display initialization ──
|
||||
static void initDisplay() {
|
||||
Serial.println("LovyanGFX init...");
|
||||
|
||||
// Note: LovyanGFX handles I2C internally (port 1 for touch, port 0 for CH422G)
|
||||
// No need to call Wire.begin() or Wire1.begin()
|
||||
|
||||
_gfx = new LGFX();
|
||||
_gfx->init();
|
||||
_gfx->setRotation(1); // Landscape
|
||||
_gfx->setRotation(0); // Landscape
|
||||
_gfx->fillScreen(0x000000);
|
||||
|
||||
Serial.println("Display ready");
|
||||
@@ -84,45 +40,42 @@ DisplayDriverGFX& DisplayDriverGFX::instance() {
|
||||
// ── IDisplayDriver implementation ──
|
||||
|
||||
void DisplayDriverGFX::begin() {
|
||||
initExpander();
|
||||
initDisplay();
|
||||
// Turn on backlight immediately
|
||||
setBacklight(true);
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::setBacklight(bool on) {
|
||||
if (_expander) {
|
||||
_expander->digitalWrite(LCD_BL, on ? HIGH : LOW);
|
||||
if(_gfx) {
|
||||
// LovyanGFX handles backlight via setBrightness
|
||||
_gfx->setBrightness(on ? 255 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
int DisplayDriverGFX::width() {
|
||||
return DISP_W;
|
||||
}
|
||||
int DisplayDriverGFX::width() { return DISP_W; }
|
||||
|
||||
int DisplayDriverGFX::height() {
|
||||
return DISP_H;
|
||||
}
|
||||
int DisplayDriverGFX::height() { return DISP_H; }
|
||||
|
||||
// ── Touch handling ──
|
||||
|
||||
TouchEvent DisplayDriverGFX::readTouch() {
|
||||
TouchEvent evt;
|
||||
|
||||
if (!_gfx) return evt;
|
||||
if(!_gfx)
|
||||
return evt;
|
||||
|
||||
int32_t x, y;
|
||||
if (_gfx->getTouch(&x, &y)) {
|
||||
evt.pressed = true;
|
||||
bool pressed = _gfx->getTouch(&x, &y);
|
||||
|
||||
// Only report NEW touches (debounce - ignore held touches)
|
||||
evt.pressed = pressed && !_lastTouch.pressed;
|
||||
|
||||
if(pressed) {
|
||||
evt.x = static_cast<int>(x);
|
||||
evt.y = static_cast<int>(y);
|
||||
|
||||
// Track press start
|
||||
if (!_lastTouch.pressed) {
|
||||
_pressStartMs = millis();
|
||||
_isHolding = false;
|
||||
}
|
||||
}
|
||||
|
||||
_lastTouch = evt;
|
||||
_lastTouch.pressed = pressed;
|
||||
return evt;
|
||||
}
|
||||
|
||||
@@ -154,8 +107,8 @@ HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
||||
unsigned long elapsed = millis() - _pressStartMs;
|
||||
|
||||
if(!_isHolding) {
|
||||
// Start tracking hold
|
||||
_isHolding = true;
|
||||
state.started = true;
|
||||
}
|
||||
|
||||
state.active = true;
|
||||
@@ -172,73 +125,135 @@ HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
||||
// ── Rendering ──
|
||||
|
||||
void DisplayDriverGFX::render(const ScreenState& state) {
|
||||
if (!_gfx) return;
|
||||
|
||||
// Clear with background color
|
||||
_gfx->fillScreen(0x001030); // Dark blue
|
||||
|
||||
if (!state.showDashboard) {
|
||||
// Show alert/message screen
|
||||
renderAlert(state);
|
||||
if(!_gfx)
|
||||
return;
|
||||
|
||||
// Check if we need full redraw
|
||||
if(state.screen != _lastScreen) {
|
||||
_needsRedraw = true;
|
||||
_lastScreen = state.screen;
|
||||
}
|
||||
|
||||
// Draw dashboard tiles
|
||||
switch(state.screen) {
|
||||
case ScreenID::BOOT:
|
||||
if(_needsRedraw) {
|
||||
_gfx->fillScreen(0x000000);
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(10, 10);
|
||||
_gfx->print("KLUBHAUS BOOT");
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case ScreenID::OFF:
|
||||
if(_needsRedraw) {
|
||||
_gfx->fillScreen(0x000000);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case ScreenID::ALERT:
|
||||
// Only redraw on first entry or screen change
|
||||
if(_needsRedraw) {
|
||||
drawAlert(state);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case ScreenID::DASHBOARD:
|
||||
if(_needsRedraw) {
|
||||
drawDashboard(state);
|
||||
_needsRedraw = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::drawAlert(const ScreenState& state) {
|
||||
uint32_t elapsed = millis() - state.alertStartMs;
|
||||
uint8_t pulse = static_cast<uint8_t>(180.0f + 75.0f * sinf(elapsed / 300.0f));
|
||||
uint16_t bg = _gfx->color565(pulse, 0, 0);
|
||||
|
||||
_gfx->fillScreen(bg);
|
||||
_gfx->setTextColor(0xFFFF, bg);
|
||||
|
||||
_gfx->setTextSize(3);
|
||||
_gfx->setCursor(10, 20);
|
||||
_gfx->print(state.alertTitle.length() > 0 ? state.alertTitle.c_str() : "ALERT");
|
||||
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(10, 80);
|
||||
_gfx->print(state.alertBody);
|
||||
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(10, DISP_H - 20);
|
||||
_gfx->print("Hold to silence...");
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
||||
_gfx->fillScreen(0x001030); // Dark blue
|
||||
|
||||
// Header
|
||||
_gfx->fillRect(0, 0, DISP_W, 30, 0x1A1A); // Dark gray
|
||||
_gfx->setFont(&fonts::Font0); // Built-in minimal font
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(5, 10);
|
||||
_gfx->printf("KLUBHAUS");
|
||||
|
||||
// WiFi status
|
||||
_gfx->setCursor(DISP_W - 100, 10);
|
||||
_gfx->printf("WiFi:%s", state.wifiSsid.length() > 0 ? "ON" : "OFF");
|
||||
|
||||
// Tiles: 2 rows × 4 columns
|
||||
constexpr int cols = 4;
|
||||
constexpr int rows = 2;
|
||||
constexpr int tileW = DISP_W / cols;
|
||||
constexpr int tileH = DISP_H / rows;
|
||||
constexpr int tileH = (DISP_H - 30) / rows;
|
||||
constexpr int margin = 8;
|
||||
|
||||
for (int i = 0; i < state.dashTiles.size(); i++) {
|
||||
// Draw placeholder tiles (8 total for 2x4 grid)
|
||||
const char* tileLabels[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
int col = i % cols;
|
||||
int row = i / cols;
|
||||
|
||||
int x = col * tileW + margin;
|
||||
int y = row * tileH + margin;
|
||||
int y = 30 + row * tileH + margin;
|
||||
int w = tileW - 2 * margin;
|
||||
int h = tileH - 2 * margin;
|
||||
|
||||
// Tile background
|
||||
uint16_t tileColor = state.dashTiles[i].active ? 0x04A0 : 0x0220;
|
||||
_gfx->fillRoundRect(x, y, w, h, 8, tileColor);
|
||||
_gfx->fillRoundRect(x, y, w, h, 8, 0x0220);
|
||||
|
||||
// Tile border
|
||||
_gfx->drawRoundRect(x, y, w, h, 8, 0xFFFF);
|
||||
|
||||
// Tile label
|
||||
// Tile number
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(x + 10, y + 10);
|
||||
_gfx->print(state.dashTiles[i].label);
|
||||
_gfx->setCursor(x + w / 2 - 10, y + h / 2 - 10);
|
||||
_gfx->print(tileLabels[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw WiFi status
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(DISP_W - 100, 10);
|
||||
_gfx->printf("WiFi: %s", state.wifiConnected ? "ON" : "OFF");
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::updateHint() {
|
||||
if (!_gfx) return;
|
||||
void DisplayDriverGFX::updateHint(int x, int y, bool active) {
|
||||
if(!_gfx)
|
||||
return;
|
||||
|
||||
static uint32_t lastTime = 0;
|
||||
uint32_t now = millis();
|
||||
if (now - lastTime < 50) return;
|
||||
if(now - lastTime < 100)
|
||||
return;
|
||||
lastTime = now;
|
||||
|
||||
float t = (now % 2000) / 2000.0f;
|
||||
uint8_t v = static_cast<uint8_t>(30.0f + 30.0f * sinf(t * 2 * 3.14159f));
|
||||
uint16_t col = ((v >> 3) << 11) | ((v >> 2) << 5) | (v >> 3);
|
||||
// active=true: faster pulse (500ms), active=false: slower pulse (2000ms)
|
||||
float period = active ? 500.0f : 2000.0f;
|
||||
float t = fmodf(now, period) / period;
|
||||
uint8_t v = static_cast<uint8_t>(30.0f + 30.0f * sinf(t * 2.0f * 3.14159f));
|
||||
uint16_t col = _gfx->color565(v, v, v);
|
||||
|
||||
_gfx->drawCircle(DISP_W / 2, DISP_H / 2, 50, col);
|
||||
}
|
||||
|
||||
// Helper for alert rendering (implement as needed)
|
||||
void DisplayDriverGFX::renderAlert(const ScreenState& state) {
|
||||
// Placeholder - implement based on your ScreenState fields
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(3);
|
||||
_gfx->setCursor(200, 200);
|
||||
_gfx->print("Alert Mode");
|
||||
_gfx->drawCircle(x, y, 50, col);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "ScreenState.h"
|
||||
#include "IDisplayDriver.h"
|
||||
|
||||
struct TouchEvent {
|
||||
bool pressed = false;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
};
|
||||
|
||||
struct HoldState {
|
||||
bool active = false;
|
||||
bool completed = false;
|
||||
float progress = 0.0f; // 0.0 – 1.0
|
||||
};
|
||||
#include <Arduino.h>
|
||||
|
||||
class DisplayDriverGFX : public IDisplayDriver {
|
||||
public:
|
||||
@@ -26,7 +14,7 @@ public:
|
||||
TouchEvent readTouch() override;
|
||||
int dashboardTouch(int x, int y) override;
|
||||
HoldState updateHold(unsigned long holdMs) override;
|
||||
void updateHint() override;
|
||||
void updateHint(int x, int y, bool active) override;
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
@@ -35,8 +23,16 @@ public:
|
||||
static DisplayDriverGFX& instance();
|
||||
|
||||
private:
|
||||
// Helper rendering functions
|
||||
void drawAlert(const ScreenState& state);
|
||||
void drawDashboard(const ScreenState& state);
|
||||
|
||||
// Touch handling
|
||||
TouchEvent _lastTouch = { false, 0, 0 };
|
||||
unsigned long _pressStartMs = 0;
|
||||
bool _isHolding = false;
|
||||
|
||||
// Screen tracking
|
||||
ScreenID _lastScreen = ScreenID::BOOT;
|
||||
bool _needsRedraw = true;
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#define LGFX_USE_V1
|
||||
#include <LovyanGFX.hpp>
|
||||
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
|
||||
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
|
||||
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
|
||||
|
||||
// ── Display dimensions ──
|
||||
#define TFT_HOR_RES 800
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
// 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);
|
||||
@@ -20,35 +21,60 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ── State machine tick ──
|
||||
logic.update();
|
||||
TouchEvent evt = display.readTouch();
|
||||
|
||||
// ── Render current screen ──
|
||||
logic.update();
|
||||
display.render(logic.getScreenState());
|
||||
|
||||
// ── Touch handling ──
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
|
||||
// Track initial hold position for hint
|
||||
static int holdStartX = -1;
|
||||
static int holdStartY = -1;
|
||||
|
||||
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;
|
||||
}
|
||||
// Draw hint during hold (ACTIVE) or idle (IDLE)
|
||||
if(holdStartX >= 0) {
|
||||
if(h.active) {
|
||||
display.updateHint(holdStartX, holdStartY, true);
|
||||
} else {
|
||||
display.updateHint(holdStartX, holdStartY, false);
|
||||
}
|
||||
if (!h.active) {
|
||||
display.updateHint();
|
||||
}
|
||||
} else {
|
||||
TouchEvent evt = display.readTouch();
|
||||
if (evt.pressed && st.screen == ScreenID::DASHBOARD) {
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
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);
|
||||
if(tile >= 0) {
|
||||
Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
}
|
||||
} else if(st.screen == ScreenID::ALERT) {
|
||||
Serial.println("[TOUCH] ALERT tap");
|
||||
}
|
||||
}
|
||||
|
||||
// ── Serial console ──
|
||||
if(Serial.available()) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
if (cmd.length() > 0) logic.onSerialCommand(cmd);
|
||||
if(cmd.length() > 0)
|
||||
logic.onSerialCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "IDisplayDriver.h"
|
||||
|
||||
/// Owns a pointer to the concrete driver; all calls delegate.
|
||||
/// Board sketch creates the concrete driver and passes it in.
|
||||
class DisplayManager {
|
||||
public:
|
||||
DisplayManager() : _drv(nullptr) {}
|
||||
explicit DisplayManager(IDisplayDriver* drv) : _drv(drv) {}
|
||||
void setDriver(IDisplayDriver* drv) { _drv = drv; }
|
||||
DisplayManager(IDisplayDriver* drv)
|
||||
: _drv(drv) { }
|
||||
|
||||
void begin() {
|
||||
if(_drv)
|
||||
_drv->begin();
|
||||
}
|
||||
|
||||
void setBacklight(bool on) {
|
||||
if(_drv)
|
||||
_drv->setBacklight(on);
|
||||
}
|
||||
|
||||
void render(const ScreenState& st) {
|
||||
if(_drv)
|
||||
_drv->render(st);
|
||||
}
|
||||
|
||||
void begin() { if (_drv) _drv->begin(); }
|
||||
void setBacklight(bool on) { if (_drv) _drv->setBacklight(on); }
|
||||
void render(const ScreenState& st) { if (_drv) _drv->render(st); }
|
||||
TouchEvent readTouch() { return _drv ? _drv->readTouch() : TouchEvent {}; }
|
||||
|
||||
int dashboardTouch(int x, int y) { return _drv ? _drv->dashboardTouch(x, y) : -1; }
|
||||
|
||||
HoldState updateHold(unsigned long ms) { return _drv ? _drv->updateHold(ms) : HoldState {}; }
|
||||
void updateHint() { if (_drv) _drv->updateHint(); }
|
||||
|
||||
void updateHint(int x, int y, bool active) {
|
||||
if(_drv)
|
||||
_drv->updateHint(x, y, active);
|
||||
}
|
||||
|
||||
int width() { return _drv ? _drv->width() : 0; }
|
||||
|
||||
int height() { return _drv ? _drv->height() : 0; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -7,14 +7,13 @@ DoorbellLogic::DoorbellLogic(DisplayManager* display)
|
||||
|
||||
String DoorbellLogic::topicUrl(const char* base) {
|
||||
String suffix = _debug ? "_test" : "";
|
||||
return String("https://") + NTFY_SERVER + "/" + base + suffix
|
||||
+ "/json?since=20s&poll=1";
|
||||
return String("https://") + NTFY_SERVER + "/" + base + suffix + "/json?since=20s&poll=1";
|
||||
}
|
||||
|
||||
// ── Lifecycle ───────────────────────────────────────────────
|
||||
|
||||
void DoorbellLogic::begin(const char* version, const char* boardName,
|
||||
const WiFiCred* creds, int credCount) {
|
||||
void DoorbellLogic::begin(
|
||||
const char* version, const char* boardName, const WiFiCred* creds, int credCount) {
|
||||
_version = version;
|
||||
_board = boardName;
|
||||
#ifdef DEBUG_MODE
|
||||
@@ -23,7 +22,8 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
|
||||
|
||||
Serial.println(F("========================================"));
|
||||
Serial.printf(" KLUBHAUS ALERT v%s — %s\n", _version, _board);
|
||||
if (_debug) Serial.println(F(" *** DEBUG MODE — _test topics ***"));
|
||||
if(_debug)
|
||||
Serial.println(F(" *** DEBUG MODE — _test topics ***"));
|
||||
Serial.println(F("========================================\n"));
|
||||
|
||||
// Display
|
||||
@@ -34,8 +34,7 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
|
||||
|
||||
if(_net.isConnected()) {
|
||||
_net.syncNTP();
|
||||
Serial.printf("[NET] WiFi:%s RSSI:%d IP:%s\n",
|
||||
_net.getSSID().c_str(), _net.getRSSI(),
|
||||
Serial.printf("[NET] WiFi:%s RSSI:%d IP:%s\n", _net.getSSID().c_str(), _net.getRSSI(),
|
||||
_net.getIP().c_str());
|
||||
_net.dnsCheck(NTFY_SERVER);
|
||||
_net.tlsCheck(NTFY_SERVER);
|
||||
@@ -53,8 +52,8 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
|
||||
Serial.printf("[CONFIG] ADMIN_URL: %s\n", _adminUrl.c_str());
|
||||
|
||||
// Boot status
|
||||
flushStatus(String("BOOTED — ") + _net.getSSID() + " "
|
||||
+ _net.getIP() + " RSSI:" + String(_net.getRSSI()));
|
||||
flushStatus(String("BOOTED — ") + _net.getSSID() + " " + _net.getIP()
|
||||
+ " RSSI:" + String(_net.getRSSI()));
|
||||
}
|
||||
|
||||
void DoorbellLogic::finishBoot() {
|
||||
@@ -78,7 +77,8 @@ void DoorbellLogic::update() {
|
||||
_state.wifiSsid = _net.getSSID();
|
||||
_state.ipAddr = _net.getIP();
|
||||
}
|
||||
if (!_net.checkConnection()) return;
|
||||
if(!_net.checkConnection())
|
||||
return;
|
||||
|
||||
// Poll
|
||||
if(now - _lastPollMs >= POLL_INTERVAL_MS) {
|
||||
@@ -112,7 +112,8 @@ void DoorbellLogic::update() {
|
||||
_state.backlightOn = false;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,32 +129,39 @@ void DoorbellLogic::pollTopics() {
|
||||
void DoorbellLogic::pollTopic(const String& url, const char* label) {
|
||||
String body;
|
||||
int code = _net.httpGet(url.c_str(), body);
|
||||
if (code != 200 || body.length() == 0) return;
|
||||
if(code != 200 || body.length() == 0)
|
||||
return;
|
||||
|
||||
// ntfy returns newline-delimited JSON
|
||||
int pos = 0;
|
||||
while(pos < (int)body.length()) {
|
||||
int nl = body.indexOf('\n', pos);
|
||||
if (nl < 0) nl = body.length();
|
||||
if(nl < 0)
|
||||
nl = body.length();
|
||||
String line = body.substring(pos, nl);
|
||||
line.trim();
|
||||
pos = nl + 1;
|
||||
if (line.length() == 0) continue;
|
||||
if(line.length() == 0)
|
||||
continue;
|
||||
|
||||
JsonDocument doc;
|
||||
if (deserializeJson(doc, line)) continue;
|
||||
if(deserializeJson(doc, line))
|
||||
continue;
|
||||
|
||||
const char* evt = doc["event"] | "";
|
||||
if (strcmp(evt, "message") != 0) continue;
|
||||
if(strcmp(evt, "message") != 0)
|
||||
continue;
|
||||
|
||||
const char* title = doc["title"] | "";
|
||||
const char* message = doc["message"] | "";
|
||||
Serial.printf("[%s] title=\"%s\" message=\"%s\"\n",
|
||||
label, title, message);
|
||||
Serial.printf("[%s] title=\"%s\" message=\"%s\"\n", label, title, message);
|
||||
|
||||
if (strcmp(label, "ALERT") == 0) onAlert(String(title), String(message));
|
||||
else if (strcmp(label, "SILENCE") == 0) onSilence();
|
||||
else if (strcmp(label, "ADMIN") == 0) onAdmin(String(message));
|
||||
if(strcmp(label, "ALERT") == 0)
|
||||
onAlert(String(title), String(message));
|
||||
else if(strcmp(label, "SILENCE") == 0)
|
||||
onSilence();
|
||||
else if(strcmp(label, "ADMIN") == 0)
|
||||
onAdmin(String(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +184,8 @@ void DoorbellLogic::onAlert(const String& title, const String& body) {
|
||||
}
|
||||
|
||||
void DoorbellLogic::onSilence() {
|
||||
if (_state.deviceState != DeviceState::ALERTING) return;
|
||||
if(_state.deviceState != DeviceState::ALERTING)
|
||||
return;
|
||||
Serial.println("[SILENCE] Alert silenced");
|
||||
_state.silenceStartMs = millis();
|
||||
transition(DeviceState::SILENCED);
|
||||
@@ -219,8 +228,7 @@ void DoorbellLogic::flushStatus(const String& message) {
|
||||
|
||||
void DoorbellLogic::heartbeat() {
|
||||
String m = String("HEARTBEAT ") + deviceStateStr(_state.deviceState)
|
||||
+ " up:" + String(millis() / 1000) + "s"
|
||||
+ " RSSI:" + String(_net.getRSSI())
|
||||
+ " up:" + String(millis() / 1000) + "s" + " RSSI:" + String(_net.getRSSI())
|
||||
+ " heap:" + String(ESP.getFreeHeap());
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
m += " psram:" + String(ESP.getFreePsram());
|
||||
@@ -237,24 +245,36 @@ void DoorbellLogic::transition(DeviceState s) {
|
||||
|
||||
void DoorbellLogic::onSerialCommand(const String& cmd) {
|
||||
Serial.printf("[CMD] %s\n", cmd.c_str());
|
||||
if (cmd == "alert") onAlert("Test Alert", "Serial test");
|
||||
else if (cmd == "silence") onSilence();
|
||||
else if (cmd == "reboot") ESP.restart();
|
||||
else if (cmd == "dashboard") onAdmin("dashboard");
|
||||
else if (cmd == "off") onAdmin("off");
|
||||
if(cmd == "alert")
|
||||
onAlert("Test Alert", "Serial test");
|
||||
else if(cmd == "silence")
|
||||
onSilence();
|
||||
else if(cmd == "reboot")
|
||||
ESP.restart();
|
||||
else if(cmd == "dashboard")
|
||||
onAdmin("dashboard");
|
||||
else if(cmd == "off")
|
||||
onAdmin("off");
|
||||
else if(cmd == "status") {
|
||||
Serial.printf("[STATE] %s screen:%s bl:%s\n",
|
||||
deviceStateStr(_state.deviceState),
|
||||
screenIdStr(_state.screen),
|
||||
_state.backlightOn ? "ON" : "OFF");
|
||||
Serial.printf("[STATE] %s screen:%s bl:%s\n", deviceStateStr(_state.deviceState),
|
||||
screenIdStr(_state.screen), _state.backlightOn ? "ON" : "OFF");
|
||||
Serial.printf("[MEM] heap:%d", ESP.getFreeHeap());
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
Serial.printf(" psram:%d", ESP.getFreePsram());
|
||||
#endif
|
||||
Serial.println();
|
||||
Serial.printf("[NET] %s RSSI:%d IP:%s\n",
|
||||
_state.wifiSsid.c_str(), _state.wifiRssi,
|
||||
Serial.printf("[NET] %s RSSI:%d IP:%s\n", _state.wifiSsid.c_str(), _state.wifiRssi,
|
||||
_state.ipAddr.c_str());
|
||||
} else
|
||||
Serial.println(F("[CMD] alert|silence|reboot|dashboard|off|status"));
|
||||
}
|
||||
else Serial.println(F("[CMD] alert|silence|reboot|dashboard|off|status"));
|
||||
|
||||
void DoorbellLogic::setScreen(ScreenID s) {
|
||||
Serial.printf("[SCREEN] Set to %s\n", screenIdStr(s));
|
||||
_state.screen = s;
|
||||
|
||||
// Auto-manage backlight based on screen
|
||||
bool needsBacklight = (s != ScreenID::OFF);
|
||||
_display->setBacklight(needsBacklight);
|
||||
_state.backlightOn = needsBacklight;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "Config.h"
|
||||
#include "ScreenState.h"
|
||||
#include "DisplayManager.h"
|
||||
#include "NetManager.h"
|
||||
#include "ScreenState.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class DoorbellLogic {
|
||||
public:
|
||||
explicit DoorbellLogic(DisplayManager* display);
|
||||
|
||||
/// Call from setup(). Pass board-specific WiFi creds.
|
||||
void begin(const char* version, const char* boardName,
|
||||
const WiFiCred* creds, int credCount);
|
||||
void begin(const char* version, const char* boardName, const WiFiCred* creds, int credCount);
|
||||
/// Call from loop() — polls topics, runs timers, transitions state.
|
||||
void update();
|
||||
/// Transition out of BOOTED → SILENT. Call at end of setup().
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
|
||||
/// Externally trigger silence (e.g. hold-to-silence gesture).
|
||||
void silenceAlert();
|
||||
void setScreen(ScreenID s);
|
||||
|
||||
private:
|
||||
void pollTopics();
|
||||
|
||||
@@ -9,6 +9,7 @@ struct TouchEvent {
|
||||
|
||||
struct HoldState {
|
||||
bool active = false;
|
||||
bool started = false;
|
||||
bool completed = false;
|
||||
float progress = 0.0f; // 0.0 – 1.0
|
||||
};
|
||||
@@ -31,8 +32,8 @@ public:
|
||||
/// Track a long-press gesture; returns progress/completion.
|
||||
virtual HoldState updateHold(unsigned long holdMs) = 0;
|
||||
/// Idle hint animation (e.g. pulsing ring) while alert is showing.
|
||||
virtual void updateHint() = 0;
|
||||
|
||||
/// @param active If true, show "holding" animation; if false, show "idle" animation.
|
||||
virtual void updateHint(int x, int y, bool active) = 0;
|
||||
virtual int width() = 0;
|
||||
virtual int height() = 0;
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
// Umbrella header — board sketches just #include <KlubhausCore.h>
|
||||
#include "Config.h"
|
||||
#include "ScreenState.h"
|
||||
#include "IDisplayDriver.h"
|
||||
#include "DisplayManager.h"
|
||||
#include "NetManager.h"
|
||||
#include "DoorbellLogic.h"
|
||||
#include "IDisplayDriver.h"
|
||||
#include "NetManager.h"
|
||||
#include "ScreenState.h"
|
||||
|
||||
@@ -16,12 +16,12 @@ void NetManager::begin(const WiFiCred* creds, int count) {
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
Serial.printf("[WIFI] Connected: %s %s\n",
|
||||
getSSID().c_str(), getIP().c_str());
|
||||
Serial.printf("[WIFI] Connected: %s %s\n", getSSID().c_str(), getIP().c_str());
|
||||
}
|
||||
|
||||
bool NetManager::checkConnection() {
|
||||
if (WiFi.status() == WL_CONNECTED) return true;
|
||||
if(WiFi.status() == WL_CONNECTED)
|
||||
return true;
|
||||
Serial.println("[WIFI] Reconnecting...");
|
||||
return _multi.run(WIFI_CONNECT_TIMEOUT_MS) == WL_CONNECTED;
|
||||
}
|
||||
@@ -35,12 +35,12 @@ int NetManager::getRSSI() { return WiFi.RSSI(); }
|
||||
|
||||
bool NetManager::syncNTP() {
|
||||
Serial.println("[NTP] Starting sync...");
|
||||
if (!_ntp) _ntp = new NTPClient(_udp, "pool.ntp.org", 0, 60000);
|
||||
if(!_ntp)
|
||||
_ntp = new NTPClient(_udp, "pool.ntp.org", 0, 60000);
|
||||
_ntp->begin();
|
||||
_ntp->forceUpdate();
|
||||
_ntpReady = _ntp->isTimeSet();
|
||||
Serial.printf("[NTP] %s: %s UTC\n",
|
||||
_ntpReady ? "Synced" : "FAILED",
|
||||
Serial.printf("[NTP] %s: %s UTC\n", _ntpReady ? "Synced" : "FAILED",
|
||||
_ntpReady ? _ntp->getFormattedTime().c_str() : "--");
|
||||
return _ntpReady;
|
||||
}
|
||||
@@ -54,8 +54,7 @@ String NetManager::getTimeStr() {
|
||||
bool NetManager::dnsCheck(const char* host) {
|
||||
IPAddress ip;
|
||||
bool ok = WiFi.hostByName(host, ip);
|
||||
Serial.printf("[NET] DNS %s: %s\n", ok ? "OK" : "FAIL",
|
||||
ok ? ip.toString().c_str() : "");
|
||||
Serial.printf("[NET] DNS %s: %s\n", ok ? "OK" : "FAIL", ok ? ip.toString().c_str() : "");
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -64,7 +63,8 @@ bool NetManager::tlsCheck(const char* host) {
|
||||
c.setInsecure();
|
||||
c.setTimeout(HTTP_TIMEOUT_MS);
|
||||
bool ok = c.connect(host, 443);
|
||||
if (ok) c.stop();
|
||||
if(ok)
|
||||
c.stop();
|
||||
Serial.printf("[NET] TLS %s\n", ok ? "OK" : "FAIL");
|
||||
return ok;
|
||||
}
|
||||
@@ -81,7 +81,8 @@ int NetManager::httpGet(const char* url, String& response) {
|
||||
http.begin(client, url);
|
||||
|
||||
int code = http.GET();
|
||||
if (code > 0) response = http.getString();
|
||||
if(code > 0)
|
||||
response = http.getString();
|
||||
http.end();
|
||||
return code;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
#include "Config.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <NTPClient.h>
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "Config.h"
|
||||
|
||||
class NetManager {
|
||||
public:
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
enum class DeviceState {
|
||||
BOOTED,
|
||||
SILENT,
|
||||
ALERTING,
|
||||
SILENCED
|
||||
};
|
||||
enum class DeviceState { BOOTED, SILENT, ALERTING, SILENCED };
|
||||
|
||||
enum class ScreenID {
|
||||
BOOT,
|
||||
OFF,
|
||||
ALERT,
|
||||
DASHBOARD
|
||||
};
|
||||
enum class ScreenID { BOOT, OFF, ALERT, DASHBOARD };
|
||||
|
||||
struct ScreenState {
|
||||
DeviceState deviceState = DeviceState::BOOTED;
|
||||
@@ -31,24 +21,34 @@ struct ScreenState {
|
||||
uint32_t uptimeMs = 0;
|
||||
uint32_t lastPollMs = 0;
|
||||
uint32_t lastHeartbeatMs = 0;
|
||||
|
||||
bool showDashboard = false;
|
||||
};
|
||||
|
||||
inline const char* deviceStateStr(DeviceState s) {
|
||||
switch(s) {
|
||||
case DeviceState::BOOTED: return "BOOTED";
|
||||
case DeviceState::SILENT: return "SILENT";
|
||||
case DeviceState::ALERTING: return "ALERTING";
|
||||
case DeviceState::SILENCED: return "SILENCED";
|
||||
case DeviceState::BOOTED:
|
||||
return "BOOTED";
|
||||
case DeviceState::SILENT:
|
||||
return "SILENT";
|
||||
case DeviceState::ALERTING:
|
||||
return "ALERTING";
|
||||
case DeviceState::SILENCED:
|
||||
return "SILENCED";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
inline const char* screenIdStr(ScreenID s) {
|
||||
switch(s) {
|
||||
case ScreenID::BOOT: return "BOOT";
|
||||
case ScreenID::OFF: return "OFF";
|
||||
case ScreenID::ALERT: return "ALERT";
|
||||
case ScreenID::DASHBOARD: return "DASHBOARD";
|
||||
case ScreenID::BOOT:
|
||||
return "BOOT";
|
||||
case ScreenID::OFF:
|
||||
return "OFF";
|
||||
case ScreenID::ALERT:
|
||||
return "ALERT";
|
||||
case ScreenID::DASHBOARD:
|
||||
return "DASHBOARD";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ description = "Install shared (platform-independent) libraries"
|
||||
run = """
|
||||
arduino-cli lib install "ArduinoJson@7.4.1"
|
||||
arduino-cli lib install "NTPClient@3.2.1"
|
||||
arduino-cli lib install "ESP32_IO_Expander@0.0.4"
|
||||
echo "[OK] Shared libraries installed"
|
||||
"""
|
||||
|
||||
@@ -33,15 +32,37 @@ run = """
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
LOVyanGFX_DIR="vendor/esp32-s3-lcd-43/LovyanGFX"
|
||||
|
||||
# Clone LovyanGFX (latest)
|
||||
if [ ! -d "vendor/esp32-s3-lcd-43/LovyanGFX" ]; then
|
||||
if [ ! -d "$LOVyanGFX_DIR" ]; then
|
||||
echo "Cloning LovyanGFX..."
|
||||
git clone --depth 1 \
|
||||
https://github.com/lovyan03/LovyanGFX.git \
|
||||
vendor/esp32-s3-lcd-43/LovyanGFX
|
||||
"$LOVyanGFX_DIR"
|
||||
else
|
||||
echo "LovyanGFX already exists, skipping"
|
||||
fi
|
||||
|
||||
# Create library.properties that correctly points to source
|
||||
cat > "$LOVyanGFX_DIR/library.properties" << 'EOF'
|
||||
name=LovyanGFX
|
||||
version=1.2.0
|
||||
author=lovyan03
|
||||
maintainer=lovyan03
|
||||
sentence=Display and touch driver library for ESP32
|
||||
paragraph=Universal graphics library for ESP32 with support for various displays and touch controllers
|
||||
category=Display
|
||||
url=https://github.com/lovyan03/LovyanGFX
|
||||
architectures=esp32
|
||||
includes=LovyanGFX.hpp
|
||||
# This tells Arduino to build from src/
|
||||
# Arduino will look in src/ for .cpp files
|
||||
EOF
|
||||
|
||||
# Create a empty src to ensure sources are found
|
||||
mkdir -p "$LOVyanGFX_DIR/src"
|
||||
|
||||
echo "[OK] LovyanGFX vendored"
|
||||
"""
|
||||
|
||||
@@ -56,13 +77,12 @@ description = "Compile ESP32-32E sketch"
|
||||
depends = ["install-libs"]
|
||||
run = """
|
||||
arduino-cli compile \
|
||||
--fqbn "esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB" \
|
||||
--fqbn "esp32:esp32@2.0.11:esp32:FlashSize=4M,PartitionScheme=default" \
|
||||
--libraries ./libraries \
|
||||
--libraries ./vendor/esp32-s3-lcd-43 \
|
||||
--libraries ./vendor/esp32-32e/TFT_eSPI \
|
||||
--build-property "compiler.cpp.extra_flags=-DDEBUG_MODE -DBOARD_HAS_PSRAM" \
|
||||
--build-property "build.extra_flags=-DCONFIG_ESP32S3_OLD_I2C_LEGACY_DEVICE_COMPAT_MODE=1" \
|
||||
--warnings default \
|
||||
./boards/esp32-s3-lcd-43
|
||||
./boards/esp32-32e
|
||||
"""
|
||||
|
||||
[tasks.upload-32e]
|
||||
@@ -83,14 +103,14 @@ arduino-cli monitor --port "${PORT:-/dev/ttyUSB0}" --config baudrate=115200
|
||||
# ── ESP32-S3-LCD-4.3 ────────────────────────────────────
|
||||
|
||||
[tasks.compile-s3-43]
|
||||
description = "Compile ESP32-S3-LCD-4.3 sketch"
|
||||
description = "Compile ESP32-S3-LCD-4.3 sketch (Core 2.x)"
|
||||
depends = ["install-libs"]
|
||||
run = """
|
||||
arduino-cli compile \
|
||||
--fqbn "esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB" \
|
||||
--libraries ./libraries \
|
||||
--libraries ./vendor/esp32-s3-lcd-43/LovyanGFX \
|
||||
--build-property "compiler.cpp.extra_flags=-DDEBUG_MODE -DBOARD_HAS_PSRAM" \
|
||||
--library ./vendor/esp32-s3-lcd-43/LovyanGFX \
|
||||
--build-property "compiler.cpp.extra_flags=-DDEBUG_MODE -DBOARD_HAS_PSRAM -DLGFX_USE_V1" \
|
||||
--warnings default \
|
||||
./boards/esp32-s3-lcd-43
|
||||
"""
|
||||
@@ -119,3 +139,17 @@ rm -rf boards/esp32-32e/build
|
||||
rm -rf boards/esp32-s3-lcd-43/build
|
||||
echo "[OK] Build artifacts cleaned"
|
||||
"""
|
||||
|
||||
[tasks.format]
|
||||
run = """
|
||||
clang-format -i --style=file \
|
||||
boards/esp32-32e/*.cpp \
|
||||
boards/esp32-32e/*.h \
|
||||
boards/esp32-32e/*.ino \
|
||||
boards/esp32-s3-lcd-43/*.cpp \
|
||||
boards/esp32-s3-lcd-43/*.h \
|
||||
boards/esp32-s3-lcd-43/*.ino \
|
||||
libraries/KlubhausCore/src/*.cpp \
|
||||
libraries/KlubhausCore/src/*.h \
|
||||
libraries/KlubhausCore/*.properties
|
||||
"""
|
||||
|
||||
2
sketches/doorbell-touch/vendor/.gitignore
vendored
Normal file
2
sketches/doorbell-touch/vendor/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user