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,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:

View File

@@ -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);
@@ -31,19 +32,19 @@ void loop() {
static int holdStartX = -1;
static int holdStartY = -1;
if (st.deviceState == DeviceState::ALERTING) {
if(st.deviceState == DeviceState::ALERTING) {
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
if (h.completed) {
if(h.completed) {
logic.silenceAlert();
holdStartX = -1;
holdStartY = -1;
}
if (h.started) {
if(h.started) {
TouchEvent t = display.readTouch();
holdStartX = t.x;
holdStartY = t.y;
}
if (!h.active && holdStartX >= 0) {
if(!h.active && holdStartX >= 0) {
display.updateHint(holdStartX, holdStartY);
}
} else {
@@ -51,18 +52,20 @@ void loop() {
holdStartY = -1;
}
if (st.screen == ScreenID::DASHBOARD) {
if(st.screen == ScreenID::DASHBOARD) {
TouchEvent evt = display.readTouch();
if (evt.pressed) {
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);
}
}
// ── Serial console ──
if (Serial.available()) {
if(Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if (cmd.length() > 0) logic.onSerialCommand(cmd);
if(cmd.length() > 0)
logic.onSerialCommand(cmd);
}
}

View File

@@ -1,8 +1,9 @@
#pragma once
#include <Arduino.h>
#include "IDisplayDriver.h"
#include <Arduino.h>
class DisplayDriverGFX : public IDisplayDriver {
public:
// ── IDisplayDriver ──
@@ -27,7 +28,7 @@ private:
void drawDashboard(const ScreenState& state);
// Touch handling
TouchEvent _lastTouch = {false, 0, 0};
TouchEvent _lastTouch = { false, 0, 0 };
unsigned long _pressStartMs = 0;
bool _isHolding = false;

View File

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

View File

@@ -1,20 +1,19 @@
#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;
#ifdef DEBUG_MODE
@@ -22,8 +21,9 @@ void DoorbellLogic::begin(const char* version, const char* boardName,
#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,10 +32,9 @@ 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(),
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);

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().

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,24 +4,24 @@
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;
}
@@ -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;
}

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:

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: