From b501f2d0d2786b91ad5721b48c7ad0f53a02e518 Mon Sep 17 00:00:00 2001 From: tiijay Date: Sun, 9 Nov 2025 14:13:01 +0100 Subject: [PATCH] v.0.2.2 ColorSerial, usage --- lib/Utils/src/ColorSerial.cpp | 64 ++++++++++++++++++++++++++++++++--- lib/Utils/src/ColorSerial.h | 13 +++++-- src/main.cpp | 18 ++++++---- 3 files changed, 82 insertions(+), 13 deletions(-) diff --git a/lib/Utils/src/ColorSerial.cpp b/lib/Utils/src/ColorSerial.cpp index 7910f3e..fa79209 100644 --- a/lib/Utils/src/ColorSerial.cpp +++ b/lib/Utils/src/ColorSerial.cpp @@ -165,7 +165,7 @@ void ColorSerial::data(const char *label, int value, const char *unit) data(label, buf, unit); } -void ColorSerial::temperature(float temp, const char *label) +void ColorSerial::temperature(float temp, const char *temp_unit, const char *label) { const char *color; if (temp < 0) @@ -185,7 +185,7 @@ void ColorSerial::temperature(float temp, const char *label) Serial.print(RESET); Serial.print(color); Serial.print(temp, 1); - Serial.print("°C"); + Serial.print(temp_unit); Serial.print(RESET); Serial.println(); } @@ -257,7 +257,7 @@ void ColorSerial::progressBar(int percent, const char *label, int width) } // Section Headers -void ColorSerial::header(const char *title, char decorator, int width) +void ColorSerial::header(const char *title, const char *decorator, int width) { int titleLen = strlen(title); int padding = (width - titleLen - 2) / 2; @@ -275,7 +275,7 @@ void ColorSerial::header(const char *title, char decorator, int width) // Title line Serial.print(MAGENTA); - Serial.print("║"); + Serial.print("|"); Serial.print(RESET); for (int i = 0; i < padding; i++) @@ -298,6 +298,62 @@ void ColorSerial::header(const char *title, char decorator, int width) Serial.println(); } +void ColorSerial::boxHeader(const char *title, int width) +{ + int titleLen = strlen(title); + int padding = (width - titleLen - 4) / 2; // -4 für die Box-Ränder + + Serial.println(); + + // Top line + Serial.print(MAGENTA); + Serial.print("╔"); + for (int i = 0; i < width - 2; i++) + { + Serial.print("═"); + } + Serial.print("╗"); + Serial.print(RESET); + Serial.println(); + + // Title line + Serial.print(MAGENTA); + Serial.print("║"); + Serial.print(RESET); + + for (int i = 0; i < padding; i++) + { + Serial.print(" "); + } + + Serial.print(BOLD); + Serial.print(title); + Serial.print(RESET); + + // Padding nach dem Titel + // for (int i = 0; i < (width - titleLen - padding - 4); i++) + for (int i = 0; i < (width - titleLen - padding - 2); i++) + { + Serial.print(" "); + } + + Serial.print(MAGENTA); + Serial.print("║"); + Serial.print(RESET); + Serial.println(); + + // Bottom line + Serial.print(MAGENTA); + Serial.print("╚"); + for (int i = 0; i < width - 2; i++) + { + Serial.print("═"); + } + Serial.print("╝"); + Serial.print(RESET); + Serial.println(); +} + void ColorSerial::subheader(const char *title) { Serial.print(CYAN); diff --git a/lib/Utils/src/ColorSerial.h b/lib/Utils/src/ColorSerial.h index 3cdc1a3..2dbce54 100644 --- a/lib/Utils/src/ColorSerial.h +++ b/lib/Utils/src/ColorSerial.h @@ -38,6 +38,12 @@ public: static const char *ICON_WIFI; static const char *ICON_WEATHER; + // Box Drawing Characters (als const char*) + static const char *BOX_DOUBLE_HORIZ; + static const char *BOX_SINGLE_HORIZ; + static const char *BOX_DOUBLE_VERT; + static const char *BOX_SINGLE_VERT; + // Main Logging Methods static void success(const char *message, const char *details = ""); static void error(const char *message, const char *details = ""); @@ -49,15 +55,16 @@ public: static void data(const char *label, const char *value, const char *unit = ""); static void data(const char *label, float value, const char *unit = ""); static void data(const char *label, int value, const char *unit = ""); - static void temperature(float temp, const char *label = "Temperature"); + static void temperature(float temp, const char *temp_unit = "°C", const char *label = "Temperature"); static void wifiStatus(); // Progress Bars static void progressBar(int percent, const char *label = "", int width = 20); - // Section Headers - static void header(const char *title, char decorator = '═', int width = 40); + // Section Headers (mit ASCII Zeichen) + static void header(const char *title, const char *decorator = "=", int width = 40); static void subheader(const char *title); + static void boxHeader(const char *title, int width = 40); // Alternative mit Box-Zeichen // Weather Specific static void weatherCondition(int code, const char *customLabel = ""); diff --git a/src/main.cpp b/src/main.cpp index 0de1db5..77aa70b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,7 +197,7 @@ void json_with_WiFiClient() void json_with_HTTPClient() { - Serial.println("json_with_HTTPClient()"); + ColorSerial::debug("json_with_HTTPClient()"); HTTPClient http; @@ -213,13 +213,13 @@ void json_with_HTTPClient() return; } - Serial.println("connected to api.open-meteo.com :-)"); - Serial.println("=== Full Response Complete ==="); + ColorSerial::info("connected to api.open-meteo.com :-)"); + ColorSerial::info("=== Full Response Complete ==="); String payload = http.getString(); http.end(); - Serial.println(payload); + ColorSerial::debug(payload.c_str()); // JSON parsen JsonDocument doc; @@ -233,6 +233,11 @@ void json_with_HTTPClient() float temperature = current["temperature"]; String temp_unit = units["temperature"]; + ColorSerial::temperature(temperature, temp_unit.c_str()); + + String temp_msg = "Temperature: " + String(temperature, 1) + temp_unit.c_str(); + + ColorSerial::info(temp_msg.c_str(), "Anzeige Temperatur Wert"); Serial.printf("Temperature: %.1f %s", temperature, temp_unit.c_str()); Serial.println(); } @@ -255,17 +260,18 @@ void setup() delay(10); ColorSerial::header("PICO W WEATHER STATION"); + ColorSerial::boxHeader("PICO W WEATHER STATION"); ColorSerial::info("System starting up", "v1.0"); connect_wifi(); if (WiFi.status() == WL_CONNECTED) { - json_with_WiFiClient(); + // json_with_WiFiClient(); json_with_HTTPClient(); } else { - Serial.println("WiFi NOT connected."); + ColorSerial::warning("WiFi NOT connected."); } setupMatrix();