v.0.2.2 ColorSerial, usage

This commit is contained in:
tiijay
2025-11-09 14:13:01 +01:00
parent 9d29dcd542
commit b501f2d0d2
3 changed files with 82 additions and 13 deletions

View File

@@ -165,7 +165,7 @@ void ColorSerial::data(const char *label, int value, const char *unit)
data(label, buf, 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; const char *color;
if (temp < 0) if (temp < 0)
@@ -185,7 +185,7 @@ void ColorSerial::temperature(float temp, const char *label)
Serial.print(RESET); Serial.print(RESET);
Serial.print(color); Serial.print(color);
Serial.print(temp, 1); Serial.print(temp, 1);
Serial.print("°C"); Serial.print(temp_unit);
Serial.print(RESET); Serial.print(RESET);
Serial.println(); Serial.println();
} }
@@ -257,7 +257,7 @@ void ColorSerial::progressBar(int percent, const char *label, int width)
} }
// Section Headers // 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 titleLen = strlen(title);
int padding = (width - titleLen - 2) / 2; int padding = (width - titleLen - 2) / 2;
@@ -275,7 +275,7 @@ void ColorSerial::header(const char *title, char decorator, int width)
// Title line // Title line
Serial.print(MAGENTA); Serial.print(MAGENTA);
Serial.print(""); Serial.print("|");
Serial.print(RESET); Serial.print(RESET);
for (int i = 0; i < padding; i++) for (int i = 0; i < padding; i++)
@@ -298,6 +298,62 @@ void ColorSerial::header(const char *title, char decorator, int width)
Serial.println(); 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) void ColorSerial::subheader(const char *title)
{ {
Serial.print(CYAN); Serial.print(CYAN);

View File

@@ -38,6 +38,12 @@ public:
static const char *ICON_WIFI; static const char *ICON_WIFI;
static const char *ICON_WEATHER; 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 // Main Logging Methods
static void success(const char *message, const char *details = ""); static void success(const char *message, const char *details = "");
static void error(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, const char *value, const char *unit = "");
static void data(const char *label, float 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 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(); static void wifiStatus();
// Progress Bars // Progress Bars
static void progressBar(int percent, const char *label = "", int width = 20); static void progressBar(int percent, const char *label = "", int width = 20);
// Section Headers // Section Headers (mit ASCII Zeichen)
static void header(const char *title, char decorator = '', int width = 40); static void header(const char *title, const char *decorator = "=", int width = 40);
static void subheader(const char *title); static void subheader(const char *title);
static void boxHeader(const char *title, int width = 40); // Alternative mit Box-Zeichen
// Weather Specific // Weather Specific
static void weatherCondition(int code, const char *customLabel = ""); static void weatherCondition(int code, const char *customLabel = "");

View File

@@ -197,7 +197,7 @@ void json_with_WiFiClient()
void json_with_HTTPClient() void json_with_HTTPClient()
{ {
Serial.println("json_with_HTTPClient()"); ColorSerial::debug("json_with_HTTPClient()");
HTTPClient http; HTTPClient http;
@@ -213,13 +213,13 @@ void json_with_HTTPClient()
return; return;
} }
Serial.println("connected to api.open-meteo.com :-)"); ColorSerial::info("connected to api.open-meteo.com :-)");
Serial.println("=== Full Response Complete ==="); ColorSerial::info("=== Full Response Complete ===");
String payload = http.getString(); String payload = http.getString();
http.end(); http.end();
Serial.println(payload); ColorSerial::debug(payload.c_str());
// JSON parsen // JSON parsen
JsonDocument doc; JsonDocument doc;
@@ -233,6 +233,11 @@ void json_with_HTTPClient()
float temperature = current["temperature"]; float temperature = current["temperature"];
String temp_unit = units["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.printf("Temperature: %.1f %s", temperature, temp_unit.c_str());
Serial.println(); Serial.println();
} }
@@ -255,17 +260,18 @@ void setup()
delay(10); delay(10);
ColorSerial::header("PICO W WEATHER STATION"); ColorSerial::header("PICO W WEATHER STATION");
ColorSerial::boxHeader("PICO W WEATHER STATION");
ColorSerial::info("System starting up", "v1.0"); ColorSerial::info("System starting up", "v1.0");
connect_wifi(); connect_wifi();
if (WiFi.status() == WL_CONNECTED) if (WiFi.status() == WL_CONNECTED)
{ {
json_with_WiFiClient(); // json_with_WiFiClient();
json_with_HTTPClient(); json_with_HTTPClient();
} }
else else
{ {
Serial.println("WiFi NOT connected."); ColorSerial::warning("WiFi NOT connected.");
} }
setupMatrix(); setupMatrix();