style: apply consistent code formatting and spacing

This commit is contained in:
2026-02-17 04:15:48 -08:00
parent f39364f67f
commit 8e9bd18676
13 changed files with 217 additions and 223 deletions

View File

@@ -1,29 +1,29 @@
#include "DoorbellLogic.h"
DoorbellLogic::DoorbellLogic(DisplayManager* display)
: _display(display) {}
: _display(display) { }
// ── URL builder ─────────────────────────────────────────────
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;
_board = boardName;
#ifdef DEBUG_MODE
_debug = true;
#endif
Serial.println(F("========================================"));
Serial.printf( " KLUBHAUS ALERT v%s — %s\n", _version, _board);
if (_debug) Serial.println(F(" *** DEBUG MODE — _test topics ***"));
Serial.printf(" KLUBHAUS ALERT v%s — %s\n", _version, _board);
if(_debug)
Serial.println(F(" *** DEBUG MODE — _test topics ***"));
Serial.println(F("========================================\n"));
// Display
@@ -32,21 +32,20 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
// Network
_net.begin(creds, credCount);
if (_net.isConnected()) {
if(_net.isConnected()) {
_net.syncNTP();
Serial.printf("[NET] WiFi:%s RSSI:%d IP:%s\n",
_net.getSSID().c_str(), _net.getRSSI(),
_net.getIP().c_str());
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);
}
// Topic URLs
_alertUrl = topicUrl(ALERT_TOPIC);
_alertUrl = topicUrl(ALERT_TOPIC);
_silenceUrl = topicUrl(SILENCE_TOPIC);
_adminUrl = topicUrl(ADMIN_TOPIC);
String sfx = _debug ? "_test" : "";
_statusUrl = String("https://") + NTFY_SERVER + "/" + STATUS_TOPIC + sfx;
_adminUrl = topicUrl(ADMIN_TOPIC);
String sfx = _debug ? "_test" : "";
_statusUrl = String("https://") + NTFY_SERVER + "/" + STATUS_TOPIC + sfx;
Serial.printf("[CONFIG] ALERT_URL: %s\n", _alertUrl.c_str());
Serial.printf("[CONFIG] SILENCE_URL: %s\n", _silenceUrl.c_str());

View File

@@ -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().
@@ -38,16 +38,16 @@ private:
String topicUrl(const char* base);
DisplayManager* _display;
NetManager _net;
ScreenState _state;
NetManager _net;
ScreenState _state;
const char* _version = "";
const char* _board = "";
bool _debug = false;
const char* _version = "";
const char* _board = "";
bool _debug = false;
uint32_t _lastPollMs = 0;
uint32_t _lastPollMs = 0;
uint32_t _lastHeartbeatMs = 0;
uint32_t _bootGraceEnd = 0;
uint32_t _bootGraceEnd = 0;
String _alertUrl;
String _silenceUrl;

View File

@@ -3,15 +3,15 @@
struct TouchEvent {
bool pressed = false;
int x = 0;
int y = 0;
int x = 0;
int y = 0;
};
struct HoldState {
bool active = false;
bool started = false;
bool completed = false;
float progress = 0.0f; // 0.0 1.0
bool active = false;
bool started = false;
bool completed = false;
float progress = 0.0f; // 0.0 1.0
};
/// Abstract display driver — implemented per-board.
@@ -28,12 +28,12 @@ public:
// ── Touch ──
virtual TouchEvent readTouch() = 0;
/// Returns tile index at (x,y), or -1 if none.
virtual int dashboardTouch(int x, int y) = 0;
virtual int dashboardTouch(int x, int y) = 0;
/// 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(int x, int y) = 0;
virtual int width() = 0;
virtual int width() = 0;
virtual int height() = 0;
};

View File

@@ -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"

View File

@@ -4,44 +4,44 @@
void NetManager::begin(const WiFiCred* creds, int count) {
WiFi.mode(WIFI_STA);
for (int i = 0; i < count; i++)
for(int i = 0; i < count; i++)
_multi.addAP(creds[i].ssid, creds[i].pass);
Serial.println("[WIFI] Connecting...");
unsigned long t0 = millis();
while (_multi.run() != WL_CONNECTED) {
if (millis() - t0 > WIFI_CONNECT_TIMEOUT_MS) {
while(_multi.run() != WL_CONNECTED) {
if(millis() - t0 > WIFI_CONNECT_TIMEOUT_MS) {
Serial.println("[WIFI] Timeout!");
return;
}
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;
}
bool NetManager::isConnected() { return WiFi.status() == WL_CONNECTED; }
String NetManager::getSSID() { return WiFi.SSID(); }
String NetManager::getIP() { return WiFi.localIP().toString(); }
int NetManager::getRSSI() { return WiFi.RSSI(); }
bool NetManager::isConnected() { return WiFi.status() == WL_CONNECTED; }
String NetManager::getSSID() { return WiFi.SSID(); }
String NetManager::getIP() { return WiFi.localIP().toString(); }
int NetManager::getRSSI() { return WiFi.RSSI(); }
// ── NTP ─────────────────────────────────────────────────────
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",
_ntpReady ? _ntp->getFormattedTime().c_str() : "--");
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;
}

View File

@@ -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:
@@ -16,9 +17,9 @@ public:
String getSSID();
String getIP();
int getRSSI();
int getRSSI();
bool syncNTP();
bool syncNTP();
String getTimeStr();
bool dnsCheck(const char* host);
@@ -30,8 +31,8 @@ public:
int httpPost(const char* url, const String& body);
private:
WiFiMulti _multi;
WiFiUDP _udp;
NTPClient* _ntp = nullptr;
bool _ntpReady = false;
WiFiMulti _multi;
WiFiUDP _udp;
NTPClient* _ntp = nullptr;
bool _ntpReady = false;
};

View File

@@ -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;
@@ -35,9 +25,8 @@ struct ScreenState {
bool showDashboard = false;
};
inline const char* deviceStateStr(DeviceState s)
{
switch (s) {
inline const char* deviceStateStr(DeviceState s) {
switch(s) {
case DeviceState::BOOTED:
return "BOOTED";
case DeviceState::SILENT:
@@ -50,9 +39,8 @@ inline const char* deviceStateStr(DeviceState s)
return "?";
}
inline const char* screenIdStr(ScreenID s)
{
switch (s) {
inline const char* screenIdStr(ScreenID s) {
switch(s) {
case ScreenID::BOOT:
return "BOOT";
case ScreenID::OFF: