From 8e9bd186762a3c8dc5a2874f42a3a284e378ccf7 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 17 Feb 2026 04:15:48 -0800 Subject: [PATCH] style: apply consistent code formatting and spacing --- boards/esp32-32e/DisplayDriverTFT.h | 15 +- boards/esp32-32e/board_config.h | 10 +- boards/esp32-32e/esp32-32e.ino | 29 +-- boards/esp32-32e/tft_user_setup.h | 20 +- boards/esp32-s3-lcd-43/DisplayDriverGFX.h | 5 +- boards/esp32-s3-lcd-43/LovyanPins.h | 202 +++++++++---------- libraries/KlubhausCore/src/DoorbellLogic.cpp | 31 ++- libraries/KlubhausCore/src/DoorbellLogic.h | 24 +-- libraries/KlubhausCore/src/IDisplayDriver.h | 16 +- libraries/KlubhausCore/src/KlubhausCore.h | 6 +- libraries/KlubhausCore/src/NetManager.cpp | 37 ++-- libraries/KlubhausCore/src/NetManager.h | 21 +- libraries/KlubhausCore/src/ScreenState.h | 24 +-- 13 files changed, 217 insertions(+), 223 deletions(-) diff --git a/boards/esp32-32e/DisplayDriverTFT.h b/boards/esp32-32e/DisplayDriverTFT.h index 3a3b5f1..268501e 100644 --- a/boards/esp32-32e/DisplayDriverTFT.h +++ b/boards/esp32-32e/DisplayDriverTFT.h @@ -1,8 +1,9 @@ #pragma once +#include "board_config.h" + #include #include -#include "board_config.h" class DisplayDriverTFT : public IDisplayDriver { public: @@ -10,11 +11,11 @@ public: void setBacklight(bool on) override; void render(const ScreenState& state) override; TouchEvent readTouch() override; - int dashboardTouch(int x, int y) override; + int dashboardTouch(int x, int y) override; HoldState updateHold(unsigned long holdMs) override; void updateHint(int x, int y) override; - int width() override { return DISPLAY_WIDTH; } - int height() override { return DISPLAY_HEIGHT; } + int width() override { return DISPLAY_WIDTH; } + int height() override { return DISPLAY_HEIGHT; } private: void drawBoot(); @@ -23,8 +24,8 @@ private: TFT_eSPI _tft; - bool _holdActive = false; + bool _holdActive = false; uint32_t _holdStartMs = 0; - ScreenID _lastScreen = ScreenID::BOOT; - bool _needsRedraw = true; + ScreenID _lastScreen = ScreenID::BOOT; + bool _needsRedraw = true; }; diff --git a/boards/esp32-32e/board_config.h b/boards/esp32-32e/board_config.h index 7700ce0..06a9ecc 100644 --- a/boards/esp32-32e/board_config.h +++ b/boards/esp32-32e/board_config.h @@ -1,6 +1,6 @@ #pragma once -#define BOARD_NAME "WS_32E" +#define BOARD_NAME "WS_32E" // ══════════════════════════════════════════════════════════ // TODO: Set these to match YOUR display + wiring. @@ -9,12 +9,12 @@ // (which gets copied into the vendored TFT_eSPI library). // ══════════════════════════════════════════════════════════ -#define DISPLAY_WIDTH 320 -#define DISPLAY_HEIGHT 240 -#define DISPLAY_ROTATION 1 // landscape +#define DISPLAY_WIDTH 320 +#define DISPLAY_HEIGHT 240 +#define DISPLAY_ROTATION 1 // landscape // Backlight GPIO (directly wired) -#define PIN_LCD_BL 22 +#define PIN_LCD_BL 22 // Touch — if using XPT2046 via TFT_eSPI, set TOUCH_CS in tft_user_setup.h // If using capacitive touch (e.g. FT6236), configure I2C pins here: diff --git a/boards/esp32-32e/esp32-32e.ino b/boards/esp32-32e/esp32-32e.ino index 5e4cfa2..0241647 100644 --- a/boards/esp32-32e/esp32-32e.ino +++ b/boards/esp32-32e/esp32-32e.ino @@ -2,14 +2,15 @@ // Klubhaus Doorbell — ESP32-32E target // -#include +#include "DisplayDriverTFT.h" #include "board_config.h" #include "secrets.h" -#include "DisplayDriverTFT.h" + +#include DisplayDriverTFT tftDriver; -DisplayManager display(&tftDriver); -DoorbellLogic logic(&display); +DisplayManager display(&tftDriver); +DoorbellLogic logic(&display); void setup() { Serial.begin(115200); @@ -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); } } diff --git a/boards/esp32-32e/tft_user_setup.h b/boards/esp32-32e/tft_user_setup.h index ff824e8..a0bb314 100644 --- a/boards/esp32-32e/tft_user_setup.h +++ b/boards/esp32-32e/tft_user_setup.h @@ -11,27 +11,27 @@ // ── Resolution ── // FIXED: Match board_config.h (320x240 landscape) -#define TFT_WIDTH 320 +#define TFT_WIDTH 320 #define TFT_HEIGHT 240 // ── SPI Pins ── -#define TFT_MOSI 23 -#define TFT_SCLK 18 -#define TFT_CS 5 -#define TFT_DC 27 -#define TFT_RST 33 +#define TFT_MOSI 23 +#define TFT_SCLK 18 +#define TFT_CS 5 +#define TFT_DC 27 +#define TFT_RST 33 // ── Backlight (optional, can also use GPIO directly) ── // #define TFT_BL 22 // #define TFT_BACKLIGHT_ON HIGH // ── Touch (XPT2046 resistive) ── -#define TOUCH_CS 14 +#define TOUCH_CS 14 // ── SPI speed ── -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 20000000 -#define SPI_TOUCH_FREQUENCY 2500000 +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 20000000 +#define SPI_TOUCH_FREQUENCY 2500000 // ── Misc ── #define LOAD_GLCD diff --git a/boards/esp32-s3-lcd-43/DisplayDriverGFX.h b/boards/esp32-s3-lcd-43/DisplayDriverGFX.h index ae06c29..61d4d3c 100644 --- a/boards/esp32-s3-lcd-43/DisplayDriverGFX.h +++ b/boards/esp32-s3-lcd-43/DisplayDriverGFX.h @@ -1,8 +1,9 @@ #pragma once -#include #include "IDisplayDriver.h" +#include + 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; diff --git a/boards/esp32-s3-lcd-43/LovyanPins.h b/boards/esp32-s3-lcd-43/LovyanPins.h index 1c7c3e3..477940b 100644 --- a/boards/esp32-s3-lcd-43/LovyanPins.h +++ b/boards/esp32-s3-lcd-43/LovyanPins.h @@ -2,117 +2,117 @@ #define LGFX_USE_V1 #include -#include #include +#include // ── Display dimensions ── -#define TFT_HOR_RES 800 -#define TFT_VER_RES 480 +#define TFT_HOR_RES 800 +#define TFT_VER_RES 480 // ── Touch I2C (from Westcott example) ── -#define TOUCH_SDA 8 -#define TOUCH_SCL 9 -#define TOUCH_INT 4 -#define TOUCH_RST -1 +#define TOUCH_SDA 8 +#define TOUCH_SCL 9 +#define TOUCH_INT 4 +#define TOUCH_RST -1 // ── CH422G Expander pins ── -#define TP_RST 1 -#define LCD_BL 2 -#define LCD_RST 3 -#define SD_CS 4 -#define USB_SEL 5 +#define TP_RST 1 +#define LCD_BL 2 +#define LCD_RST 3 +#define SD_CS 4 +#define USB_SEL 5 class LGFX : public lgfx::LGFX_Device { public: - lgfx::Bus_RGB _bus_instance; - lgfx::Panel_RGB _panel_instance; - lgfx::Touch_GT911 _touch_instance; + lgfx::Bus_RGB _bus_instance; + lgfx::Panel_RGB _panel_instance; + lgfx::Touch_GT911 _touch_instance; - LGFX(void) { - // Panel config - { - auto cfg = _panel_instance.config(); - cfg.memory_width = TFT_HOR_RES; - cfg.memory_height = TFT_VER_RES; - cfg.panel_width = TFT_HOR_RES; - cfg.panel_height = TFT_VER_RES; - cfg.offset_x = 0; - cfg.offset_y = 0; - _panel_instance.config(cfg); + LGFX(void) { + // Panel config + { + auto cfg = _panel_instance.config(); + cfg.memory_width = TFT_HOR_RES; + cfg.memory_height = TFT_VER_RES; + cfg.panel_width = TFT_HOR_RES; + cfg.panel_height = TFT_VER_RES; + cfg.offset_x = 0; + cfg.offset_y = 0; + _panel_instance.config(cfg); + } + + // RGB parallel bus config (from Westcott) + { + auto cfg = _bus_instance.config(); + cfg.panel = &_panel_instance; + + // Blue channel + cfg.pin_d0 = 14; + cfg.pin_d1 = 38; + cfg.pin_d2 = 18; + cfg.pin_d3 = 17; + cfg.pin_d4 = 10; + + // Green channel + cfg.pin_d5 = 39; + cfg.pin_d6 = 0; + cfg.pin_d7 = 45; + cfg.pin_d8 = 48; + cfg.pin_d9 = 47; + cfg.pin_d10 = 21; + + // Red channel + cfg.pin_d11 = 1; + cfg.pin_d12 = 2; + cfg.pin_d13 = 42; + cfg.pin_d14 = 41; + cfg.pin_d15 = 40; + + // Timing + cfg.pin_henable = 5; + cfg.pin_vsync = 3; + cfg.pin_hsync = 46; + cfg.pin_pclk = 7; + cfg.freq_write = 14000000; + + cfg.hsync_polarity = 0; + cfg.hsync_front_porch = 20; + cfg.hsync_pulse_width = 10; + cfg.hsync_back_porch = 10; + + cfg.vsync_polarity = 0; + cfg.vsync_front_porch = 10; + cfg.vsync_pulse_width = 10; + cfg.vsync_back_porch = 10; + + cfg.pclk_active_neg = 0; + cfg.de_idle_high = 0; + cfg.pclk_idle_high = 0; + + _bus_instance.config(cfg); + } + _panel_instance.setBus(&_bus_instance); + + // Touch config (I2C port 1, address 0x14 - from Westcott!) + { + auto cfg = _touch_instance.config(); + cfg.x_min = 0; + cfg.x_max = TFT_HOR_RES - 1; + cfg.y_min = 0; + cfg.y_max = TFT_VER_RES - 1; + cfg.pin_int = TOUCH_INT; + cfg.pin_rst = TOUCH_RST; + cfg.bus_shared = false; + cfg.offset_rotation = 0; + cfg.i2c_port = I2C_NUM_1; // IMPORTANT: Port 1, not 0! + cfg.pin_sda = TOUCH_SDA; + cfg.pin_scl = TOUCH_SCL; + cfg.freq = 400000; + cfg.i2c_addr = 0x14; // IMPORTANT: Address 0x14, not 0x5D! + _touch_instance.config(cfg); + _panel_instance.setTouch(&_touch_instance); + } + + setPanel(&_panel_instance); } - - // RGB parallel bus config (from Westcott) - { - auto cfg = _bus_instance.config(); - cfg.panel = &_panel_instance; - - // Blue channel - cfg.pin_d0 = 14; - cfg.pin_d1 = 38; - cfg.pin_d2 = 18; - cfg.pin_d3 = 17; - cfg.pin_d4 = 10; - - // Green channel - cfg.pin_d5 = 39; - cfg.pin_d6 = 0; - cfg.pin_d7 = 45; - cfg.pin_d8 = 48; - cfg.pin_d9 = 47; - cfg.pin_d10 = 21; - - // Red channel - cfg.pin_d11 = 1; - cfg.pin_d12 = 2; - cfg.pin_d13 = 42; - cfg.pin_d14 = 41; - cfg.pin_d15 = 40; - - // Timing - cfg.pin_henable = 5; - cfg.pin_vsync = 3; - cfg.pin_hsync = 46; - cfg.pin_pclk = 7; - cfg.freq_write = 14000000; - - cfg.hsync_polarity = 0; - cfg.hsync_front_porch = 20; - cfg.hsync_pulse_width = 10; - cfg.hsync_back_porch = 10; - - cfg.vsync_polarity = 0; - cfg.vsync_front_porch = 10; - cfg.vsync_pulse_width = 10; - cfg.vsync_back_porch = 10; - - cfg.pclk_active_neg = 0; - cfg.de_idle_high = 0; - cfg.pclk_idle_high = 0; - - _bus_instance.config(cfg); - } - _panel_instance.setBus(&_bus_instance); - - // Touch config (I2C port 1, address 0x14 - from Westcott!) - { - auto cfg = _touch_instance.config(); - cfg.x_min = 0; - cfg.x_max = TFT_HOR_RES - 1; - cfg.y_min = 0; - cfg.y_max = TFT_VER_RES - 1; - cfg.pin_int = TOUCH_INT; - cfg.pin_rst = TOUCH_RST; - cfg.bus_shared = false; - cfg.offset_rotation = 0; - cfg.i2c_port = I2C_NUM_1; // IMPORTANT: Port 1, not 0! - cfg.pin_sda = TOUCH_SDA; - cfg.pin_scl = TOUCH_SCL; - cfg.freq = 400000; - cfg.i2c_addr = 0x14; // IMPORTANT: Address 0x14, not 0x5D! - _touch_instance.config(cfg); - _panel_instance.setTouch(&_touch_instance); - } - - setPanel(&_panel_instance); - } }; diff --git a/libraries/KlubhausCore/src/DoorbellLogic.cpp b/libraries/KlubhausCore/src/DoorbellLogic.cpp index 1481dee..567fdc0 100644 --- a/libraries/KlubhausCore/src/DoorbellLogic.cpp +++ b/libraries/KlubhausCore/src/DoorbellLogic.cpp @@ -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()); diff --git a/libraries/KlubhausCore/src/DoorbellLogic.h b/libraries/KlubhausCore/src/DoorbellLogic.h index 9164c4b..75711c5 100644 --- a/libraries/KlubhausCore/src/DoorbellLogic.h +++ b/libraries/KlubhausCore/src/DoorbellLogic.h @@ -1,18 +1,18 @@ #pragma once -#include -#include #include "Config.h" -#include "ScreenState.h" #include "DisplayManager.h" #include "NetManager.h" +#include "ScreenState.h" + +#include +#include 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; diff --git a/libraries/KlubhausCore/src/IDisplayDriver.h b/libraries/KlubhausCore/src/IDisplayDriver.h index f1fb617..aad8e37 100644 --- a/libraries/KlubhausCore/src/IDisplayDriver.h +++ b/libraries/KlubhausCore/src/IDisplayDriver.h @@ -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; }; diff --git a/libraries/KlubhausCore/src/KlubhausCore.h b/libraries/KlubhausCore/src/KlubhausCore.h index 4b765ab..66f769d 100644 --- a/libraries/KlubhausCore/src/KlubhausCore.h +++ b/libraries/KlubhausCore/src/KlubhausCore.h @@ -2,8 +2,8 @@ // Umbrella header — board sketches just #include #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" diff --git a/libraries/KlubhausCore/src/NetManager.cpp b/libraries/KlubhausCore/src/NetManager.cpp index 43cf916..0b38d62 100644 --- a/libraries/KlubhausCore/src/NetManager.cpp +++ b/libraries/KlubhausCore/src/NetManager.cpp @@ -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; } diff --git a/libraries/KlubhausCore/src/NetManager.h b/libraries/KlubhausCore/src/NetManager.h index 570f379..9ecca3b 100644 --- a/libraries/KlubhausCore/src/NetManager.h +++ b/libraries/KlubhausCore/src/NetManager.h @@ -1,12 +1,13 @@ #pragma once +#include "Config.h" + #include -#include -#include -#include #include #include +#include +#include +#include #include -#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; }; diff --git a/libraries/KlubhausCore/src/ScreenState.h b/libraries/KlubhausCore/src/ScreenState.h index f9d47ae..0108302 100644 --- a/libraries/KlubhausCore/src/ScreenState.h +++ b/libraries/KlubhausCore/src/ScreenState.h @@ -1,19 +1,9 @@ #pragma once #include -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: