style: apply consistent code formatting and spacing
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "board_config.h"
|
||||||
|
|
||||||
#include <KlubhausCore.h>
|
#include <KlubhausCore.h>
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
#include "board_config.h"
|
|
||||||
|
|
||||||
class DisplayDriverTFT : public IDisplayDriver {
|
class DisplayDriverTFT : public IDisplayDriver {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
// Klubhaus Doorbell — ESP32-32E target
|
// Klubhaus Doorbell — ESP32-32E target
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <KlubhausCore.h>
|
#include "DisplayDriverTFT.h"
|
||||||
#include "board_config.h"
|
#include "board_config.h"
|
||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
#include "DisplayDriverTFT.h"
|
|
||||||
|
#include <KlubhausCore.h>
|
||||||
|
|
||||||
DisplayDriverTFT tftDriver;
|
DisplayDriverTFT tftDriver;
|
||||||
DisplayManager display(&tftDriver);
|
DisplayManager display(&tftDriver);
|
||||||
@@ -55,7 +56,8 @@ void loop() {
|
|||||||
TouchEvent evt = display.readTouch();
|
TouchEvent evt = display.readTouch();
|
||||||
if(evt.pressed) {
|
if(evt.pressed) {
|
||||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +65,7 @@ void loop() {
|
|||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
String cmd = Serial.readStringUntil('\n');
|
String cmd = Serial.readStringUntil('\n');
|
||||||
cmd.trim();
|
cmd.trim();
|
||||||
if (cmd.length() > 0) logic.onSerialCommand(cmd);
|
if(cmd.length() > 0)
|
||||||
|
logic.onSerialCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "IDisplayDriver.h"
|
#include "IDisplayDriver.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
class DisplayDriverGFX : public IDisplayDriver {
|
class DisplayDriverGFX : public IDisplayDriver {
|
||||||
public:
|
public:
|
||||||
// ── IDisplayDriver ──
|
// ── IDisplayDriver ──
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#define LGFX_USE_V1
|
#define LGFX_USE_V1
|
||||||
#include <LovyanGFX.hpp>
|
#include <LovyanGFX.hpp>
|
||||||
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
|
|
||||||
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
|
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
|
||||||
|
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
|
||||||
|
|
||||||
// ── Display dimensions ──
|
// ── Display dimensions ──
|
||||||
#define TFT_HOR_RES 800
|
#define TFT_HOR_RES 800
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ DoorbellLogic::DoorbellLogic(DisplayManager* display)
|
|||||||
|
|
||||||
String DoorbellLogic::topicUrl(const char* base) {
|
String DoorbellLogic::topicUrl(const char* base) {
|
||||||
String suffix = _debug ? "_test" : "";
|
String suffix = _debug ? "_test" : "";
|
||||||
return String("https://") + NTFY_SERVER + "/" + base + suffix
|
return String("https://") + NTFY_SERVER + "/" + base + suffix + "/json?since=20s&poll=1";
|
||||||
+ "/json?since=20s&poll=1";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Lifecycle ───────────────────────────────────────────────
|
// ── Lifecycle ───────────────────────────────────────────────
|
||||||
|
|
||||||
void DoorbellLogic::begin(const char* version, const char* boardName,
|
void DoorbellLogic::begin(
|
||||||
const WiFiCred* creds, int credCount) {
|
const char* version, const char* boardName, const WiFiCred* creds, int credCount) {
|
||||||
_version = version;
|
_version = version;
|
||||||
_board = boardName;
|
_board = boardName;
|
||||||
#ifdef DEBUG_MODE
|
#ifdef DEBUG_MODE
|
||||||
@@ -23,7 +22,8 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
|
|||||||
|
|
||||||
Serial.println(F("========================================"));
|
Serial.println(F("========================================"));
|
||||||
Serial.printf(" KLUBHAUS ALERT v%s — %s\n", _version, _board);
|
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"));
|
Serial.println(F("========================================\n"));
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
@@ -34,8 +34,7 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
|
|||||||
|
|
||||||
if(_net.isConnected()) {
|
if(_net.isConnected()) {
|
||||||
_net.syncNTP();
|
_net.syncNTP();
|
||||||
Serial.printf("[NET] WiFi:%s RSSI:%d IP:%s\n",
|
Serial.printf("[NET] WiFi:%s RSSI:%d IP:%s\n", _net.getSSID().c_str(), _net.getRSSI(),
|
||||||
_net.getSSID().c_str(), _net.getRSSI(),
|
|
||||||
_net.getIP().c_str());
|
_net.getIP().c_str());
|
||||||
_net.dnsCheck(NTFY_SERVER);
|
_net.dnsCheck(NTFY_SERVER);
|
||||||
_net.tlsCheck(NTFY_SERVER);
|
_net.tlsCheck(NTFY_SERVER);
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "ScreenState.h"
|
|
||||||
#include "DisplayManager.h"
|
#include "DisplayManager.h"
|
||||||
#include "NetManager.h"
|
#include "NetManager.h"
|
||||||
|
#include "ScreenState.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
class DoorbellLogic {
|
class DoorbellLogic {
|
||||||
public:
|
public:
|
||||||
explicit DoorbellLogic(DisplayManager* display);
|
explicit DoorbellLogic(DisplayManager* display);
|
||||||
|
|
||||||
/// Call from setup(). Pass board-specific WiFi creds.
|
/// Call from setup(). Pass board-specific WiFi creds.
|
||||||
void begin(const char* version, const char* boardName,
|
void begin(const char* version, const char* boardName, const WiFiCred* creds, int credCount);
|
||||||
const WiFiCred* creds, int credCount);
|
|
||||||
/// Call from loop() — polls topics, runs timers, transitions state.
|
/// Call from loop() — polls topics, runs timers, transitions state.
|
||||||
void update();
|
void update();
|
||||||
/// Transition out of BOOTED → SILENT. Call at end of setup().
|
/// Transition out of BOOTED → SILENT. Call at end of setup().
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
// Umbrella header — board sketches just #include <KlubhausCore.h>
|
// Umbrella header — board sketches just #include <KlubhausCore.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "ScreenState.h"
|
|
||||||
#include "IDisplayDriver.h"
|
|
||||||
#include "DisplayManager.h"
|
#include "DisplayManager.h"
|
||||||
#include "NetManager.h"
|
|
||||||
#include "DoorbellLogic.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);
|
delay(250);
|
||||||
}
|
}
|
||||||
Serial.printf("[WIFI] Connected: %s %s\n",
|
Serial.printf("[WIFI] Connected: %s %s\n", getSSID().c_str(), getIP().c_str());
|
||||||
getSSID().c_str(), getIP().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetManager::checkConnection() {
|
bool NetManager::checkConnection() {
|
||||||
if (WiFi.status() == WL_CONNECTED) return true;
|
if(WiFi.status() == WL_CONNECTED)
|
||||||
|
return true;
|
||||||
Serial.println("[WIFI] Reconnecting...");
|
Serial.println("[WIFI] Reconnecting...");
|
||||||
return _multi.run(WIFI_CONNECT_TIMEOUT_MS) == WL_CONNECTED;
|
return _multi.run(WIFI_CONNECT_TIMEOUT_MS) == WL_CONNECTED;
|
||||||
}
|
}
|
||||||
@@ -35,12 +35,12 @@ int NetManager::getRSSI() { return WiFi.RSSI(); }
|
|||||||
|
|
||||||
bool NetManager::syncNTP() {
|
bool NetManager::syncNTP() {
|
||||||
Serial.println("[NTP] Starting sync...");
|
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->begin();
|
||||||
_ntp->forceUpdate();
|
_ntp->forceUpdate();
|
||||||
_ntpReady = _ntp->isTimeSet();
|
_ntpReady = _ntp->isTimeSet();
|
||||||
Serial.printf("[NTP] %s: %s UTC\n",
|
Serial.printf("[NTP] %s: %s UTC\n", _ntpReady ? "Synced" : "FAILED",
|
||||||
_ntpReady ? "Synced" : "FAILED",
|
|
||||||
_ntpReady ? _ntp->getFormattedTime().c_str() : "--");
|
_ntpReady ? _ntp->getFormattedTime().c_str() : "--");
|
||||||
return _ntpReady;
|
return _ntpReady;
|
||||||
}
|
}
|
||||||
@@ -54,8 +54,7 @@ String NetManager::getTimeStr() {
|
|||||||
bool NetManager::dnsCheck(const char* host) {
|
bool NetManager::dnsCheck(const char* host) {
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
bool ok = WiFi.hostByName(host, ip);
|
bool ok = WiFi.hostByName(host, ip);
|
||||||
Serial.printf("[NET] DNS %s: %s\n", ok ? "OK" : "FAIL",
|
Serial.printf("[NET] DNS %s: %s\n", ok ? "OK" : "FAIL", ok ? ip.toString().c_str() : "");
|
||||||
ok ? ip.toString().c_str() : "");
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +63,8 @@ bool NetManager::tlsCheck(const char* host) {
|
|||||||
c.setInsecure();
|
c.setInsecure();
|
||||||
c.setTimeout(HTTP_TIMEOUT_MS);
|
c.setTimeout(HTTP_TIMEOUT_MS);
|
||||||
bool ok = c.connect(host, 443);
|
bool ok = c.connect(host, 443);
|
||||||
if (ok) c.stop();
|
if(ok)
|
||||||
|
c.stop();
|
||||||
Serial.printf("[NET] TLS %s\n", ok ? "OK" : "FAIL");
|
Serial.printf("[NET] TLS %s\n", ok ? "OK" : "FAIL");
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,8 @@ int NetManager::httpGet(const char* url, String& response) {
|
|||||||
http.begin(client, url);
|
http.begin(client, url);
|
||||||
|
|
||||||
int code = http.GET();
|
int code = http.GET();
|
||||||
if (code > 0) response = http.getString();
|
if(code > 0)
|
||||||
|
response = http.getString();
|
||||||
http.end();
|
http.end();
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFi.h>
|
|
||||||
#include <WiFiMulti.h>
|
|
||||||
#include <WiFiClientSecure.h>
|
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
#include <WiFiMulti.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
class NetManager {
|
class NetManager {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,19 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
enum class DeviceState {
|
enum class DeviceState { BOOTED, SILENT, ALERTING, SILENCED };
|
||||||
BOOTED,
|
|
||||||
SILENT,
|
|
||||||
ALERTING,
|
|
||||||
SILENCED
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ScreenID {
|
enum class ScreenID { BOOT, OFF, ALERT, DASHBOARD };
|
||||||
BOOT,
|
|
||||||
OFF,
|
|
||||||
ALERT,
|
|
||||||
DASHBOARD
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ScreenState {
|
struct ScreenState {
|
||||||
DeviceState deviceState = DeviceState::BOOTED;
|
DeviceState deviceState = DeviceState::BOOTED;
|
||||||
@@ -35,8 +25,7 @@ struct ScreenState {
|
|||||||
bool showDashboard = false;
|
bool showDashboard = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char* deviceStateStr(DeviceState s)
|
inline const char* deviceStateStr(DeviceState s) {
|
||||||
{
|
|
||||||
switch(s) {
|
switch(s) {
|
||||||
case DeviceState::BOOTED:
|
case DeviceState::BOOTED:
|
||||||
return "BOOTED";
|
return "BOOTED";
|
||||||
@@ -50,8 +39,7 @@ inline const char* deviceStateStr(DeviceState s)
|
|||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char* screenIdStr(ScreenID s)
|
inline const char* screenIdStr(ScreenID s) {
|
||||||
{
|
|
||||||
switch(s) {
|
switch(s) {
|
||||||
case ScreenID::BOOT:
|
case ScreenID::BOOT:
|
||||||
return "BOOT";
|
return "BOOT";
|
||||||
|
|||||||
Reference in New Issue
Block a user