From 4df22f8018c04f94af4da2a4ecbfdb2c2ada0cbf Mon Sep 17 00:00:00 2001 From: David Panusch Date: Sun, 25 Dec 2022 14:58:43 +0100 Subject: [PATCH 01/15] moved mqtt and openWeatherMap Varaibles to own structs --- include/EEPROMAnything.h | 19 ++++++++------- include/Uhr.h | 28 +++++++++++++++------- include/WebPage_Adapter.h | 26 ++++++++++---------- include/mqtt_func.hpp | 2 +- include/openwmap.h | 4 ++-- src/Wortuhr.cpp | 50 +++++++++++++++++++-------------------- 6 files changed, 70 insertions(+), 59 deletions(-) diff --git a/include/EEPROMAnything.h b/include/EEPROMAnything.h index 753cb02f..131f3839 100644 --- a/include/EEPROMAnything.h +++ b/include/EEPROMAnything.h @@ -62,13 +62,14 @@ void eeprom_read() { Serial.printf("LDR : %u\n", G.ldr); Serial.printf("LDRCal : %u\n", G.ldrCal); Serial.printf("Uhrtype : %u\n", G.UhrtypeDef); - Serial.printf("MQTT_State : %u\n", G.MQTT_State); - Serial.printf("MQTT_Server : %s\n", G.MQTT_Server); - Serial.printf("MQTT_User : %s\n", G.MQTT_User); - Serial.printf("MQTT_Pass : %s\n", G.MQTT_Pass); - Serial.printf("MQTT_ClientId : %s\n", G.MQTT_ClientId); - Serial.printf("MQTT_Topic : %s\n", G.MQTT_Topic); - Serial.printf("MQTT_Port : %u\n", G.MQTT_Port); + + Serial.printf("MQTT_State : %u\n", G.mqtt.state); + Serial.printf("MQTT_Server : %s\n", G.mqtt.serverAdress); + Serial.printf("MQTT_User : %s\n", G.mqtt.user); + Serial.printf("MQTT_Pass : %s\n", G.mqtt.password); + Serial.printf("MQTT_ClientId : %s\n", G.mqtt.clientId); + Serial.printf("MQTT_Topic : %s\n", G.mqtt.topic); + Serial.printf("MQTT_Port : %u\n", G.mqtt.port); Serial.printf("autoLdrEnabled : %u\n", G.autoLdrEnabled); Serial.printf("autoLdrBright : %u\n", G.autoLdrBright); @@ -85,9 +86,9 @@ void eeprom_read() { Serial.printf("bootShowIP : %u\n", G.bootShowIP); Serial.printf("Colortype : %u\n", G.Colortype); Serial.print("OWM_apikey: "); - Serial.println(G.apikey); + Serial.println(G.openWeatherMap.apikey); Serial.print("OWM_city : "); - Serial.println(G.cityid); + Serial.println(G.openWeatherMap.cityid); delay(100); } diff --git a/include/Uhr.h b/include/Uhr.h index b51fb8c1..dd89c4d8 100644 --- a/include/Uhr.h +++ b/include/Uhr.h @@ -33,6 +33,21 @@ enum uhrzeit_t { H_ZWOELF = 21 }; +struct MqttData { + uint8_t state; + char serverAdress[PAYLOAD_LENGTH]; + char user[PAYLOAD_LENGTH]; + char password[PAYLOAD_LENGTH]; + char clientId[PAYLOAD_LENGTH]; + char topic[PAYLOAD_LENGTH]; + uint16_t port; +}; + +struct OpenWeatherMapData { + char apikey[35]; + char cityid[8]; +}; + struct GLOBAL { uint8_t sernr; uint16_t prog; @@ -47,8 +62,6 @@ struct GLOBAL { uint8_t hell; uint16_t ldr; uint16_t ldrCal; - char apikey[35]; - char cityid[8]; int geschw; uint8_t client_nr; uint8_t zeige_sek; @@ -69,13 +82,10 @@ struct GLOBAL { uint8_t UhrtypeDef; uint8_t Colortype; - uint8_t MQTT_State; - char MQTT_Server[PAYLOAD_LENGTH]; - char MQTT_User[PAYLOAD_LENGTH]; - char MQTT_Pass[PAYLOAD_LENGTH]; - char MQTT_ClientId[PAYLOAD_LENGTH]; - char MQTT_Topic[PAYLOAD_LENGTH]; - uint16_t MQTT_Port; + + MqttData mqtt; + + OpenWeatherMapData openWeatherMap; uint8_t autoLdrEnabled; uint8_t autoLdrBright; diff --git a/include/WebPage_Adapter.h b/include/WebPage_Adapter.h index 1c87afc5..75f5de60 100644 --- a/include/WebPage_Adapter.h +++ b/include/WebPage_Adapter.h @@ -394,18 +394,18 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, case COMMAND_SET_MQTT: { // MQTT Daten speichern G.conf = COMMAND_SET_MQTT; - G.MQTT_State = split(payload, 3); - G.MQTT_Port = split(payload, 6, 5); + G.mqtt.state = split(payload, 3); + G.mqtt.port = split(payload, 6, 5); uint8_t index_start = 11; - payloadTextHandling(payload, G.MQTT_Server, index_start); + payloadTextHandling(payload, G.mqtt.serverAdress, index_start); index_start += PAYLOAD_LENGTH; - payloadTextHandling(payload, G.MQTT_User, index_start); + payloadTextHandling(payload, G.mqtt.user, index_start); index_start += PAYLOAD_LENGTH; - payloadTextHandling(payload, G.MQTT_Pass, index_start); + payloadTextHandling(payload, G.mqtt.password, index_start); index_start += PAYLOAD_LENGTH; - payloadTextHandling(payload, G.MQTT_ClientId, index_start); + payloadTextHandling(payload, G.mqtt.clientId, index_start); index_start += PAYLOAD_LENGTH; - payloadTextHandling(payload, G.MQTT_Topic, index_start); + payloadTextHandling(payload, G.mqtt.topic, index_start); break; } @@ -451,25 +451,25 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, ii = 0; for (uint8_t k = 3; k < 10; k++) { if (payload[k] != ' ') { - G.cityid[ii] = payload[k]; + G.openWeatherMap.cityid[ii] = payload[k]; ii++; } } - G.cityid[ii] = '\0'; + G.openWeatherMap.cityid[ii] = '\0'; // jj = 0; for (uint8_t l = 11; l < 43; l++) { if (payload[l] != ' ') { - G.apikey[jj] = payload[l]; + G.openWeatherMap.apikey[jj] = payload[l]; jj++; } } - G.apikey[jj] = '\0'; + G.openWeatherMap.apikey[jj] = '\0'; Serial.println("write EEPROM!"); Serial.print("CityID : "); - Serial.println(G.cityid); + Serial.println(G.openWeatherMap.cityid); Serial.print("APIkey : "); - Serial.println(G.apikey); + Serial.println(G.openWeatherMap.apikey); break; } diff --git a/include/mqtt_func.hpp b/include/mqtt_func.hpp index 2aac1c23..ed0aab02 100644 --- a/include/mqtt_func.hpp +++ b/include/mqtt_func.hpp @@ -59,6 +59,6 @@ void MQTT_callback(char *topic, byte *payload, unsigned int length) { } void MQTT_reconnect() { - mqttClient.subscribe(G.MQTT_Topic); + mqttClient.subscribe(G.mqtt.topic); Serial.println("MQTT Connected..."); } diff --git a/include/openwmap.h b/include/openwmap.h index 6798f99d..f290577e 100644 --- a/include/openwmap.h +++ b/include/openwmap.h @@ -15,9 +15,9 @@ void getweather() { // create calling URL memset(resource, 0, sizeof(resource)); strncat(resource, resource1, 22); - strncat(resource, G.cityid, 7); + strncat(resource, G.openWeatherMap.cityid, 7); strncat(resource, resource2, 20); - strncat(resource, G.apikey, 35); + strncat(resource, G.openWeatherMap.apikey, 35); strncat(resource, resource3, 6); Serial.print("Calling URL: "); diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 8cbe244d..21b0bc31 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -270,8 +270,8 @@ void setup() { G.zeige_min = 1; G.ldr = 0; G.ldrCal = 0; - strcpy(G.cityid, ""); - strcpy(G.apikey, ""); + strcpy(G.openWeatherMap.cityid, ""); + strcpy(G.openWeatherMap.apikey, ""); strcpy(G.zeitserver, "europe.pool.ntp.org"); strcpy(G.hostname, "uhr"); strcpy(G.ltext, "HELLO WORLD "); @@ -289,13 +289,13 @@ void setup() { G.Sprachvariation[i] = false; } - G.MQTT_State = 0; - G.MQTT_Port = 1883; - strcpy(G.MQTT_Server, "192.168.4.1"); - strcpy(G.MQTT_User, "User"); - strcpy(G.MQTT_Pass, "Passwort"); - strcpy(G.MQTT_ClientId, "ClientId"); - strcpy(G.MQTT_Topic, "Wortuhr"); + G.mqtt.state = 0; + G.mqtt.port = 1883; + strcpy(G.mqtt.serverAdress, "192.168.4.1"); + strcpy(G.mqtt.user, "User"); + strcpy(G.mqtt.password, "Passwort"); + strcpy(G.mqtt.clientId, "ClientId"); + strcpy(G.mqtt.topic, "Wortuhr"); G.UhrtypeDef = DEFAULT_LAYOUT; G.Colortype = DEFAULT_LEDTYPE; @@ -411,11 +411,11 @@ void setup() { // MQTT //------------------------------------- - if (G.MQTT_State == 1) { - mqttClient.setServer(G.MQTT_Server, G.MQTT_Port); + if (G.mqtt.state == 1) { + mqttClient.setServer(G.mqtt.serverAdress, G.mqtt.port); mqttClient.setCallback(MQTT_callback); - mqttClient.connect(G.MQTT_ClientId, G.MQTT_User, G.MQTT_Pass); - mqttClient.subscribe(G.MQTT_Topic); + mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); + mqttClient.subscribe(G.mqtt.topic); } //------------------------------------- @@ -503,7 +503,7 @@ void loop() { //------------------------------------------------ // MQTT //------------------------------------------------ - if (G.MQTT_State == 1 && WiFi.status() == WL_CONNECTED) { + if (G.mqtt.state == 1 && WiFi.status() == WL_CONNECTED) { if (!mqttClient.connected()) { MQTT_reconnect(); } @@ -615,13 +615,13 @@ void loop() { { DynamicJsonDocument config(1024); config["command"] = "mqtt"; - config["MQTT_State"] = G.MQTT_State; - config["MQTT_Port"] = G.MQTT_Port; - config["MQTT_Server"] = G.MQTT_Server; - config["MQTT_User"] = G.MQTT_User; - config["MQTT_Pass"] = G.MQTT_Pass; - config["MQTT_ClientId"] = G.MQTT_ClientId; - config["MQTT_Topic"] = G.MQTT_Topic; + config["MQTT_State"] = G.mqtt.state; + config["MQTT_Port"] = G.mqtt.port; + config["MQTT_Server"] = G.mqtt.serverAdress; + config["MQTT_User"] = G.mqtt.user; + config["MQTT_Pass"] = G.mqtt.password; + config["MQTT_ClientId"] = G.mqtt.clientId; + config["MQTT_Topic"] = G.mqtt.topic; serializeJson(config, str); Serial.print("Sending Payload:"); Serial.println(str); @@ -655,8 +655,8 @@ void loop() { config["zeige_min"] = G.zeige_min; config["ldr"] = G.ldr; config["ldrCal"] = G.ldrCal; - config["cityid"] = G.cityid; - config["apikey"] = G.apikey; + config["cityid"] = G.openWeatherMap.cityid; + config["apikey"] = G.openWeatherMap.apikey; config["colortype"] = G.Colortype; config["UhrtypeDef"] = G.UhrtypeDef; config["bootLedBlink"] = G.bootLedBlink; @@ -771,8 +771,8 @@ void loop() { case COMMAND_SET_MQTT: // MQTT Einstellungen { - if (!mqttClient.connected() && G.MQTT_State) { - mqttClient.connect(G.MQTT_ClientId, G.MQTT_User, G.MQTT_Pass); + if (!mqttClient.connected() && G.mqtt.state) { + mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); MQTT_reconnect(); } eeprom_write(); From de0956ea0599d2961c2ae80d205b4b4267c8324e Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 00:12:00 +0100 Subject: [PATCH 02/15] Removed internal Variable of changes_in_array() --- include/uhr_func.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/uhr_func.hpp b/include/uhr_func.hpp index 1bf5ef1c..5b6d2ca6 100644 --- a/include/uhr_func.hpp +++ b/include/uhr_func.hpp @@ -176,13 +176,12 @@ void copy_array(const uint16_t source[], uint16_t destination[]) { //------------------------------------------------------------------------------ bool changes_in_array() { - bool return_value = false; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { if (Word_array[i] != Word_array_old[i]) { - return_value = true; + return true; } } - return return_value; + return false; } //------------------------------------------------------------------------------ From 42b6908aaadf3ff13d63be3d6d954cb33b19891f Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 00:18:42 +0100 Subject: [PATCH 03/15] Removed old C-Style Cast and If_clause in autoLdr() --- include/uhr_func.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/uhr_func.hpp b/include/uhr_func.hpp index 5b6d2ca6..f1cb5035 100644 --- a/include/uhr_func.hpp +++ b/include/uhr_func.hpp @@ -47,12 +47,9 @@ RgbwColor led_get_pixel_rgbw(uint16_t i) { // Helligkeitsregelung nach Uhrzeiten oder per LDR //------------------------------------------------------------------------------ static uint8_t autoLdr(uint8_t val) { - if (G.autoLdrEnabled) { - // G.hh enthaelt zeitabhaengige Helligkeitswerte in % - uint16_t u16 = (val * G.hh) / 100; - return ((uint8_t)((u16 * ldrVal) / 100)); - } - return val; + // G.hh enthaelt zeitabhaengige Helligkeitswerte in % + uint16_t u16 = (val * G.hh) / 100; + return (static_cast((u16 * ldrVal) / 100)); } //------------------------------------------------------------------------------ From 6a617b08965ca1d89316b8e94055c315d627df6c Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 00:21:10 +0100 Subject: [PATCH 04/15] Removed unnecessary for-loop in led_clear() --- include/uhr_func.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/uhr_func.hpp b/include/uhr_func.hpp index f1cb5035..8a4b7906 100644 --- a/include/uhr_func.hpp +++ b/include/uhr_func.hpp @@ -119,8 +119,6 @@ static inline void led_clear_pixel(uint16_t i) { void led_clear() { for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { Word_array[i] = 500; - } - for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { led_clear_pixel(i); } } From 62eb1d4b12936eb146963b11d98985ab7a6acbad Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 00:46:25 +0100 Subject: [PATCH 05/15] Removed HSL_to_RGB() and Added led_set_pixel_hsb() instead --- include/uhr_func.hpp | 137 ++++++++++--------------------------------- 1 file changed, 32 insertions(+), 105 deletions(-) diff --git a/include/uhr_func.hpp b/include/uhr_func.hpp index 8a4b7906..44b5ec61 100644 --- a/include/uhr_func.hpp +++ b/include/uhr_func.hpp @@ -12,6 +12,17 @@ void led_set_pixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { //------------------------------------------------------------------------------ +void led_set_pixel_hsb(uint16_t hue, uint8_t sat, uint8_t bri, uint16_t i) { + + if (G.Colortype == Grbw) { + strip_RGBW->SetPixelColor(i, HsbColor(hue / 360, sat / 255, bri / 255)); + } else { + strip_RGB->SetPixelColor(i, HsbColor(hue / 255, sat / 255, bri / 255)); + } +} + +//------------------------------------------------------------------------------ + void led_set_pixel_Color_Object(uint16_t i, RgbColor color) { if (G.Colortype == Grbw) { @@ -206,99 +217,25 @@ void led_set_Icon(uint8_t num_icon, uint8_t brightness = 100, } //------------------------------------------------------------------------------ -// HSV to RGB 8Bit -// Farbkreis hue = 0 bis 360 (Farbwert) -// bri = 0 bis 255 (Dunkelstufe) -// sat = 0 bis 255 (Farbsättigung) -//------------------------------------------------------------------------------ - -void hsv_to_rgb(double hue, float sat, float bri, uint8_t *c) { - hue = 3.14159F * hue / 180.0F; // convert to radians. - sat /= 255.0F; // from percentage to ratio - bri /= 255.0F; // from percentage to ratio - sat = sat > 0 ? (sat < 1 ? sat : 1) : 0; // clamp s and i to interval [0,1] - bri = bri > 0 ? (bri < 1 ? bri : 1) : 0; // clamp s and i to interval [0,1] - bri = bri * - std::sqrt(bri); // shape intensity to have finer granularity near 0 - if (G.Colortype == Grbw) { - if (hue < 2.09439) { - c[0] = sat * 255.0 * bri / 3.0 * - (1 + std::cos(hue) / std::cos(1.047196667 - hue)); - c[1] = sat * 255.0 * bri / 3.0 * - (1 + (1 - std::cos(hue) / std::cos(1.047196667 - hue))); - c[2] = 0; - c[3] = 255.0 * (1.0 - sat) * bri; - } else if (hue < 4.188787) { - hue = hue - 2.09439; - c[1] = sat * 255.0 * bri / 3.0 * - (1 + std::cos(hue) / std::cos(1.047196667 - hue)); - c[2] = sat * 255.0 * bri / 3.0 * - (1 + (1 - std::cos(hue) / std::cos(1.047196667 - hue))); - c[0] = 0; - c[3] = 255.0 * (1.0 - sat) * bri; - } else { - hue = hue - 4.188787; - c[2] = sat * 255.0 * bri / 3.0 * - (1 + std::cos(hue) / std::cos(1.047196667 - hue)); - c[0] = sat * 255.0 * bri / 3.0 * - (1 + (1 - std::cos(hue) / std::cos(1.047196667 - hue))); - c[1] = 0; - c[3] = 255.0 * (1 - sat) * bri; - } - } else { - while (hue < 0) { - hue += 360.0F; - } // cycle h around to 0-360 degrees - while (hue >= 360) { - hue -= 360.0F; - } - - if (hue < 2.09439) { - c[0] = 255 * bri / 3 * - (1 + sat * std::cos(hue) / std::cos(1.047196667 - hue)); - c[1] = - 255 * bri / 3 * - (1 + sat * (1 - std::cos(hue) / std::cos(1.047196667 - hue))); - c[2] = 255 * bri / 3 * (1 - sat); - } else if (hue < 4.188787) { - hue = hue - 2.09439; - c[1] = 255 * bri / 3 * - (1 + sat * std::cos(hue) / std::cos(1.047196667 - hue)); - c[2] = - 255 * bri / 3 * - (1 + sat * (1 - std::cos(hue) / std::cos(1.047196667 - hue))); - c[0] = 255 * bri / 3 * (1 - sat); - } else { - hue = hue - 4.188787; - c[2] = - 255 * bri / 3 * (1 + sat * cos(hue) / cos(1.047196667 - hue)); - c[0] = 255 * bri / 3 * - (1 + sat * (1 - cos(hue) / cos(1.047196667 - hue))); - c[1] = 255 * bri / 3 * (1 - sat); - } - c[3] = 0; +static inline void checkIfHueIsOutOfBound(float &hue) { + if (hue > 360) { + hue = 0; } } //------------------------------------------------------------------------------ static void led_single(uint8_t wait) { - - float h; - uint8_t c[4]; + float hue; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - - h = 360.0 * i / (usedUhrType->NUM_PIXELS() - 1); - h = h + 360.0 / usedUhrType->NUM_PIXELS(); - if (h > 360) { - h = 0; - } + hue = 360.0 * i / (usedUhrType->NUM_PIXELS() - 1); + hue = hue + 360.0 / usedUhrType->NUM_PIXELS(); + checkIfHueIsOutOfBound(hue); led_clear(); - hsv_to_rgb(h, 255, 255, c); - led_set_pixel(c[0], c[1], c[2], c[3], i); + led_set_pixel_hsb(hue, 255, 255, i); led_show(); delay(wait); } @@ -374,42 +311,32 @@ static void set_farbe_rahmen() { //------------------------------------------------------------------------------ static void rainbow() { - - static float h = 0.0; - uint8_t c[4]; - hsv_to_rgb(h, 255, G.hell * 10, c); + static float hue = 0; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - led_set_pixel(c[0], c[1], c[2], c[3], i); + led_set_pixel_hsb(hue, 255, G.hell * 10, i); } led_show(); - h++; - if (h > 359) { - h = 0.0; - } + hue++; + checkIfHueIsOutOfBound(hue); } //----------------------------------------------------------------------------- static void rainbowCycle() { - static float h = 0; - float hh; - uint8_t c[4]; + static float hue = 0; + float displayedHue; - hh = h; + displayedHue = hue; for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - hsv_to_rgb(hh, 255, G.hell * 10, c); - led_set_pixel(c[0], c[1], c[2], c[3], usedUhrType->getSMatrix(i)); - hh = hh + 360.0 / usedUhrType->NUM_SMATRIX(); - if (hh > 360) { - hh = 0; - } + led_set_pixel_hsb(displayedHue, 255, G.hell * 10, + usedUhrType->getSMatrix(i)); + displayedHue = displayedHue + 360.0 / usedUhrType->NUM_SMATRIX(); + checkIfHueIsOutOfBound(displayedHue); } led_show(); - h++; - if (h > 360) { - h = 0.0; - } + hue++; + checkIfHueIsOutOfBound(hue); } //------------------------------------------------------------------------------ From 5cb257479413571cf9cb6f0776a95b548ff4916c Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 13:11:50 +0100 Subject: [PATCH 06/15] Removed COMMAND_BRIGHTNESS, instead COMMAND_SET_BRIGHTNESS will be used for all Brightness values. Fixed Handling of Brightness update in Wortuhr.cpp --- include/Uhr.h | 1 - include/WebPage_Adapter.h | 8 +------- src/Wortuhr.cpp | 1 - webpage/script.js | 29 +++++++++++++++++------------ 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/Uhr.h b/include/Uhr.h index dd89c4d8..440ac1f3 100644 --- a/include/Uhr.h +++ b/include/Uhr.h @@ -210,7 +210,6 @@ enum Command { COMMAND_SET_BOOT = 101, COMMAND_SET_AUTO_LDR = 102, - COMMAND_BRIGHTNESS = 151, COMMAND_SPEED = 152, COMMAND_REQUEST_CONFIG_VALUES = 200, diff --git a/include/WebPage_Adapter.h b/include/WebPage_Adapter.h index 75f5de60..584d893c 100644 --- a/include/WebPage_Adapter.h +++ b/include/WebPage_Adapter.h @@ -289,13 +289,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_BRIGHTNESS: { // Helligkeit - G.hell = split(payload, 27); - break; - } - - //------------------------------------------------------------------------------ - case COMMAND_SPEED: { // Geschwindigkeit G.geschw = split(payload, 30); break; @@ -485,6 +478,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, G.h20 = split(payload, 18); G.h22 = split(payload, 21); G.h24 = split(payload, 24); + G.hell = split(payload, 27); break; } diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 21b0bc31..f222d624 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -764,7 +764,6 @@ void loop() { eeprom_write(); led_clear(); parameters_changed = true; - G.prog = COMMAND_MODE_WORD_CLOCK; G.conf = COMMAND_IDLE; break; } diff --git a/webpage/script.js b/webpage/script.js index b96b5697..59b00361 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -596,6 +596,21 @@ function sendCmd(command, addData = "") { debugMessage("Send data: ", data); } +function sendBrightnessData(command, addData = "") { + h6 = $("#brightness-6").get("value"); + h8 = $("#brightness-8").get("value"); + h12 = $("#brightness-12").get("value"); + h16 = $("#brightness-16").get("value"); + h18 = $("#brightness-18").get("value"); + h20 = $("#brightness-20").get("value"); + h22 = $("#brightness-22").get("value"); + h24 = $("#brightness-24").get("value"); + hell = $("#slider-brightness").get("value"); + + sendCmd(COMMAND_SET_BRIGHTNESS, nstr(h6) + nstr(h8) + nstr(h12) + nstr(h16) + nstr(h18) + nstr(h20) + nstr(h22) + nstr(h24) + nstr(hell)); + debugMessage("Helligkeit wurde neu konfiguriert"); +} + $.ready(function() { initConfigValues(); @@ -756,7 +771,7 @@ $.ready(function() { if (sleep === 0) { getSliders(); if (id === "slider-brightness") { - sendData(COMMAND_BRIGHTNESS); + sendBrightnessData(COMMAND_SET_BRIGHTNESS); } if (id === "slider-speed") { sendData(COMMAND_SPEED); @@ -830,17 +845,7 @@ $.ready(function() { debugMessage("Lauftext wurde neu konfiguriert"); }); $("[id*='brightness']").on("change", function() { - h6 = $("#brightness-6").get("value"); - h8 = $("#brightness-8").get("value"); - h12 = $("#brightness-12").get("value"); - h16 = $("#brightness-16").get("value"); - h18 = $("#brightness-18").get("value"); - h20 = $("#brightness-20").get("value"); - h22 = $("#brightness-22").get("value"); - h24 = $("#brightness-24").get("value"); - - sendCmd(COMMAND_SET_BRIGHTNESS, nstr(h6) + nstr(h8) + nstr(h12) + nstr(h16) + nstr(h18) + nstr(h20) + nstr(h22) + nstr(h24)); - debugMessage("Helligkeit wurde neu konfiguriert"); + sendBrightnessData(COMMAND_SET_BRIGHTNESS); }); $("#weather-button").on("click", function() { From 01483b6810ab011187a9e575041412fc50455f45 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 13:34:49 +0100 Subject: [PATCH 07/15] FIxed Range of Brightness slider. Instead of 1 to 10 the Range is now 0-100. Also fixed led_set_pixel_hsb() to properly handle bri and sat values. Added possible RGBW values within the function. Rearranged function attributes for default values. --- include/uhr_func.hpp | 19 ++++++++++++------- webpage/index.html | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/uhr_func.hpp b/include/uhr_func.hpp index 44b5ec61..c4a60f86 100644 --- a/include/uhr_func.hpp +++ b/include/uhr_func.hpp @@ -12,12 +12,17 @@ void led_set_pixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { //------------------------------------------------------------------------------ -void led_set_pixel_hsb(uint16_t hue, uint8_t sat, uint8_t bri, uint16_t i) { +void led_set_pixel_hsb(uint16_t ledIndex, float hue, float sat, float bri, + uint8_t alpha = 0) { + HsbColor hsbColor = HsbColor(hue / 360, sat / 100, bri / 100); if (G.Colortype == Grbw) { - strip_RGBW->SetPixelColor(i, HsbColor(hue / 360, sat / 255, bri / 255)); + RgbColor rgbColor = RgbColor(hsbColor); + + strip_RGBW->SetPixelColor( + ledIndex, RgbwColor(rgbColor.R, rgbColor.G, rgbColor.B, alpha)); } else { - strip_RGB->SetPixelColor(i, HsbColor(hue / 255, sat / 255, bri / 255)); + strip_RGB->SetPixelColor(ledIndex, hsbColor); } } @@ -235,7 +240,7 @@ static void led_single(uint8_t wait) { checkIfHueIsOutOfBound(hue); led_clear(); - led_set_pixel_hsb(hue, 255, 255, i); + led_set_pixel_hsb(i, hue, 100, 100); led_show(); delay(wait); } @@ -314,7 +319,7 @@ static void rainbow() { static float hue = 0; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - led_set_pixel_hsb(hue, 255, G.hell * 10, i); + led_set_pixel_hsb(i, hue, 100, G.hell); } led_show(); hue++; @@ -329,8 +334,8 @@ static void rainbowCycle() { displayedHue = hue; for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - led_set_pixel_hsb(displayedHue, 255, G.hell * 10, - usedUhrType->getSMatrix(i)); + led_set_pixel_hsb(usedUhrType->getSMatrix(i), displayedHue, 100, + G.hell); displayedHue = displayedHue + 360.0 / usedUhrType->NUM_SMATRIX(); checkIfHueIsOutOfBound(displayedHue); } diff --git a/webpage/index.html b/webpage/index.html index 6f4d2f1d..76416deb 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -125,7 +125,7 @@

Einstellung

-
+
From 5bee7ecce39b408651783f0b9e6532074179752e Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 28 Dec 2022 18:41:54 +0100 Subject: [PATCH 08/15] Added New Handling for Speed and Brightness in Wortuhr.cpp. Changed Name of Comand_Modes to Clear Names. Fixed G.Prog_init for Comand_Modes. Refcatored javascript Funktions in script.js --- include/Uhr.h | 6 ++-- include/WebPage_Adapter.h | 20 +++++-------- include/mqtt_func.hpp | 6 ++-- src/Wortuhr.cpp | 38 ++++++++--------------- webpage/index.html | 2 +- webpage/script.js | 63 ++++++++++++++++----------------------- 6 files changed, 53 insertions(+), 82 deletions(-) diff --git a/include/Uhr.h b/include/Uhr.h index 440ac1f3..1d41dbfd 100644 --- a/include/Uhr.h +++ b/include/Uhr.h @@ -182,9 +182,9 @@ enum Command { COMMAND_MODE_WORD_CLOCK = 1, COMMAND_MODE_SECONDS = 2, - COMMAND_MODE_MARQUEE = 3, - COMMAND_MODE_RAINBOW = 4, - COMMAND_MODE_CHANGE = 5, + COMMAND_MODE_SCROLLINGTEXT = 3, + COMMAND_MODE_RAINBOWCYCLE = 4, + COMMAND_MODE_RAINBOW = 5, COMMAND_MODE_COLOR = 6, COMMAND_MODE_ANIMATION = 10, diff --git a/include/WebPage_Adapter.h b/include/WebPage_Adapter.h index 584d893c..ea868eb6 100644 --- a/include/WebPage_Adapter.h +++ b/include/WebPage_Adapter.h @@ -204,10 +204,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, case COMMAND_MODE_SECONDS: { // Sekunden G.prog = COMMAND_MODE_SECONDS; - G.param1 = split(payload, 33); - if (G.param1 == 0) { G.prog_init = 1; - } G.rgb[Effect][0] = split(payload, 3); G.rgb[Effect][1] = split(payload, 6); @@ -220,12 +217,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_MODE_MARQUEE: { // Laufschrift - G.prog = COMMAND_MODE_MARQUEE; - G.param1 = split(payload, 33); - if (G.param1 == 0) { + case COMMAND_MODE_SCROLLINGTEXT: { + G.prog = COMMAND_MODE_SCROLLINGTEXT; G.prog_init = 1; - } G.rgb[Effect][0] = split(payload, 3); G.rgb[Effect][1] = split(payload, 6); @@ -238,8 +232,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_MODE_RAINBOW: { // Regenbogen - G.prog = COMMAND_MODE_RAINBOW; + case COMMAND_MODE_RAINBOWCYCLE: { + G.prog = COMMAND_MODE_RAINBOWCYCLE; G.prog_init = 1; G.hell = split(payload, 27); @@ -249,8 +243,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_MODE_CHANGE: { // Farbwechsel - G.prog = COMMAND_MODE_CHANGE; + case COMMAND_MODE_RAINBOW: { + G.prog = COMMAND_MODE_RAINBOW; G.prog_init = 1; G.hell = split(payload, 27); @@ -290,7 +284,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ case COMMAND_SPEED: { // Geschwindigkeit - G.geschw = split(payload, 30); + G.geschw = split(payload, 3); break; } diff --git a/include/mqtt_func.hpp b/include/mqtt_func.hpp index ed0aab02..b13ef555 100644 --- a/include/mqtt_func.hpp +++ b/include/mqtt_func.hpp @@ -38,11 +38,11 @@ void MQTT_callback(char *topic, byte *payload, unsigned int length) { } else if (str_buffer.compare("Sekundenanzeige")) { G.prog = COMMAND_MODE_SECONDS; } else if (str_buffer.compare("Laufschrift")) { - G.prog = COMMAND_MODE_MARQUEE; + G.prog = COMMAND_MODE_SCROLLINGTEXT; } else if (str_buffer.compare("Regenbogen")) { - G.prog = COMMAND_MODE_RAINBOW; + G.prog = COMMAND_MODE_RAINBOWCYCLE; } else if (str_buffer.compare("Farbwechsel")) { - G.prog = COMMAND_MODE_CHANGE; + G.prog = COMMAND_MODE_RAINBOW; } else if (str_buffer.compare("Farbe")) { G.prog = COMMAND_MODE_COLOR; } diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index f222d624..fbe9e4e1 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -857,43 +857,31 @@ void loop() { break; } - case COMMAND_MODE_MARQUEE: // Laufschriftanzeige - { + case COMMAND_MODE_SCROLLINGTEXT: + case COMMAND_MODE_RAINBOWCYCLE: + case COMMAND_MODE_RAINBOW: { if (G.prog_init == 1) { G.prog_init = 0; led_clear(); - count_delay = (G.geschw + 1) * 20; + count_delay = (11u - G.geschw) * 30u; } - if (count_delay >= (G.geschw + 1u) * 20u) { + if (count_delay >= (11u - G.geschw) * 30u) { + switch (G.prog) { + case COMMAND_MODE_SCROLLINGTEXT: { laufschrift(G.ltext); - count_delay = 0; - } break; } - - case COMMAND_MODE_RAINBOW: // Regenbogenanzeige - { - if (G.prog_init == 1) { - G.prog_init = 0; - uhr_clear(); - count_delay = G.geschw * 7 + 1; - } - if (count_delay >= G.geschw * 7u + 1u) { + case COMMAND_MODE_RAINBOWCYCLE: { rainbowCycle(); - count_delay = 0; + break; } + case COMMAND_MODE_RAINBOW: { + rainbow(); break; } - - case COMMAND_MODE_CHANGE: // Farbwechselanzeige - { - if (G.prog_init == 1) { - G.prog_init = 0; - led_clear(); - count_delay = G.geschw * 7 + 1; + default: + break; } - if (count_delay >= G.geschw * 7u + 1u) { - rainbow(); count_delay = 0; } break; diff --git a/webpage/index.html b/webpage/index.html index 76416deb..658ca60b 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -138,7 +138,7 @@

Einstellung

-
+
diff --git a/webpage/script.js b/webpage/script.js index 59b00361..d441e11d 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -112,9 +112,9 @@ var animDemo = false; // operation modes var COMMAND_MODE_WORD_CLOCK = 1; var COMMAND_MODE_SECONDS = 2; -var COMMAND_MODE_MARQUEE = 3; -var COMMAND_MODE_RAINBOW = 4; -var COMMAND_MODE_CHANGE = 5; +var COMMAND_MODE_SCROLLINGTEXT = 3; +var COMMAND_MODE_RAINBOWCYCLE = 4; +var COMMAND_MODE_RAINBOW = 5; var COMMAND_MODE_COLOR = 6; var COMMAND_MODE_ANIMATION = 10; @@ -418,7 +418,8 @@ function changeColor(color) { rgb[color.index][1] = color.green; rgb[color.index][2] = color.blue; rgb[color.index][3] = Math.round(255 * (1.0 - color.alpha)); - sendData(command, nstr(1)); + sendColorData(command, nstr(1)); +} } function createColorPicker() { @@ -442,14 +443,6 @@ function createColorPicker() { alphaSlider.classList.add("specific-colortype-4"); } -/** - * Gets all the values from the sliders and puts them in the config variables. - */ -function getSliders() { - hell = $("#slider-brightness").get("value"); - geschw = $("#slider-speed").get("value"); -} - /** * show the color configuration in the color picker */ @@ -505,7 +498,7 @@ function toggleBackground() { rgb[COLOR_BACKGROUND][3] = 0; } setColorPicker(withBackground); - sendData(command, nstr(1)); + sendColorData(command, nstr(1)); } /** @@ -573,23 +566,6 @@ function getPaddedString(string, maxStringLength) { return string.padEnd(maxStringLength, " "); } -function sendData(command, addData = "") { - var data = nstr(command) + - nstr(rgb[COLOR_FOREGROUND][0]) + - nstr(rgb[COLOR_FOREGROUND][1]) + - nstr(rgb[COLOR_FOREGROUND][2]) + - nstr(rgb[COLOR_FOREGROUND][3]) + - nstr(rgb[COLOR_BACKGROUND][0]) + - nstr(rgb[COLOR_BACKGROUND][1]) + - nstr(rgb[COLOR_BACKGROUND][2]) + - nstr(rgb[COLOR_BACKGROUND][3]) + - nstr(hell) + - nstr(geschw) + addData + "999"; - - websocket.send(data); - debugMessage("Send data: ", data); -} - function sendCmd(command, addData = "") { var data = nstr(command) + addData + "999"; websocket.send(data); @@ -605,12 +581,24 @@ function sendBrightnessData(command, addData = "") { h20 = $("#brightness-20").get("value"); h22 = $("#brightness-22").get("value"); h24 = $("#brightness-24").get("value"); - hell = $("#slider-brightness").get("value"); sendCmd(COMMAND_SET_BRIGHTNESS, nstr(h6) + nstr(h8) + nstr(h12) + nstr(h16) + nstr(h18) + nstr(h20) + nstr(h22) + nstr(h24) + nstr(hell)); debugMessage("Helligkeit wurde neu konfiguriert"); } +function sendColorData(command, addData = "") { + sendCmd(command, nstr(rgb[COLOR_FOREGROUND][0]) + + nstr(rgb[COLOR_FOREGROUND][1]) + + nstr(rgb[COLOR_FOREGROUND][2]) + + nstr(rgb[COLOR_FOREGROUND][3]) + + nstr(rgb[COLOR_BACKGROUND][0]) + + nstr(rgb[COLOR_BACKGROUND][1]) + + nstr(rgb[COLOR_BACKGROUND][2]) + + nstr(rgb[COLOR_BACKGROUND][3]) + + nstr(hell) + + nstr(geschw)); +} + $.ready(function() { initConfigValues(); @@ -706,17 +694,17 @@ $.ready(function() { if (id === "mode-marquee") { hasSpeed = true; hasText = true; - command = COMMAND_MODE_MARQUEE; + command = COMMAND_MODE_SCROLLINGTEXT; } if (id === "mode-rainbow") { hasBrightness = true; hasSpeed = true; - command = COMMAND_MODE_RAINBOW; + command = COMMAND_MODE_RAINBOWCYCLE; } if (id === "mode-change") { hasBrightness = true; hasSpeed = true; - command = COMMAND_MODE_CHANGE; + command = COMMAND_MODE_RAINBOW; } setAnimation(); @@ -760,7 +748,7 @@ $.ready(function() { }); } - sendData(command); + sendColorData(command); setSliders(); setColors(); }); @@ -769,12 +757,13 @@ $.ready(function() { var id = $(this).get("id"); if (sleep === 0) { - getSliders(); if (id === "slider-brightness") { + hell = $("#slider-brightness").get("value"); sendBrightnessData(COMMAND_SET_BRIGHTNESS); } if (id === "slider-speed") { - sendData(COMMAND_SPEED); + geschw = $("#slider-speed").get("value"); + sendCmd(COMMAND_SPEED, nstr(geschw)); } setSliders(); From bbd2070f7fb36ecac05b438ba0f1eee853206087 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Mon, 2 Jan 2023 17:36:24 +0100 Subject: [PATCH 09/15] Refactured uhr_func.h in clockWork.h and clockWork.hpp. Just splitted the library no further Changes to code, exept for refacoring to funtionnames to camelCase and english as common language. --- include/Animation.h | 1 + include/Animation.hpp | 28 +-- include/clockWork.h | 74 ++++++++ include/{uhr_func.hpp => clockWork.hpp} | 227 ++++++++++++------------ include/wifi_func.hpp | 2 +- src/Wortuhr.cpp | 84 ++++----- webpage/script.js | 1 - 7 files changed, 251 insertions(+), 166 deletions(-) create mode 100644 include/clockWork.h rename include/{uhr_func.hpp => clockWork.hpp} (86%) diff --git a/include/Animation.h b/include/Animation.h index 9b5793f6..6469e71b 100644 --- a/include/Animation.h +++ b/include/Animation.h @@ -1,5 +1,6 @@ #pragma once +#include "font.h" #include "icons.h" #include diff --git a/include/Animation.hpp b/include/Animation.hpp index 4f1e50f8..6afecb03 100644 --- a/include/Animation.hpp +++ b/include/Animation.hpp @@ -242,7 +242,7 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source, for (int r = 0; r < max_rows; r++) { for (int c = 0; c < max_cols; c++) { if (source == STRIPE) { - color = led_get_pixel( + color = clockWork.ledGetPixel( usedUhrType->getFrontMatrix(r + row_start, c + col_start)); } else { color = source[r][c]; @@ -293,21 +293,25 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source, void Animation::set_minutes() { if (G.zeige_min > 0) { uint8_t m = lastMinute % 5; - led_set_pixel_Color_Object(usedUhrType->getMinArr(G.zeige_min - 1, 0), - m > 0 ? foregroundMinute : background); - led_set_pixel_Color_Object(usedUhrType->getMinArr(G.zeige_min - 1, 1), - m > 1 ? foregroundMinute : background); - led_set_pixel_Color_Object(usedUhrType->getMinArr(G.zeige_min - 1, 2), - m > 2 ? foregroundMinute : background); - led_set_pixel_Color_Object(usedUhrType->getMinArr(G.zeige_min - 1, 3), - m > 3 ? foregroundMinute : background); + clockWork.ledSetPixelColorObject( + usedUhrType->getMinArr(G.zeige_min - 1, 0), + m > 0 ? foregroundMinute : background); + clockWork.ledSetPixelColorObject( + usedUhrType->getMinArr(G.zeige_min - 1, 1), + m > 1 ? foregroundMinute : background); + clockWork.ledSetPixelColorObject( + usedUhrType->getMinArr(G.zeige_min - 1, 2), + m > 2 ? foregroundMinute : background); + clockWork.ledSetPixelColorObject( + usedUhrType->getMinArr(G.zeige_min - 1, 3), + m > 3 ? foregroundMinute : background); } } // Ueberschreibe die LEDs mit interner Matrix void Animation::copy2Stripe(RgbfColor **source) { for (uint8_t row = 0; row < max_rows; row++) { for (uint8_t col = 0; col < max_cols; col++) { - led_set_pixel_Color_Object( + clockWork.ledSetPixelColorObject( usedUhrType->getFrontMatrix(row + row_start, col + col_start), source[row][col]); } @@ -404,7 +408,7 @@ void Animation::loop(struct tm &tm) { copyMatrix(work, act); colorize(work); copy2Stripe(work); - led_show(); + clockWork.ledShow(); } } else { if ((animType != lastAnimType) || @@ -466,7 +470,7 @@ void Animation::loop(struct tm &tm) { } animColorChange(); copy2Stripe(work); - led_show(); + clockWork.ledShow(); } } } diff --git a/include/clockWork.h b/include/clockWork.h new file mode 100644 index 00000000..ebdc50db --- /dev/null +++ b/include/clockWork.h @@ -0,0 +1,74 @@ +#pragma once + +#include + +class ClockWork { +private: + inline void checkIfHueIsOutOfBound(float &hue) { + if (hue > 360) { + hue = 0; + } + } + + void ledSetPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, + uint16_t i); + void ledSetPixelHsb(uint16_t ledIndex, float hue, float sat, float bri, + uint8_t alpha); + + void ledSetPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, + uint8_t offsetRow, unsigned char unsigned_d1); + + uint8_t setBrightnessAuto(uint8_t val); + void setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position); + void setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position, uint8_t percentage); + + inline void ledClearClock(); + inline void ledClearPixel(uint16_t i); + + void ledShiftColumnToRight(); + + void clockSetHour(const uint8_t std, const uint8_t voll); + void clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll); + void clockShowMinute(uint8_t min); + void clockSetClock(); + void clockShowWeather(); + +public: + ClockWork() = default; + ~ClockWork() = default; + + RgbColor ledGetPixel(uint16_t i); + RgbwColor ledGetPixelRgbw(uint16_t i); + + void ledSetPixelColorObject(uint16_t i, RgbColor color); + void ledSetPixelColorObjectRgbw(uint16_t i, RgbwColor color); + + void ledShow(); + void ledClear(); + inline void ledClearFrame(); + void ledSet(bool changed = false); + + bool changesInClockface(); + void copyClockface(const uint16_t source[], uint16_t destination[]); + void calcClockFace(); + + void ledSetIcon(uint8_t num_icon, uint8_t brightness, bool rgb_icon); + void ledSingle(uint8_t wait); + void ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww); + + void ledSetColor(); + void doLDRLogic(); + void ledSetFrameColor(); + + void rainbow(); + void rainbowCycle(); + void scrollingText(const char *buf); + void showIp(const char *buf); + + void showWifiSignalStrength(int strength); + void ledShowNumbers(const char d1, const char d2); + + void ledShowSeconds(); +}; diff --git a/include/uhr_func.hpp b/include/clockWork.hpp similarity index 86% rename from include/uhr_func.hpp rename to include/clockWork.hpp index c4a60f86..b03eaa7c 100644 --- a/include/uhr_func.hpp +++ b/include/clockWork.hpp @@ -1,7 +1,20 @@ +#include "Animation.h" +#include "NeoMultiFeature.hpp" #include "Uhr.h" +#include "Uhrtypes/Uhrtype.hpp" +#include "clockWork.h" +#include "font.h" +#include "icons.h" #include -void led_set_pixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { +extern NeoPixelBus *strip_RGB; +extern NeoPixelBus *strip_RGBW; + +extern iUhrType *usedUhrType; +extern Animation *animation; + +void ClockWork::ledSetPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, + uint16_t i) { if (G.Colortype == Grbw) { strip_RGBW->SetPixelColor(i, RgbwColor(rr, gg, bb, ww)); @@ -12,8 +25,8 @@ void led_set_pixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { //------------------------------------------------------------------------------ -void led_set_pixel_hsb(uint16_t ledIndex, float hue, float sat, float bri, - uint8_t alpha = 0) { +void ClockWork::ledSetPixelHsb(uint16_t ledIndex, float hue, float sat, + float bri, uint8_t alpha = 0) { HsbColor hsbColor = HsbColor(hue / 360, sat / 100, bri / 100); if (G.Colortype == Grbw) { @@ -28,7 +41,7 @@ void led_set_pixel_hsb(uint16_t ledIndex, float hue, float sat, float bri, //------------------------------------------------------------------------------ -void led_set_pixel_Color_Object(uint16_t i, RgbColor color) { +void ClockWork::ledSetPixelColorObject(uint16_t i, RgbColor color) { if (G.Colortype == Grbw) { strip_RGBW->SetPixelColor(i, RgbwColor(color)); @@ -39,13 +52,13 @@ void led_set_pixel_Color_Object(uint16_t i, RgbColor color) { //------------------------------------------------------------------------------ -void led_set_pixel_Color_Object_rgbw(uint16_t i, RgbwColor color) { +void ClockWork::ledSetPixelColorObjectRgbw(uint16_t i, RgbwColor color) { strip_RGBW->SetPixelColor(i, RgbwColor(color)); } //------------------------------------------------------------------------------ -RgbColor led_get_pixel(uint16_t i) { +RgbColor ClockWork::ledGetPixel(uint16_t i) { if (G.Colortype == Grbw) { RgbwColor rgbw = strip_RGBW->GetPixelColor(i); return RgbColor(rgbw.R, rgbw.G, rgbw.B); @@ -55,14 +68,14 @@ RgbColor led_get_pixel(uint16_t i) { //------------------------------------------------------------------------------ -RgbwColor led_get_pixel_rgbw(uint16_t i) { +RgbwColor ClockWork::ledGetPixelRgbw(uint16_t i) { return strip_RGBW->GetPixelColor(i); } //------------------------------------------------------------------------------ // Helligkeitsregelung nach Uhrzeiten oder per LDR //------------------------------------------------------------------------------ -static uint8_t autoLdr(uint8_t val) { +uint8_t ClockWork::setBrightnessAuto(uint8_t val) { // G.hh enthaelt zeitabhaengige Helligkeitswerte in % uint16_t u16 = (val * G.hh) / 100; return (static_cast((u16 * ldrVal) / 100)); @@ -70,13 +83,13 @@ static uint8_t autoLdr(uint8_t val) { //------------------------------------------------------------------------------ -static void set_helligkeit_ldr(uint8_t &rr, uint8_t &gg, uint8_t &bb, - uint8_t &ww, uint8_t position) { +void ClockWork::setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, + uint8_t &ww, uint8_t position) { if (G.autoLdrEnabled) { - rr = autoLdr(G.rgb[position][0]); - gg = autoLdr(G.rgb[position][1]); - bb = autoLdr(G.rgb[position][2]); - ww = autoLdr(G.rgb[position][3]); + rr = setBrightnessAuto(G.rgb[position][0]); + gg = setBrightnessAuto(G.rgb[position][1]); + bb = setBrightnessAuto(G.rgb[position][2]); + ww = setBrightnessAuto(G.rgb[position][3]); } else { if (G.ldr == 1) { rr = G.rgb[position][0] * ldrVal / 100; @@ -94,8 +107,9 @@ static void set_helligkeit_ldr(uint8_t &rr, uint8_t &gg, uint8_t &bb, //------------------------------------------------------------------------------ -void set_helligkeit(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, - uint8_t position, uint8_t percentage = 100) { +void ClockWork::setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, + uint8_t &ww, uint8_t position, + uint8_t percentage = 100) { rr = G.rgb[position][0] * percentage / 100; gg = G.rgb[position][1] * percentage / 100; bb = G.rgb[position][2] * percentage / 100; @@ -112,7 +126,7 @@ void set_helligkeit(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, //------------------------------------------------------------------------------ -void led_show() { +void ClockWork::ledShow() { if (G.Colortype == Grbw) { strip_RGBW->Show(); } else { @@ -122,7 +136,7 @@ void led_show() { //------------------------------------------------------------------------------ -static inline void led_clear_pixel(uint16_t i) { +inline void ClockWork::ledClearPixel(uint16_t i) { if (G.Colortype == Grbw) { strip_RGBW->SetPixelColor(i, 0); } else { @@ -132,53 +146,53 @@ static inline void led_clear_pixel(uint16_t i) { //------------------------------------------------------------------------------ -void led_clear() { +void ClockWork::ledClear() { for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { Word_array[i] = 500; - led_clear_pixel(i); + ledClearPixel(i); } } //------------------------------------------------------------------------------ -static inline void uhr_clear() { +inline void ClockWork::ledClearClock() { for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - led_clear_pixel(usedUhrType->getSMatrix(i)); + ledClearPixel(usedUhrType->getSMatrix(i)); } } //------------------------------------------------------------------------------ -static inline void rahmen_clear() { +inline void ClockWork::ledClearFrame() { for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { - led_clear_pixel(usedUhrType->getRMatrix(i)); + ledClearPixel(usedUhrType->getRMatrix(i)); } } //------------------------------------------------------------------------------ -static void led_set(bool changed = false) { +void ClockWork::ledSet(bool changed) { uint8_t rr, gg, bb, ww; uint8_t r2, g2, b2, w2; - set_helligkeit_ldr(rr, gg, bb, ww, Foreground); - set_helligkeit_ldr(r2, g2, b2, w2, Background); + setBrightnessLdr(rr, gg, bb, ww, Foreground); + setBrightnessLdr(r2, g2, b2, w2, Background); for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { if (Word_array_old[i] < usedUhrType->NUM_PIXELS()) { // foreground - led_set_pixel(rr, gg, bb, ww, i); + ledSetPixel(rr, gg, bb, ww, i); } else { // background - led_set_pixel(r2, g2, b2, w2, i); + ledSetPixel(r2, g2, b2, w2, i); } } if (animation->led_show_notify(changed, _minute)) { - led_show(); + ledShow(); } } //------------------------------------------------------------------------------ -void copy_array(const uint16_t source[], uint16_t destination[]) { +void ClockWork::copyClockface(const uint16_t source[], uint16_t destination[]) { for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { destination[i] = source[i]; } @@ -186,7 +200,7 @@ void copy_array(const uint16_t source[], uint16_t destination[]) { //------------------------------------------------------------------------------ -bool changes_in_array() { +bool ClockWork::changesInClockface() { for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { if (Word_array[i] != Word_array_old[i]) { return true; @@ -197,10 +211,10 @@ bool changes_in_array() { //------------------------------------------------------------------------------ -void led_set_Icon(uint8_t num_icon, uint8_t brightness = 100, - bool rgb_icon = false) { +void ClockWork::ledSetIcon(uint8_t num_icon, uint8_t brightness = 100, + bool rgb_icon = false) { uint8_t rr, gg, bb, ww; - set_helligkeit(rr, gg, bb, ww, Foreground, brightness); + setBrightness(rr, gg, bb, ww, Foreground, brightness); for (uint8_t col = 0; col < GRAFIK_11X10_COLS; col++) { if (rgb_icon) { rr = col < 3 ? 255 : 0; @@ -211,27 +225,19 @@ void led_set_Icon(uint8_t num_icon, uint8_t brightness = 100, for (uint8_t row = 0; row < GRAFIK_11X10_ROWS; row++) { if (pgm_read_word(&(grafik_11x10[num_icon][row])) & (1 << (GRAFIK_11X10_COLS - 1 - col))) { - led_set_pixel(rr, gg, bb, ww, - usedUhrType->getFrontMatrix(row, col)); + ledSetPixel(rr, gg, bb, ww, + usedUhrType->getFrontMatrix(row, col)); } else { - led_clear_pixel(usedUhrType->getFrontMatrix(row, col)); + ledClearPixel(usedUhrType->getFrontMatrix(row, col)); } } } - led_show(); -} - -//------------------------------------------------------------------------------ - -static inline void checkIfHueIsOutOfBound(float &hue) { - if (hue > 360) { - hue = 0; - } + ledShow(); } //------------------------------------------------------------------------------ -static void led_single(uint8_t wait) { +void ClockWork::ledSingle(uint8_t wait) { float hue; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { @@ -239,34 +245,35 @@ static void led_single(uint8_t wait) { hue = hue + 360.0 / usedUhrType->NUM_PIXELS(); checkIfHueIsOutOfBound(hue); - led_clear(); - led_set_pixel_hsb(i, hue, 100, 100); - led_show(); + ledClear(); + ledSetPixelHsb(i, hue, 100, 100); + ledShow(); delay(wait); } } //------------------------------------------------------------------------------ -static void led_set_all(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww) { +void ClockWork::ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, + uint8_t ww) { for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - led_set_pixel(rr, gg, bb, ww, i); + ledSetPixel(rr, gg, bb, ww, i); } } //------------------------------------------------------------------------------ -static void set_farbe() { +void ClockWork::ledSetColor() { uint8_t rr, gg, bb, ww; - set_helligkeit(rr, gg, bb, ww, Effect); - led_set_all(rr, gg, bb, ww); + setBrightness(rr, gg, bb, ww, Effect); + ledSetAllPixels(rr, gg, bb, ww); } //------------------------------------------------------------------------------ // Routine Helligkeitsregelung //------------------------------------------------------------------------------ -static void doLDRLogic() { +void ClockWork::doLDRLogic() { int16_t lux = analogRead(A0); // Range 0-1023 uint8_t ldrValOld = ldrVal; @@ -298,67 +305,65 @@ static void doLDRLogic() { } if (ldrValOld != ldrVal) { // lass den LDR sofort wirken - led_set(); + ledSet(); } } //------------------------------------------------------------------------------ -static void set_farbe_rahmen() { +void ClockWork::ledSetFrameColor() { uint8_t rr, gg, bb, ww; - set_helligkeit(rr, gg, bb, ww, Frame); + setBrightness(rr, gg, bb, ww, Frame); for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { - led_set_pixel(rr, gg, bb, ww, usedUhrType->getRMatrix(i)); + ledSetPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(i)); } } //------------------------------------------------------------------------------ -static void rainbow() { +void ClockWork::rainbow() { static float hue = 0; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - led_set_pixel_hsb(i, hue, 100, G.hell); + ledSetPixelHsb(i, hue, 100, G.hell); } - led_show(); + ledShow(); hue++; checkIfHueIsOutOfBound(hue); } //----------------------------------------------------------------------------- -static void rainbowCycle() { +void ClockWork::rainbowCycle() { static float hue = 0; float displayedHue; displayedHue = hue; for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - led_set_pixel_hsb(usedUhrType->getSMatrix(i), displayedHue, 100, - G.hell); + ledSetPixelHsb(usedUhrType->getSMatrix(i), displayedHue, 100, G.hell); displayedHue = displayedHue + 360.0 / usedUhrType->NUM_SMATRIX(); checkIfHueIsOutOfBound(displayedHue); } - led_show(); + ledShow(); hue++; checkIfHueIsOutOfBound(hue); } //------------------------------------------------------------------------------ -void shift_all_pixels_to_right() { +void ClockWork::ledShiftColumnToRight() { for (uint8_t col = 0; col < usedUhrType->COLS_MATRIX() - 1; col++) { for (uint8_t row = 0; row < usedUhrType->ROWS_MATRIX() - 1 /* Only Front*/; row++) { if (G.Colortype == Grbw) { - led_set_pixel_Color_Object_rgbw( + ledSetPixelColorObjectRgbw( usedUhrType->getFrontMatrix(row, col), - led_get_pixel_rgbw( - usedUhrType->getFrontMatrix(row, col + 1))); + ledGetPixelRgbw(usedUhrType->getFrontMatrix(row, col + 1))); } else { - led_set_pixel_Color_Object( + ledSetPixelColorObject( usedUhrType->getFrontMatrix(row, col), - led_get_pixel(usedUhrType->getFrontMatrix(row, col + 1))); + ledGetPixel(usedUhrType->getFrontMatrix(row, col + 1))); } } } @@ -366,12 +371,12 @@ void shift_all_pixels_to_right() { //------------------------------------------------------------------------------ -static void laufschrift(const char *buf) { +void ClockWork::scrollingText(const char *buf) { static uint8_t i = 0, ii = 0; static uint8_t offsetRow = 1; uint8_t fontIndex = buf[ii]; - shift_all_pixels_to_right(); + ledShiftColumnToRight(); if (usedUhrType->has24HourLayout()) { offsetRow = 4; @@ -380,23 +385,23 @@ static void laufschrift(const char *buf) { if (i < 5) { for (uint8_t row = 0; row < 8; row++) { if (pgm_read_byte(&(font_7x5[fontIndex][i])) & (1u << row)) { - led_set_pixel( + ledSetPixel( G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], G.rgb[Effect][3], usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } else { - led_clear_pixel(usedUhrType->getFrontMatrix( + ledClearPixel(usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } } } else { for (uint8_t row = 0; row < 8; row++) { - led_clear_pixel(usedUhrType->getFrontMatrix( + ledClearPixel(usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } } - led_show(); + ledShow(); i++; if (i > 5) { @@ -410,22 +415,23 @@ static void laufschrift(const char *buf) { //------------------------------------------------------------------------------ -static void zeigeip(const char *buf) { +void ClockWork::showIp(const char *buf) { uint8_t StringLength = strlen(buf); StringLength = StringLength * 6; // Times 6, because thats the length of a // char in the 7x5 font plus spacing for (uint16_t i = 0; i <= StringLength; i++) { - laufschrift(buf); + scrollingText(buf); delay(200); } } //------------------------------------------------------------------------------ -void set_pixel_for_char(uint8_t col, uint8_t row, uint8_t offsetCol, - uint8_t offsetRow, unsigned char unsigned_d1) { +void ClockWork::ledSetPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, + uint8_t offsetRow, + unsigned char unsigned_d1) { if (pgm_read_byte(&(font_7x5[unsigned_d1][col])) & (1u << row)) { - led_set_pixel( + ledSetPixel( G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], G.rgb[Effect][3], usedUhrType->getFrontMatrix(row + offsetRow, col + offsetCol)); @@ -436,20 +442,20 @@ void set_pixel_for_char(uint8_t col, uint8_t row, uint8_t offsetCol, // show signal-strenght by using different brightness for the individual rings //------------------------------------------------------------------------------ -void show_icon_wlan(int strength) { +void ClockWork::showWifiSignalStrength(int strength) { if (strength <= 100) { - led_set_Icon(WLAN100, 100); + ledSetIcon(WLAN100, 100); } else if (strength <= 60) { - led_set_Icon(WLAN60, 60); + ledSetIcon(WLAN60, 60); } else if (strength <= 30) { - led_set_Icon(WLAN30, 30); + ledSetIcon(WLAN30, 30); } } //------------------------------------------------------------------------------ -static void zahlen(const char d1, const char d2) { - uhr_clear(); +void ClockWork::ledShowNumbers(const char d1, const char d2) { + ledClearClock(); static uint8_t offsetLetter0 = 0; static uint8_t offsetLetter1 = 6; static uint8_t offsetRow = 1; @@ -463,19 +469,19 @@ static void zahlen(const char d1, const char d2) { for (uint8_t col = 0; col < 5; col++) { for (uint8_t row = 0; row < 8; row++) { // 1. Zahl ohne Offset - set_pixel_for_char(col, row, offsetLetter0, offsetRow, + ledSetPixelForChar(col, row, offsetLetter0, offsetRow, static_cast(d1)); // 2. Zahl mit Offset - set_pixel_for_char(col, row, offsetLetter1, offsetRow, + ledSetPixelForChar(col, row, offsetLetter1, offsetRow, static_cast(d2)); } } - led_show(); + ledShow(); } //------------------------------------------------------------------------------ -static void set_stunde(const uint8_t std, const uint8_t voll) { +void ClockWork::clockSetHour(const uint8_t std, const uint8_t voll) { switch (std) { case 0: usedUhrType->show(h_zwoelf); @@ -567,7 +573,7 @@ static void set_stunde(const uint8_t std, const uint8_t voll) { //------------------------------------------------------------------------------ -void show_minuten(uint8_t min) { +void ClockWork::clockShowMinute(uint8_t min) { if (G.zeige_min > 0) { // Minuten / Sekunden-Animation // Minute (1-4) ermitteln @@ -596,9 +602,9 @@ void show_minuten(uint8_t min) { //------------------------------------------------------------------------------ -void set_minute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { +void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { if (!usedUhrType->has24HourLayout()) { - show_minuten(min); + clockShowMinute(min); min /= 5; min *= 5; } @@ -803,7 +809,7 @@ static void countdownToMidnight() { //------------------------------------------------------------------------------ -static void set_uhrzeit() { +void ClockWork::clockSetClock() { uhrzeit = 0; if (!G.Sprachvariation[NotShowItIs]) { @@ -813,23 +819,24 @@ static void set_uhrzeit() { uint8_t offsetH = 0; uint8_t voll = 0; - set_minute(_minute, offsetH, voll); - set_stunde(_stunde + offsetH, voll); + clockSetMinute(_minute, offsetH, voll); + clockSetHour(_stunde + offsetH, voll); } //------------------------------------------------------------------------------ -static void show_sekunde() { +void ClockWork::ledShowSeconds() { uint8_t rr, gg, bb, ww; - set_helligkeit(rr, gg, bb, ww, Effect); + setBrightness(rr, gg, bb, ww, Effect); - led_set_pixel(rr, gg, bb, ww, usedUhrType->getRMatrix(_sekunde48)); + ledSetPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(_sekunde48)); } //------------------------------------------------------------------------------ // Wetterdaten anzeigen //------------------------------------------------------------------------------ -static void show_wetter() { + +void ClockWork::clockShowWeather() { switch (wetterswitch) { // +6h @@ -1326,13 +1333,13 @@ static void show_wetter() { //------------------------------------------------------------------------------ -static void calc_word_array() { +void ClockWork::calcClockFace() { uint8_t rr, gg, bb, ww; if (_stunde == 23 && _minute == 59 && _sekunde >= 50) { countdownToMidnight(); } else { - set_uhrzeit(); + clockSetClock(); } // Helligkeitswert ermitteln @@ -1354,14 +1361,14 @@ static void calc_word_array() { G.hh = G.h22; } - set_helligkeit_ldr(rr, gg, bb, ww, Background); + setBrightnessLdr(rr, gg, bb, ww, Background); // Hintergrund setzen for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - led_set_pixel(rr, gg, bb, ww, i); + ledSetPixel(rr, gg, bb, ww, i); } if (usedUhrType->hasWeatherLayout()) { - show_wetter(); + clockShowWeather(); } } diff --git a/include/wifi_func.hpp b/include/wifi_func.hpp index d057c451..150bd924 100644 --- a/include/wifi_func.hpp +++ b/include/wifi_func.hpp @@ -37,7 +37,7 @@ void WlanStart() { Serial.println(""); // IP-Adresse als Laufschrift anzeigen if (G.bootShowIP) { - zeigeip(ip_adress); + clockWork.showIp(ip_adress); } Serial.printf("-- Ende WlanStart -- \n\n"); diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index fbe9e4e1..e87eae35 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -111,17 +111,17 @@ const char TZ_Europe_Berlin[] = "CET-1CEST,M3.5.0,M10.5.0/3"; RTC_Type RTC; #include "Animation.h" -#include "font.h" +#include "clockWork.h" +Animation *animation; +ClockWork clockWork; + +#include "Animation.hpp" +#include "clockWork.hpp" #include "icons.h" #include "mqtt_func.hpp" #include "openwmap.h" -#include "uhr_func.hpp" #include "wifi_func.hpp" -#include "Animation.hpp" - -Animation *animation; - #define EEPROM_SIZE 512 _Static_assert(sizeof(G) <= EEPROM_SIZE, "Datenstruktur G zu gross für reservierten EEPROM Bereich"); @@ -340,15 +340,15 @@ void setup() { Serial.println("LED Init"); InitLedStrip(G.Colortype); if (G.bootLedBlink) { - led_set_all(0x40, 0x40, 0x40, 0x40); - led_show(); + clockWork.ledSetAllPixels(0x40, 0x40, 0x40, 0x40); + clockWork.ledShow(); delay(20); } if (G.bootLedSweep) { - led_single(20); + clockWork.ledSingle(20); } - led_clear(); - led_show(); + clockWork.ledClear(); + clockWork.ledShow(); G.conf = COMMAND_IDLE; @@ -381,13 +381,13 @@ void setup() { // Start WiFi //------------------------------------- if (G.bootShowWifi) { - show_icon_wlan(0); + clockWork.showWifiSignalStrength(0); } Network_setup(G.hostname); int strength = Network_getQuality(); Serial.printf("Signal strength: %i\n", strength); if (G.bootShowWifi) { - show_icon_wlan(strength); + clockWork.showWifiSignalStrength(strength); } WlanStart(); configTime(0, 0, G.zeitserver); @@ -435,7 +435,7 @@ void setup() { // setup frame if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && G.zeige_min < 2) { - set_farbe_rahmen(); + clockWork.ledSetFrameColor(); } //------------------------------------- @@ -524,12 +524,12 @@ void loop() { if (last_sekunde48 != _sekunde48) { if (G.prog == 0 && G.conf == 0) { if (G.zeige_sek == 1 || G.zeige_min == 2) { - rahmen_clear(); + clockWork.ledClearFrame(); } if (G.zeige_sek > 0) { - show_sekunde(); + clockWork.ledShowSeconds(); } - led_show(); + clockWork.ledShow(); } last_sekunde48 = _sekunde48; } @@ -547,11 +547,11 @@ void loop() { //--- LDR Regelung if ((G.ldr == 1) || G.autoLdrEnabled) { - doLDRLogic(); + clockWork.doLDRLogic(); } if (G.prog == 0 && G.conf == 0) { - led_clear(); + clockWork.ledClear(); G.prog = COMMAND_MODE_WORD_CLOCK; } last_sekunde = _sekunde; @@ -560,7 +560,7 @@ void loop() { if ((_sekunde == 0) | (_sekunde == 10) | (_sekunde == 20) | (_sekunde == 30) | (_sekunde == 40) | (_sekunde == 50)) { wetterswitch++; - led_clear(); + clockWork.ledClear(); if (wetterswitch > 4) { wetterswitch = 1; } @@ -762,7 +762,7 @@ void loop() { case COMMAND_SET_TIME_MANUAL: // Uhrzeit manuell einstellen { eeprom_write(); - led_clear(); + clockWork.ledClear(); parameters_changed = true; G.conf = COMMAND_IDLE; break; @@ -796,7 +796,7 @@ void loop() { G.Colortype = G.param1; eeprom_write(); InitLedStrip(G.Colortype); - led_set_Icon(RGB_I, 100, true); + clockWork.ledSetIcon(RGB_I, 100, true); break; } @@ -846,14 +846,14 @@ void loop() { case COMMAND_MODE_SECONDS: // Sekundenanzeige { if (G.prog_init == 1) { - led_clear(); + clockWork.ledClear(); G.prog_init = 0; } char d1[5]; char d2[5]; sprintf(d1, "%d", (int)(_sekunde / 10)); sprintf(d2, "%d", (int)(_sekunde % 10)); - zahlen(d1[0], d2[0]); + clockWork.ledShowNumbers(d1[0], d2[0]); break; } @@ -862,26 +862,26 @@ void loop() { case COMMAND_MODE_RAINBOW: { if (G.prog_init == 1) { G.prog_init = 0; - led_clear(); + clockWork.ledClear(); count_delay = (11u - G.geschw) * 30u; } if (count_delay >= (11u - G.geschw) * 30u) { switch (G.prog) { case COMMAND_MODE_SCROLLINGTEXT: { - laufschrift(G.ltext); - break; - } + clockWork.scrollingText(G.ltext); + break; + } case COMMAND_MODE_RAINBOWCYCLE: { - rainbowCycle(); + clockWork.rainbowCycle(); break; - } + } case COMMAND_MODE_RAINBOW: { - rainbow(); - break; - } + clockWork.rainbow(); + break; + } default: break; - } + } count_delay = 0; } break; @@ -891,8 +891,8 @@ void loop() { { if (G.prog_init == 1) { G.prog_init = 0; - set_farbe(); - led_show(); + clockWork.ledSetColor(); + clockWork.ledShow(); } break; } @@ -910,19 +910,19 @@ void loop() { } case COMMAND_MODE_WORD_CLOCK: { - calc_word_array(); + clockWork.calcClockFace(); - if (changes_in_array()) { - copy_array(Word_array, Word_array_old); - led_set(true); + if (clockWork.changesInClockface()) { + clockWork.copyClockface(Word_array, Word_array_old); + clockWork.ledSet(true); } else if (parameters_changed) { - led_set(); + clockWork.ledSet(); } parameters_changed = false; if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && G.zeige_min < 2) { - set_farbe_rahmen(); + clockWork.ledSetFrameColor(); } G.prog = COMMAND_IDLE; } diff --git a/webpage/script.js b/webpage/script.js index d441e11d..cd6f1a59 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -420,7 +420,6 @@ function changeColor(color) { rgb[color.index][3] = Math.round(255 * (1.0 - color.alpha)); sendColorData(command, nstr(1)); } -} function createColorPicker() { colorPicker = new iro.ColorPicker("#color-picker", { From 87229903feee3fefd834c7244f506292aaceb3b7 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Mon, 2 Jan 2023 17:42:33 +0100 Subject: [PATCH 10/15] Fixed an Issue where the scrolling text is not displayed in the middle of the Wordclock. --- include/clockWork.h | 2 + include/clockWork.hpp | 47 +++++--- include/font.h | 264 +++++++++++++++++++++++++++++++++++++++++- src/font.cpp | 260 ----------------------------------------- 4 files changed, 296 insertions(+), 277 deletions(-) delete mode 100644 src/font.cpp diff --git a/include/clockWork.h b/include/clockWork.h index ebdc50db..c1893e85 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -26,6 +26,8 @@ class ClockWork { inline void ledClearClock(); inline void ledClearPixel(uint16_t i); + inline void ledClearRow(uint8_t row); + inline void ledClearFrontExeptofFontspace(uint8_t offsetRow); void ledShiftColumnToRight(); diff --git a/include/clockWork.hpp b/include/clockWork.hpp index b03eaa7c..ae717ae5 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -163,6 +163,27 @@ inline void ClockWork::ledClearClock() { //------------------------------------------------------------------------------ +inline void ClockWork::ledClearRow(uint8_t row) { + for (uint8_t i = 0; i < usedUhrType->COLS_MATRIX(); i++) { + ledClearPixel(usedUhrType->getFrontMatrix(row, i)); + } +} + +//------------------------------------------------------------------------------ + +inline void ClockWork::ledClearFrontExeptofFontspace(uint8_t offsetRow) { + for (uint8_t i = 0; i < offsetRow; i++) { + ledClearRow(i); + } + + for (uint8_t i = usedUhrType->ROWS_MATRIX() - 1; i > offsetRow + fontHeight; + i--) { + ledClearRow(i - 1); + } +} + +//------------------------------------------------------------------------------ + inline void ClockWork::ledClearFrame() { for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { ledClearPixel(usedUhrType->getRMatrix(i)); @@ -373,17 +394,14 @@ void ClockWork::ledShiftColumnToRight() { void ClockWork::scrollingText(const char *buf) { static uint8_t i = 0, ii = 0; - static uint8_t offsetRow = 1; + uint8_t offsetRow = (usedUhrType->ROWS_MATRIX() - fontHeight - 1) / 2; uint8_t fontIndex = buf[ii]; ledShiftColumnToRight(); + ledClearFrontExeptofFontspace(offsetRow); - if (usedUhrType->has24HourLayout()) { - offsetRow = 4; - } - - if (i < 5) { - for (uint8_t row = 0; row < 8; row++) { + if (i < fontWidth) { + for (uint8_t row = 0; row < fontHeight; row++) { if (pgm_read_byte(&(font_7x5[fontIndex][i])) & (1u << row)) { ledSetPixel( G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], @@ -396,7 +414,7 @@ void ClockWork::scrollingText(const char *buf) { } } } else { - for (uint8_t row = 0; row < 8; row++) { + for (uint8_t row = 0; row < fontHeight; row++) { ledClearPixel(usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } @@ -404,7 +422,7 @@ void ClockWork::scrollingText(const char *buf) { ledShow(); i++; - if (i > 5) { + if (i > fontWidth) { i = 0; ii++; if (ii > strlen(buf)) { @@ -457,17 +475,16 @@ void ClockWork::showWifiSignalStrength(int strength) { void ClockWork::ledShowNumbers(const char d1, const char d2) { ledClearClock(); static uint8_t offsetLetter0 = 0; - static uint8_t offsetLetter1 = 6; - static uint8_t offsetRow = 1; + static uint8_t offsetLetter1 = fontWidth + 1; + uint8_t offsetRow = (usedUhrType->ROWS_MATRIX() - fontHeight - 1) / 2; if (usedUhrType->has24HourLayout()) { offsetLetter0 = 3; - offsetLetter1 = 9; - offsetRow = 4; + offsetLetter1 = fontWidth + 4; } - for (uint8_t col = 0; col < 5; col++) { - for (uint8_t row = 0; row < 8; row++) { + for (uint8_t col = 0; col < fontWidth; col++) { + for (uint8_t row = 0; row < fontHeight; row++) { // 1. Zahl ohne Offset ledSetPixelForChar(col, row, offsetLetter0, offsetRow, static_cast(d1)); diff --git a/include/font.h b/include/font.h index 4e3bcca6..7d8b8d85 100644 --- a/include/font.h +++ b/include/font.h @@ -1,5 +1,265 @@ +#pragma once + #include -#pragma once +const PROGMEM uint8_t fontHeight = 7; +const PROGMEM uint8_t fontWidth = 5; -extern const PROGMEM byte font_7x5[256][5]; +const PROGMEM byte font_7x5[256][5] = { + {0x00, 0x00, 0x00, 0x00, 0x00}, // 0 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 1 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 2 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 3 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 4 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 5 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 6 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 7 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 8 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 9 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 10 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 11 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 12 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 13 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 14 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 15 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 16 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 17 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 18 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 19 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 20 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 21 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 22 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 23 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 24 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 25 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 26 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 27 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 28 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 29 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 30 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 31 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 32 + {0x00, 0x00, 0x5F, 0x00, 0x00}, // 33 ! + {0x00, 0x07, 0x00, 0x07, 0x00}, // 34 " + {0x14, 0x7F, 0x14, 0x7F, 0x14}, // 35 # + {0x24, 0x2A, 0x6B, 0x2A, 0x12}, // 36 $ + {0x23, 0x13, 0x08, 0x64, 0x62}, // 37 % + {0x36, 0x49, 0x59, 0x26, 0x50}, // 38 & + {0x00, 0x00, 0x04, 0x03, 0x00}, // 39 ' + {0x00, 0x1C, 0x22, 0x41, 0x00}, // 40 ( + {0x00, 0x41, 0x22, 0x1C, 0x00}, // 41 ) + {0x24, 0x18, 0x7E, 0x18, 0x24}, // 42 * + {0x08, 0x08, 0x3E, 0x08, 0x08}, // 43 + + {0x00, 0x00, 0x58, 0x38, 0x00}, // 44 , + {0x08, 0x08, 0x08, 0x08, 0x08}, // 45 - + {0x00, 0x00, 0x60, 0x60, 0x00}, // 46 . + {0x20, 0x10, 0x08, 0x04, 0x02}, // 47 / + {0x3E, 0x51, 0x49, 0x45, 0x3E}, // 48 0 + {0x00, 0x04, 0x42, 0x7F, 0x40}, // 49 1 + {0x42, 0x61, 0x51, 0x49, 0x46}, // 50 2 + {0x22, 0x41, 0x49, 0x49, 0x36}, // 51 3 + {0x18, 0x14, 0x52, 0x7F, 0x50}, // 52 4 + {0x27, 0x45, 0x45, 0x45, 0x39}, // 53 5 + {0x3C, 0x4A, 0x49, 0x49, 0x30}, // 54 6 + {0x61, 0x11, 0x09, 0x05, 0x03}, // 55 7 + {0x36, 0x49, 0x49, 0x49, 0x36}, // 56 8 + {0x06, 0x49, 0x49, 0x49, 0x3E}, // 57 9 + {0x00, 0x00, 0x36, 0x36, 0x00}, // 58 : + {0x00, 0x00, 0x56, 0x36, 0x00}, // 59 ; + {0x00, 0x08, 0x14, 0x22, 0x41}, // 60 < + {0x14, 0x14, 0x14, 0x14, 0x14}, // 61 = + {0x00, 0x41, 0x22, 0x14, 0x08}, // 62 > + {0x02, 0x01, 0x51, 0x09, 0x06}, // 63 ? + {0x3E, 0x41, 0x5D, 0x55, 0x1E}, // 64 @ + {0x7C, 0x12, 0x11, 0x12, 0x7C}, // 65 A + {0x7F, 0x49, 0x49, 0x49, 0x36}, // 66 B + {0x3E, 0x41, 0x41, 0x41, 0x22}, // 67 C + {0x7F, 0x41, 0x41, 0x22, 0x1C}, // 68 D + {0x7F, 0x49, 0x49, 0x49, 0x41}, // 69 E + {0x7F, 0x09, 0x09, 0x09, 0x01}, // 70 F + {0x3E, 0x41, 0x49, 0x49, 0x3A}, // 71 G + {0x7F, 0x08, 0x08, 0x08, 0x7F}, // 72 H + {0x00, 0x41, 0x7F, 0x41, 0x00}, // 73 I + {0x20, 0x40, 0x41, 0x3F, 0x01}, // 74 J + {0x7F, 0x08, 0x14, 0x22, 0x41}, // 75 K + {0x7F, 0x40, 0x40, 0x40, 0x40}, // 76 L + {0x7F, 0x02, 0x04, 0x02, 0x7F}, // 77 M + {0x7F, 0x02, 0x0C, 0x10, 0x7F}, // 78 N + {0x3E, 0x41, 0x41, 0x41, 0x3E}, // 79 O + {0x7F, 0x09, 0x09, 0x09, 0x06}, // 80 P + {0x3E, 0x41, 0x51, 0x21, 0x5E}, // 81 Q + {0x7F, 0x09, 0x19, 0x29, 0x46}, // 82 R + {0x26, 0x49, 0x49, 0x49, 0x32}, // 83 S + {0x01, 0x01, 0x7F, 0x01, 0x01}, // 84 T + {0x3F, 0x40, 0x40, 0x40, 0x3F}, // 85 U + {0x1F, 0x20, 0x40, 0x20, 0x1F}, // 86 V + {0x3F, 0x40, 0x30, 0x40, 0x3F}, // 87 W + {0x63, 0x14, 0x08, 0x14, 0x63}, // 88 X + {0x07, 0x08, 0x70, 0x08, 0x07}, // 89 Y + {0x61, 0x51, 0x49, 0x45, 0x43}, // 90 Z + {0x00, 0x7F, 0x41, 0x41, 0x00}, // 91 [ + {0x02, 0x04, 0x08, 0x10, 0x20}, // 92 BACKSLASH + {0x00, 0x41, 0x41, 0x7F, 0x00}, // 93 ] + {0x04, 0x02, 0x01, 0x02, 0x04}, // 94 ^ + {0x40, 0x40, 0x40, 0x40, 0x40}, // 95 _ + {0x00, 0x00, 0x03, 0x04, 0x00}, // 96 ` + {0x20, 0x54, 0x54, 0x54, 0x78}, // 97 a + {0x7F, 0x44, 0x44, 0x44, 0x38}, // 98 b + {0x38, 0x44, 0x44, 0x44, 0x44}, // 99 c + {0x38, 0x44, 0x44, 0x44, 0x7F}, // 100 d + {0x38, 0x54, 0x54, 0x54, 0x18}, // 101 e + {0x44, 0x7E, 0x45, 0x01, 0x02}, // 102 f + {0x08, 0x54, 0x54, 0x54, 0x3C}, // 103 g + {0x7F, 0x08, 0x04, 0x04, 0x78}, // 104 h + {0x00, 0x44, 0x7D, 0x40, 0x00}, // 105 i + {0x20, 0x40, 0x44, 0x3D, 0x00}, // 106 j + {0x7F, 0x10, 0x28, 0x44, 0x00}, // 107 k + {0x00, 0x41, 0x7F, 0x40, 0x00}, // 108 l + {0x7C, 0x04, 0x7C, 0x04, 0x78}, // 109 m + {0x7C, 0x08, 0x04, 0x04, 0x78}, // 110 n + {0x38, 0x44, 0x44, 0x44, 0x38}, // 111 o + {0x7C, 0x14, 0x14, 0x14, 0x08}, // 112 p + {0x08, 0x14, 0x14, 0x14, 0x7C}, // 113 q + {0x00, 0x7C, 0x08, 0x04, 0x04}, // 114 r + {0x48, 0x54, 0x54, 0x54, 0x24}, // 115 s + {0x04, 0x3F, 0x44, 0x40, 0x20}, // 116 t + {0x3C, 0x40, 0x40, 0x20, 0x7C}, // 117 u + {0x1C, 0x20, 0x40, 0x20, 0x1C}, // 118 v + {0x3C, 0x40, 0x30, 0x40, 0x3C}, // 119 w + {0x44, 0x28, 0x10, 0x28, 0x44}, // 120 x + {0x0C, 0x50, 0x50, 0x50, 0x3C}, // 121 y + {0x44, 0x64, 0x54, 0x4C, 0x44}, // 122 z + {0x08, 0x08, 0x36, 0x41, 0x41}, // 123 { + {0x00, 0x00, 0x77, 0x00, 0x00}, // 124 | + {0x41, 0x41, 0x36, 0x08, 0x08}, // 125 } + {0x08, 0x04, 0x04, 0x08, 0x08}, // 126 ~ + {0x00, 0x00, 0x00, 0x00, 0x00}, // 127 + {0x1E, 0xA1, 0xE1, 0x21, 0x12}, /* 128 € */ + {0x3C, 0x41, 0x40, 0x21, 0x7C}, /* 129  */ + {0x38, 0x54, 0x56, 0x55, 0x18}, /* 130 ‚ */ + {0x20, 0x56, 0x55, 0x56, 0x78}, /* 131 ƒ */ + {0x20, 0x55, 0x54, 0x55, 0x78}, /* 132 „ */ + {0x20, 0x54, 0x55, 0x56, 0x78}, /* 133 … */ + {0x20, 0x54, 0x57, 0x57, 0x78}, /* 134 † */ + {0x1C, 0xA2, 0xE2, 0x22, 0x14}, /* 135 ‡ */ + {0x38, 0x56, 0x55, 0x56, 0x18}, /* 136 ˆ */ + {0x38, 0x55, 0x54, 0x55, 0x18}, /* 137 ‰ */ + {0x38, 0x54, 0x55, 0x56, 0x18}, /* 138 Š */ + {0x00, 0x45, 0x7C, 0x41, 0x00}, /* 139 ‹ */ + {0x00, 0x46, 0x7D, 0x42, 0x00}, /* 140 Œ */ + {0x00, 0x44, 0x7D, 0x42, 0x00}, /* 141  */ + {0x79, 0x14, 0x12, 0x14, 0x79}, /* 142 Ž */ + {0x78, 0x14, 0x17, 0x17, 0x78}, /* 143  */ + {0x7C, 0x54, 0x55, 0x56, 0x44}, /* 144  */ + {0x00, 0x00, 0x00, 0x00, 0x00}, // 145 + {0x00, 0x00, 0x00, 0x00, 0x00}, // 146 + {0x30, 0x4A, 0x49, 0x4A, 0x30}, /* 147 “ */ + {0x38, 0x45, 0x44, 0x45, 0x38}, /* 148 ” */ + {0x38, 0x45, 0x46, 0x44, 0x38}, /* 149 • */ + {0x38, 0x42, 0x41, 0x22, 0x78}, /* 150 – */ + {0x3C, 0x41, 0x42, 0x20, 0x7C}, /* 151 — */ + {0x0C, 0x51, 0x50, 0x51, 0x3C}, /* 152 ˜ */ + {0x3D, 0x42, 0x42, 0x42, 0x3D}, /* 153 ™ */ + {0x3C, 0x41, 0x40, 0x21, 0x7C}, /* 154 š */ + {0x1C, 0x22, 0x63, 0x22, 0x22}, /* 155 › */ + {0x68, 0x7E, 0x49, 0x42, 0x20}, /* 156 œ */ + {0x00, 0x00, 0x00, 0x00, 0x00}, /* 157  */ + {0x00, 0x00, 0x00, 0x00, 0x00}, /* 158 ž */ + {0x20, 0x48, 0x3e, 0x09, 0x02}, /* 159 Ÿ */ + {0x20, 0x54, 0x56, 0x55, 0x78}, /* 160   */ + {0x00, 0x46, 0x7D, 0x40, 0x00}, /* 161  */ + {0x38, 0x44, 0x46, 0x45, 0x38}, /* 162 ¢ */ + {0x3C, 0x40, 0x42, 0x21, 0x7C}, /* 163 £ */ + {0x78, 0x12, 0x09, 0x0A, 0x71}, /* 164 ¤ */ + {0x7C, 0x0A, 0x11, 0x22, 0x7D}, /* 165 ¥ */ + {0x00, 0x06, 0x09, 0x0F, 0x08}, /* 166 ¦ */ + {0x00, 0x06, 0x09, 0x09, 0x06}, /* 167 § */ + {0x20, 0x40, 0x45, 0x48, 0x30}, /* 168 ¨ */ + {0x00, 0x00, 0xF8, 0xF8, 0x18}, /* 169 © */ + {0x18, 0x18, 0xF8, 0xF8, 0x00}, /* 170 ª */ + {0x17, 0x08, 0x04, 0x76, 0x5D}, /* 171 « */ + {0x17, 0x08, 0x1C, 0x76, 0x11}, /* 172 ¬ */ + {0x00, 0x00, 0x7D, 0x00, 0x00}, /* 173 ­ */ + {0x08, 0x14, 0x2A, 0x14, 0x22}, /* 174 ® */ + {0x22, 0x14, 0x2A, 0x14, 0x08}, /* 175 ¯ */ + {0x44, 0x11, 0x44, 0x11, 0x44}, /* 176 ° */ + {0x55, 0xAA, 0x55, 0xAA, 0x55}, /* 177 ± */ + {0x55, 0xFF, 0x55, 0xFF, 0x55}, /* 178 ² */ + {0x00, 0x00, 0xFF, 0xFF, 0x00}, /* 179 ³ */ + {0x18, 0x18, 0xFF, 0xFF, 0x00}, /* 180 ´ */ + {0x24, 0x24, 0xFF, 0xFF, 0x00}, /* 181 µ */ + {0x18, 0xFF, 0x00, 0x00, 0xFF}, /* 182 ¶ */ + {0x18, 0xF8, 0x08, 0x08, 0xF8}, /* 183 · */ + {0x24, 0x24, 0xFF, 0xFF, 0x00}, /* 184 ¸ */ + {0x24, 0xE7, 0x00, 0x00, 0xE7}, /* 185 ¹ */ + {0x00, 0xFF, 0x00, 0x00, 0xFF}, /* 186 º */ + {0x24, 0xE4, 0x04, 0x04, 0xFC}, /* 187 » */ + {0x24, 0x27, 0x20, 0x20, 0x3F}, /* 188 ¼ */ + {0x18, 0x1F, 0x18, 0x18, 0x1F}, /* 189 ½ */ + {0x24, 0x24, 0x3F, 0x3F, 0x00}, /* 190 ¾ */ + {0x18, 0x18, 0xF8, 0xF8, 0x00}, /* 191 ¿ */ + {0x00, 0x00, 0x1F, 0x1F, 0x18}, /* 192 À */ + {0x18, 0x18, 0x1F, 0x1F, 0x18}, /* 193 Á */ + {0x18, 0x18, 0xF8, 0xF8, 0x18}, /* 194  */ + {0x00, 0x00, 0xFF, 0xFF, 0x18}, /* 195 à */ + {0x18, 0x18, 0x18, 0x18, 0x18}, /* 196 Ä */ + {0x18, 0x18, 0xFF, 0xFF, 0x18}, /* 197 Å */ + {0x00, 0x00, 0xFF, 0xFF, 0x24}, /* 198 Æ */ + {0x00, 0xFF, 0x00, 0x00, 0xFF}, /* 199 Ç */ + {0x00, 0x3F, 0x20, 0x20, 0x27}, /* 200 È */ + {0x00, 0xFC, 0x04, 0x04, 0xE4}, /* 201 É */ + {0x24, 0x27, 0x20, 0x20, 0x27}, /* 202 Ê */ + {0x24, 0xE4, 0x04, 0x04, 0xE4}, /* 203 Ë */ + {0x00, 0xFF, 0x00, 0x00, 0xE7}, /* 204 Ì */ + {0x24, 0x24, 0x24, 0x24, 0x24}, /* 205 Í */ + {0x24, 0xE7, 0x00, 0x00, 0xE7}, /* 206 Î */ + {0x24, 0x24, 0x27, 0x27, 0x24}, /* 207 Ï */ + {0x18, 0x1F, 0x18, 0x18, 0x1F}, /* 208 Ð */ + {0x24, 0x24, 0xE4, 0xE4, 0x24}, /* 209 Ñ */ + {0x18, 0xF8, 0x18, 0x18, 0xF8}, /* 210 Ò */ + {0x00, 0x1F, 0x18, 0x18, 0x1F}, /* 211 Ó */ + {0x00, 0x00, 0x3F, 0x3F, 0x24}, /* 212 Ô */ + {0x00, 0x00, 0xFC, 0xFC, 0x24}, /* 213 Õ */ + {0x00, 0xF8, 0x18, 0x18, 0xF8}, /* 214 Ö */ + {0x18, 0xFF, 0x18, 0x18, 0xFF}, /* 215 × */ + {0x24, 0x24, 0xFF, 0xFF, 0x24}, /* 216 Ø */ + {0x18, 0x18, 0x1F, 0x1F, 0x00}, /* 217 Ù */ + {0x00, 0x00, 0xF8, 0xF8, 0x18}, /* 218 Ú */ + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, /* 219 Û */ + {0xF0, 0xF0, 0xF0, 0xF0, 0xF0}, /* 220 Ü */ + {0xFF, 0xFF, 0xFF, 0x00, 0x00}, /* 221 Ý */ + {0x00, 0x00, 0x00, 0xFF, 0xFF}, /* 222 Þ */ + {0x0F, 0x0F, 0x0F, 0x0F, 0x0F}, /* 223 ß */ + {0x38, 0x44, 0x44, 0x38, 0x44}, /* 224 à */ + {0x7e, 0x01, 0x09, 0x49, 0x36}, /* 225 á */ + {0x01, 0x7F, 0x01, 0x01, 0x03}, /* 226 â */ + {0x04, 0x7C, 0x04, 0x7C, 0x04}, /* 227 ã */ + {0x43, 0x65, 0x59, 0x41, 0x63}, /* 228 ä */ + {0x3C, 0x42, 0x42, 0x26, 0x1A}, /* 229 å */ + {0x40, 0x3E, 0x08, 0x08, 0x06}, /* 230 æ */ + {0x04, 0x06, 0x7F, 0x06, 0x04}, /* 231 Pfeil oben */ + {0x10, 0x30, 0x5F, 0x30, 0x10}, /* 232 Pfeil unten */ + {0x1C, 0x6B, 0x49, 0x6B, 0x1C}, /* 233 é */ + {0x5C, 0x62, 0x02, 0x62, 0x5C}, /* 234 ê */ + {0x00, 0x30, 0x4E, 0x49, 0x32}, /* 235 ë */ + {0x18, 0x24, 0x18, 0x24, 0x18}, /* 236 ì */ + {0x2C, 0x12, 0x2A, 0x24, 0x1A}, /* 237 í */ + {0x14, 0x2A, 0x49, 0x49, 0x41}, /* 238 î */ + {0x7E, 0x01, 0x01, 0x01, 0x7E}, /* 239 ï */ + {0x2A, 0x2A, 0x2A, 0x2A, 0x2A}, /* 240 ð */ + {0x00, 0x24, 0x2E, 0x24, 0x00}, /* 241 ñ */ + {0x40, 0x51, 0x4A, 0x44, 0x40}, /* 242 ò */ + {0x40, 0x44, 0x4A, 0x51, 0x40}, /* 243 ó */ + {0x00, 0x00, 0xFE, 0x01, 0x02}, /* 244 ô */ + {0x40, 0x80, 0x7F, 0x00, 0x00}, /* 245 õ */ + {0x08, 0x08, 0x2A, 0x08, 0x08}, /* 246 ö */ + {0x24, 0x12, 0x24, 0x12, 0x00}, /* 247 ÷ */ + {0x00, 0x07, 0x05, 0x07, 0x00}, /* 248 ø */ + {0x00, 0x18, 0x18, 0x00, 0x00}, /* 249 ù */ + {0x00, 0x10, 0x10, 0x10, 0x00}, /* 250 ú */ + {0x10, 0x30, 0x40, 0x38, 0x07}, /* 251 û */ + {0x15, 0x15, 0x1F, 0x00, 0x00}, /* 252 3 hoch */ + {0x1D, 0x15, 0x17, 0x00, 0x00}, /* 253 ý */ + {0x74, 0x54, 0x5C, 0x00, 0x00}, /* 254 2 tief */ + {0x1C, 0x10, 0x78, 0x00, 0x00} /* 255 4 tief */ +}; diff --git a/src/font.cpp b/src/font.cpp deleted file mode 100644 index 815261b6..00000000 --- a/src/font.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include "font.h" - -const PROGMEM byte font_7x5[256][5] = { - {0x00, 0x00, 0x00, 0x00, 0x00}, // 0 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 1 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 2 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 3 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 4 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 5 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 6 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 7 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 8 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 9 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 10 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 12 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 13 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 14 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 15 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 16 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 17 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 18 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 19 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 20 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 21 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 22 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 23 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 24 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 25 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 26 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 27 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 28 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 29 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 30 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 31 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 32 - {0x00, 0x00, 0x5F, 0x00, 0x00}, // 33 ! - {0x00, 0x07, 0x00, 0x07, 0x00}, // 34 " - {0x14, 0x7F, 0x14, 0x7F, 0x14}, // 35 # - {0x24, 0x2A, 0x6B, 0x2A, 0x12}, // 36 $ - {0x23, 0x13, 0x08, 0x64, 0x62}, // 37 % - {0x36, 0x49, 0x59, 0x26, 0x50}, // 38 & - {0x00, 0x00, 0x04, 0x03, 0x00}, // 39 ' - {0x00, 0x1C, 0x22, 0x41, 0x00}, // 40 ( - {0x00, 0x41, 0x22, 0x1C, 0x00}, // 41 ) - {0x24, 0x18, 0x7E, 0x18, 0x24}, // 42 * - {0x08, 0x08, 0x3E, 0x08, 0x08}, // 43 + - {0x00, 0x00, 0x58, 0x38, 0x00}, // 44 , - {0x08, 0x08, 0x08, 0x08, 0x08}, // 45 - - {0x00, 0x00, 0x60, 0x60, 0x00}, // 46 . - {0x20, 0x10, 0x08, 0x04, 0x02}, // 47 / - {0x3E, 0x51, 0x49, 0x45, 0x3E}, // 48 0 - {0x00, 0x04, 0x42, 0x7F, 0x40}, // 49 1 - {0x42, 0x61, 0x51, 0x49, 0x46}, // 50 2 - {0x22, 0x41, 0x49, 0x49, 0x36}, // 51 3 - {0x18, 0x14, 0x52, 0x7F, 0x50}, // 52 4 - {0x27, 0x45, 0x45, 0x45, 0x39}, // 53 5 - {0x3C, 0x4A, 0x49, 0x49, 0x30}, // 54 6 - {0x61, 0x11, 0x09, 0x05, 0x03}, // 55 7 - {0x36, 0x49, 0x49, 0x49, 0x36}, // 56 8 - {0x06, 0x49, 0x49, 0x49, 0x3E}, // 57 9 - {0x00, 0x00, 0x36, 0x36, 0x00}, // 58 : - {0x00, 0x00, 0x56, 0x36, 0x00}, // 59 ; - {0x00, 0x08, 0x14, 0x22, 0x41}, // 60 < - {0x14, 0x14, 0x14, 0x14, 0x14}, // 61 = - {0x00, 0x41, 0x22, 0x14, 0x08}, // 62 > - {0x02, 0x01, 0x51, 0x09, 0x06}, // 63 ? - {0x3E, 0x41, 0x5D, 0x55, 0x1E}, // 64 @ - {0x7C, 0x12, 0x11, 0x12, 0x7C}, // 65 A - {0x7F, 0x49, 0x49, 0x49, 0x36}, // 66 B - {0x3E, 0x41, 0x41, 0x41, 0x22}, // 67 C - {0x7F, 0x41, 0x41, 0x22, 0x1C}, // 68 D - {0x7F, 0x49, 0x49, 0x49, 0x41}, // 69 E - {0x7F, 0x09, 0x09, 0x09, 0x01}, // 70 F - {0x3E, 0x41, 0x49, 0x49, 0x3A}, // 71 G - {0x7F, 0x08, 0x08, 0x08, 0x7F}, // 72 H - {0x00, 0x41, 0x7F, 0x41, 0x00}, // 73 I - {0x20, 0x40, 0x41, 0x3F, 0x01}, // 74 J - {0x7F, 0x08, 0x14, 0x22, 0x41}, // 75 K - {0x7F, 0x40, 0x40, 0x40, 0x40}, // 76 L - {0x7F, 0x02, 0x04, 0x02, 0x7F}, // 77 M - {0x7F, 0x02, 0x0C, 0x10, 0x7F}, // 78 N - {0x3E, 0x41, 0x41, 0x41, 0x3E}, // 79 O - {0x7F, 0x09, 0x09, 0x09, 0x06}, // 80 P - {0x3E, 0x41, 0x51, 0x21, 0x5E}, // 81 Q - {0x7F, 0x09, 0x19, 0x29, 0x46}, // 82 R - {0x26, 0x49, 0x49, 0x49, 0x32}, // 83 S - {0x01, 0x01, 0x7F, 0x01, 0x01}, // 84 T - {0x3F, 0x40, 0x40, 0x40, 0x3F}, // 85 U - {0x1F, 0x20, 0x40, 0x20, 0x1F}, // 86 V - {0x3F, 0x40, 0x30, 0x40, 0x3F}, // 87 W - {0x63, 0x14, 0x08, 0x14, 0x63}, // 88 X - {0x07, 0x08, 0x70, 0x08, 0x07}, // 89 Y - {0x61, 0x51, 0x49, 0x45, 0x43}, // 90 Z - {0x00, 0x7F, 0x41, 0x41, 0x00}, // 91 [ - {0x02, 0x04, 0x08, 0x10, 0x20}, // 92 BACKSLASH - {0x00, 0x41, 0x41, 0x7F, 0x00}, // 93 ] - {0x04, 0x02, 0x01, 0x02, 0x04}, // 94 ^ - {0x40, 0x40, 0x40, 0x40, 0x40}, // 95 _ - {0x00, 0x00, 0x03, 0x04, 0x00}, // 96 ` - {0x20, 0x54, 0x54, 0x54, 0x78}, // 97 a - {0x7F, 0x44, 0x44, 0x44, 0x38}, // 98 b - {0x38, 0x44, 0x44, 0x44, 0x44}, // 99 c - {0x38, 0x44, 0x44, 0x44, 0x7F}, // 100 d - {0x38, 0x54, 0x54, 0x54, 0x18}, // 101 e - {0x44, 0x7E, 0x45, 0x01, 0x02}, // 102 f - {0x08, 0x54, 0x54, 0x54, 0x3C}, // 103 g - {0x7F, 0x08, 0x04, 0x04, 0x78}, // 104 h - {0x00, 0x44, 0x7D, 0x40, 0x00}, // 105 i - {0x20, 0x40, 0x44, 0x3D, 0x00}, // 106 j - {0x7F, 0x10, 0x28, 0x44, 0x00}, // 107 k - {0x00, 0x41, 0x7F, 0x40, 0x00}, // 108 l - {0x7C, 0x04, 0x7C, 0x04, 0x78}, // 109 m - {0x7C, 0x08, 0x04, 0x04, 0x78}, // 110 n - {0x38, 0x44, 0x44, 0x44, 0x38}, // 111 o - {0x7C, 0x14, 0x14, 0x14, 0x08}, // 112 p - {0x08, 0x14, 0x14, 0x14, 0x7C}, // 113 q - {0x00, 0x7C, 0x08, 0x04, 0x04}, // 114 r - {0x48, 0x54, 0x54, 0x54, 0x24}, // 115 s - {0x04, 0x3F, 0x44, 0x40, 0x20}, // 116 t - {0x3C, 0x40, 0x40, 0x20, 0x7C}, // 117 u - {0x1C, 0x20, 0x40, 0x20, 0x1C}, // 118 v - {0x3C, 0x40, 0x30, 0x40, 0x3C}, // 119 w - {0x44, 0x28, 0x10, 0x28, 0x44}, // 120 x - {0x0C, 0x50, 0x50, 0x50, 0x3C}, // 121 y - {0x44, 0x64, 0x54, 0x4C, 0x44}, // 122 z - {0x08, 0x08, 0x36, 0x41, 0x41}, // 123 { - {0x00, 0x00, 0x77, 0x00, 0x00}, // 124 | - {0x41, 0x41, 0x36, 0x08, 0x08}, // 125 } - {0x08, 0x04, 0x04, 0x08, 0x08}, // 126 ~ - {0x00, 0x00, 0x00, 0x00, 0x00}, // 127 - {0x1E, 0xA1, 0xE1, 0x21, 0x12}, /* 128 € */ - {0x3C, 0x41, 0x40, 0x21, 0x7C}, /* 129  */ - {0x38, 0x54, 0x56, 0x55, 0x18}, /* 130 ‚ */ - {0x20, 0x56, 0x55, 0x56, 0x78}, /* 131 ƒ */ - {0x20, 0x55, 0x54, 0x55, 0x78}, /* 132 „ */ - {0x20, 0x54, 0x55, 0x56, 0x78}, /* 133 … */ - {0x20, 0x54, 0x57, 0x57, 0x78}, /* 134 † */ - {0x1C, 0xA2, 0xE2, 0x22, 0x14}, /* 135 ‡ */ - {0x38, 0x56, 0x55, 0x56, 0x18}, /* 136 ˆ */ - {0x38, 0x55, 0x54, 0x55, 0x18}, /* 137 ‰ */ - {0x38, 0x54, 0x55, 0x56, 0x18}, /* 138 Š */ - {0x00, 0x45, 0x7C, 0x41, 0x00}, /* 139 ‹ */ - {0x00, 0x46, 0x7D, 0x42, 0x00}, /* 140 Œ */ - {0x00, 0x44, 0x7D, 0x42, 0x00}, /* 141  */ - {0x79, 0x14, 0x12, 0x14, 0x79}, /* 142 Ž */ - {0x78, 0x14, 0x17, 0x17, 0x78}, /* 143  */ - {0x7C, 0x54, 0x55, 0x56, 0x44}, /* 144  */ - {0x00, 0x00, 0x00, 0x00, 0x00}, // 145 - {0x00, 0x00, 0x00, 0x00, 0x00}, // 146 - {0x30, 0x4A, 0x49, 0x4A, 0x30}, /* 147 “ */ - {0x38, 0x45, 0x44, 0x45, 0x38}, /* 148 ” */ - {0x38, 0x45, 0x46, 0x44, 0x38}, /* 149 • */ - {0x38, 0x42, 0x41, 0x22, 0x78}, /* 150 – */ - {0x3C, 0x41, 0x42, 0x20, 0x7C}, /* 151 — */ - {0x0C, 0x51, 0x50, 0x51, 0x3C}, /* 152 ˜ */ - {0x3D, 0x42, 0x42, 0x42, 0x3D}, /* 153 ™ */ - {0x3C, 0x41, 0x40, 0x21, 0x7C}, /* 154 š */ - {0x1C, 0x22, 0x63, 0x22, 0x22}, /* 155 › */ - {0x68, 0x7E, 0x49, 0x42, 0x20}, /* 156 œ */ - {0x00, 0x00, 0x00, 0x00, 0x00}, /* 157  */ - {0x00, 0x00, 0x00, 0x00, 0x00}, /* 158 ž */ - {0x20, 0x48, 0x3e, 0x09, 0x02}, /* 159 Ÿ */ - {0x20, 0x54, 0x56, 0x55, 0x78}, /* 160   */ - {0x00, 0x46, 0x7D, 0x40, 0x00}, /* 161  */ - {0x38, 0x44, 0x46, 0x45, 0x38}, /* 162 ¢ */ - {0x3C, 0x40, 0x42, 0x21, 0x7C}, /* 163 £ */ - {0x78, 0x12, 0x09, 0x0A, 0x71}, /* 164 ¤ */ - {0x7C, 0x0A, 0x11, 0x22, 0x7D}, /* 165 ¥ */ - {0x00, 0x06, 0x09, 0x0F, 0x08}, /* 166 ¦ */ - {0x00, 0x06, 0x09, 0x09, 0x06}, /* 167 § */ - {0x20, 0x40, 0x45, 0x48, 0x30}, /* 168 ¨ */ - {0x00, 0x00, 0xF8, 0xF8, 0x18}, /* 169 © */ - {0x18, 0x18, 0xF8, 0xF8, 0x00}, /* 170 ª */ - {0x17, 0x08, 0x04, 0x76, 0x5D}, /* 171 « */ - {0x17, 0x08, 0x1C, 0x76, 0x11}, /* 172 ¬ */ - {0x00, 0x00, 0x7D, 0x00, 0x00}, /* 173 ­ */ - {0x08, 0x14, 0x2A, 0x14, 0x22}, /* 174 ® */ - {0x22, 0x14, 0x2A, 0x14, 0x08}, /* 175 ¯ */ - {0x44, 0x11, 0x44, 0x11, 0x44}, /* 176 ° */ - {0x55, 0xAA, 0x55, 0xAA, 0x55}, /* 177 ± */ - {0x55, 0xFF, 0x55, 0xFF, 0x55}, /* 178 ² */ - {0x00, 0x00, 0xFF, 0xFF, 0x00}, /* 179 ³ */ - {0x18, 0x18, 0xFF, 0xFF, 0x00}, /* 180 ´ */ - {0x24, 0x24, 0xFF, 0xFF, 0x00}, /* 181 µ */ - {0x18, 0xFF, 0x00, 0x00, 0xFF}, /* 182 ¶ */ - {0x18, 0xF8, 0x08, 0x08, 0xF8}, /* 183 · */ - {0x24, 0x24, 0xFF, 0xFF, 0x00}, /* 184 ¸ */ - {0x24, 0xE7, 0x00, 0x00, 0xE7}, /* 185 ¹ */ - {0x00, 0xFF, 0x00, 0x00, 0xFF}, /* 186 º */ - {0x24, 0xE4, 0x04, 0x04, 0xFC}, /* 187 » */ - {0x24, 0x27, 0x20, 0x20, 0x3F}, /* 188 ¼ */ - {0x18, 0x1F, 0x18, 0x18, 0x1F}, /* 189 ½ */ - {0x24, 0x24, 0x3F, 0x3F, 0x00}, /* 190 ¾ */ - {0x18, 0x18, 0xF8, 0xF8, 0x00}, /* 191 ¿ */ - {0x00, 0x00, 0x1F, 0x1F, 0x18}, /* 192 À */ - {0x18, 0x18, 0x1F, 0x1F, 0x18}, /* 193 Á */ - {0x18, 0x18, 0xF8, 0xF8, 0x18}, /* 194  */ - {0x00, 0x00, 0xFF, 0xFF, 0x18}, /* 195 à */ - {0x18, 0x18, 0x18, 0x18, 0x18}, /* 196 Ä */ - {0x18, 0x18, 0xFF, 0xFF, 0x18}, /* 197 Å */ - {0x00, 0x00, 0xFF, 0xFF, 0x24}, /* 198 Æ */ - {0x00, 0xFF, 0x00, 0x00, 0xFF}, /* 199 Ç */ - {0x00, 0x3F, 0x20, 0x20, 0x27}, /* 200 È */ - {0x00, 0xFC, 0x04, 0x04, 0xE4}, /* 201 É */ - {0x24, 0x27, 0x20, 0x20, 0x27}, /* 202 Ê */ - {0x24, 0xE4, 0x04, 0x04, 0xE4}, /* 203 Ë */ - {0x00, 0xFF, 0x00, 0x00, 0xE7}, /* 204 Ì */ - {0x24, 0x24, 0x24, 0x24, 0x24}, /* 205 Í */ - {0x24, 0xE7, 0x00, 0x00, 0xE7}, /* 206 Î */ - {0x24, 0x24, 0x27, 0x27, 0x24}, /* 207 Ï */ - {0x18, 0x1F, 0x18, 0x18, 0x1F}, /* 208 Ð */ - {0x24, 0x24, 0xE4, 0xE4, 0x24}, /* 209 Ñ */ - {0x18, 0xF8, 0x18, 0x18, 0xF8}, /* 210 Ò */ - {0x00, 0x1F, 0x18, 0x18, 0x1F}, /* 211 Ó */ - {0x00, 0x00, 0x3F, 0x3F, 0x24}, /* 212 Ô */ - {0x00, 0x00, 0xFC, 0xFC, 0x24}, /* 213 Õ */ - {0x00, 0xF8, 0x18, 0x18, 0xF8}, /* 214 Ö */ - {0x18, 0xFF, 0x18, 0x18, 0xFF}, /* 215 × */ - {0x24, 0x24, 0xFF, 0xFF, 0x24}, /* 216 Ø */ - {0x18, 0x18, 0x1F, 0x1F, 0x00}, /* 217 Ù */ - {0x00, 0x00, 0xF8, 0xF8, 0x18}, /* 218 Ú */ - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, /* 219 Û */ - {0xF0, 0xF0, 0xF0, 0xF0, 0xF0}, /* 220 Ü */ - {0xFF, 0xFF, 0xFF, 0x00, 0x00}, /* 221 Ý */ - {0x00, 0x00, 0x00, 0xFF, 0xFF}, /* 222 Þ */ - {0x0F, 0x0F, 0x0F, 0x0F, 0x0F}, /* 223 ß */ - {0x38, 0x44, 0x44, 0x38, 0x44}, /* 224 à */ - {0x7e, 0x01, 0x09, 0x49, 0x36}, /* 225 á */ - {0x01, 0x7F, 0x01, 0x01, 0x03}, /* 226 â */ - {0x04, 0x7C, 0x04, 0x7C, 0x04}, /* 227 ã */ - {0x43, 0x65, 0x59, 0x41, 0x63}, /* 228 ä */ - {0x3C, 0x42, 0x42, 0x26, 0x1A}, /* 229 å */ - {0x40, 0x3E, 0x08, 0x08, 0x06}, /* 230 æ */ - {0x04, 0x06, 0x7F, 0x06, 0x04}, /* 231 Pfeil oben */ - {0x10, 0x30, 0x5F, 0x30, 0x10}, /* 232 Pfeil unten */ - {0x1C, 0x6B, 0x49, 0x6B, 0x1C}, /* 233 é */ - {0x5C, 0x62, 0x02, 0x62, 0x5C}, /* 234 ê */ - {0x00, 0x30, 0x4E, 0x49, 0x32}, /* 235 ë */ - {0x18, 0x24, 0x18, 0x24, 0x18}, /* 236 ì */ - {0x2C, 0x12, 0x2A, 0x24, 0x1A}, /* 237 í */ - {0x14, 0x2A, 0x49, 0x49, 0x41}, /* 238 î */ - {0x7E, 0x01, 0x01, 0x01, 0x7E}, /* 239 ï */ - {0x2A, 0x2A, 0x2A, 0x2A, 0x2A}, /* 240 ð */ - {0x00, 0x24, 0x2E, 0x24, 0x00}, /* 241 ñ */ - {0x40, 0x51, 0x4A, 0x44, 0x40}, /* 242 ò */ - {0x40, 0x44, 0x4A, 0x51, 0x40}, /* 243 ó */ - {0x00, 0x00, 0xFE, 0x01, 0x02}, /* 244 ô */ - {0x40, 0x80, 0x7F, 0x00, 0x00}, /* 245 õ */ - {0x08, 0x08, 0x2A, 0x08, 0x08}, /* 246 ö */ - {0x24, 0x12, 0x24, 0x12, 0x00}, /* 247 ÷ */ - {0x00, 0x07, 0x05, 0x07, 0x00}, /* 248 ø */ - {0x00, 0x18, 0x18, 0x00, 0x00}, /* 249 ù */ - {0x00, 0x10, 0x10, 0x10, 0x00}, /* 250 ú */ - {0x10, 0x30, 0x40, 0x38, 0x07}, /* 251 û */ - {0x15, 0x15, 0x1F, 0x00, 0x00}, /* 252 3 hoch */ - {0x1D, 0x15, 0x17, 0x00, 0x00}, /* 253 ý */ - {0x74, 0x54, 0x5C, 0x00, 0x00}, /* 254 2 tief */ - {0x1C, 0x10, 0x78, 0x00, 0x00} /* 255 4 tief */ -}; From c3ab625f3f409845f14ef8a6fab441efe99f14d4 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Tue, 3 Jan 2023 10:51:12 +0100 Subject: [PATCH 11/15] Refactored MQTT_func.h to a mqtt Class in own files .h and .hpp no further changes to behaviour. --- include/mqtt.h | 19 +++++++++++ include/{mqtt_func.hpp => mqtt.hpp} | 53 +++++++++++++++++++++++++---- src/Wortuhr.cpp | 22 +++++------- 3 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 include/mqtt.h rename include/{mqtt_func.hpp => mqtt.hpp} (58%) diff --git a/include/mqtt.h b/include/mqtt.h new file mode 100644 index 00000000..7ebc54c0 --- /dev/null +++ b/include/mqtt.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +class Mqtt { +private: + void reconnect(); + static void callback(char *topic, byte *payload, unsigned int length); + +public: + Mqtt() = default; + ~Mqtt() = default; + + void init(); + void reInit(); + void loop(); + + bool getConnected(); +}; diff --git a/include/mqtt_func.hpp b/include/mqtt.hpp similarity index 58% rename from include/mqtt_func.hpp rename to include/mqtt.hpp index b13ef555..2fb18c87 100644 --- a/include/mqtt_func.hpp +++ b/include/mqtt.hpp @@ -1,9 +1,46 @@ -#pragma once -// =========================================================== -// Callback Funktion von MQTT. Die Funktion wird aufgerufen -// wenn ein Wert empfangen wurde. -// =========================================================== -void MQTT_callback(char *topic, byte *payload, unsigned int length) { + +#include "Uhr.h" +#include "mqtt.h" +#include +#include +#include + +extern WiFiClient client; + +PubSubClient mqttClient(client); + +//------------------------------------------------------------------------------ + +void Mqtt::init() { + mqttClient.setServer(G.mqtt.serverAdress, G.mqtt.port); + mqttClient.setCallback(callback); + mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); + mqttClient.subscribe(G.mqtt.topic); +} + +//------------------------------------------------------------------------------ + +void Mqtt::reInit() { + mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); + reconnect(); +} + +//------------------------------------------------------------------------------ + +bool Mqtt::getConnected() { return mqttClient.connected(); } + +//------------------------------------------------------------------------------ + +void Mqtt::loop() { + if (!mqttClient.connected()) { + reconnect(); + } + mqttClient.loop(); +} + +//------------------------------------------------------------------------------ + +void Mqtt::callback(char *topic, byte *payload, unsigned int length) { //{"state": "on", "brightness": 255, "color": [255, 255, 255], "effect": //"rainbow"} StaticJsonDocument<200> doc; @@ -58,7 +95,9 @@ void MQTT_callback(char *topic, byte *payload, unsigned int length) { } } -void MQTT_reconnect() { +//------------------------------------------------------------------------------ + +void Mqtt::reconnect() { mqttClient.subscribe(G.mqtt.topic); Serial.println("MQTT Connected..."); } diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index e87eae35..0c1a50d3 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -57,7 +57,6 @@ bool DEBUG = true; // DEBUG ON|OFF wenn auskommentiert #include #include #include -#include #include #include #include @@ -97,7 +96,6 @@ NeoPixelBus *strip_RGB = NULL; NeoPixelBus *strip_RGBW = NULL; WiFiClient client; -PubSubClient mqttClient(client); //--OTA-- ESP8266WebServer httpServer(81); @@ -112,13 +110,16 @@ RTC_Type RTC; #include "Animation.h" #include "clockWork.h" +#include "mqtt.h" + Animation *animation; ClockWork clockWork; +Mqtt mqtt; #include "Animation.hpp" #include "clockWork.hpp" #include "icons.h" -#include "mqtt_func.hpp" +#include "mqtt.hpp" #include "openwmap.h" #include "wifi_func.hpp" @@ -412,10 +413,7 @@ void setup() { //------------------------------------- if (G.mqtt.state == 1) { - mqttClient.setServer(G.mqtt.serverAdress, G.mqtt.port); - mqttClient.setCallback(MQTT_callback); - mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); - mqttClient.subscribe(G.mqtt.topic); + mqtt.init(); } //------------------------------------- @@ -504,10 +502,7 @@ void loop() { // MQTT //------------------------------------------------ if (G.mqtt.state == 1 && WiFi.status() == WL_CONNECTED) { - if (!mqttClient.connected()) { - MQTT_reconnect(); - } - mqttClient.loop(); + mqtt.loop(); } //------------------------------------------------ @@ -770,9 +765,8 @@ void loop() { case COMMAND_SET_MQTT: // MQTT Einstellungen { - if (!mqttClient.connected() && G.mqtt.state) { - mqttClient.connect(G.mqtt.clientId, G.mqtt.user, G.mqtt.password); - MQTT_reconnect(); + if (G.mqtt.state && !mqtt.getConnected()) { + mqtt.reInit(); } eeprom_write(); G.conf = COMMAND_IDLE; From 8ced08c13180247eb1df40800d2c2965d43d6237 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Wed, 4 Jan 2023 23:29:05 +0100 Subject: [PATCH 12/15] Further Refactoring of the code. Moved essential Clock Functions from Wortuhr.cpp to ClockWork Class in that way almost all led funtions could be private. Added a single ClockWork.loop() to the Wortuhr.cpp. Also Updatet Version Tag and Added Contributor to list. --- include/clockWork.h | 60 ++--- include/clockWork.hpp | 513 +++++++++++++++++++++++++++++++++++++++++- include/wifi_func.hpp | 2 +- package.json | 6 +- platformio.ini | 1 + src/Wortuhr.cpp | 504 ++--------------------------------------- webpage/index.html | 2 +- 7 files changed, 567 insertions(+), 521 deletions(-) diff --git a/include/clockWork.h b/include/clockWork.h index c1893e85..924d36a6 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -28,8 +28,30 @@ class ClockWork { inline void ledClearPixel(uint16_t i); inline void ledClearRow(uint8_t row); inline void ledClearFrontExeptofFontspace(uint8_t offsetRow); - + inline void ledClearFrame(); void ledShiftColumnToRight(); + void ledShowSeconds(); + void ledShowNumbers(const char d1, const char d2); + void ledSet(bool changed = false); + void ledSetColor(); + void ledSetIcon(uint8_t num_icon, uint8_t brightness, bool rgb_icon); + void ledSetFrameColor(); + + void ledClear(); + void ledSingle(uint8_t wait); + void ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww); + + void loopSecondsFrame(); + void loopWeather(); + void loopLdrLogic(); + + void rainbow(); + void rainbowCycle(); + void scrollingText(const char *buf); + + bool changesInClockface(); + void copyClockface(const uint16_t source[], uint16_t destination[]); + void calcClockFace(); void clockSetHour(const uint8_t std, const uint8_t voll); void clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll); @@ -41,36 +63,22 @@ class ClockWork { ClockWork() = default; ~ClockWork() = default; + iUhrType *getPointer(uint8_t num); + void initLedStrip(uint8_t num); + + void ledShow(); + RgbColor ledGetPixel(uint16_t i); RgbwColor ledGetPixelRgbw(uint16_t i); void ledSetPixelColorObject(uint16_t i, RgbColor color); void ledSetPixelColorObjectRgbw(uint16_t i, RgbwColor color); - void ledShow(); - void ledClear(); - inline void ledClearFrame(); - void ledSet(bool changed = false); - - bool changesInClockface(); - void copyClockface(const uint16_t source[], uint16_t destination[]); - void calcClockFace(); + void loop(struct tm &tm); - void ledSetIcon(uint8_t num_icon, uint8_t brightness, bool rgb_icon); - void ledSingle(uint8_t wait); - void ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww); - - void ledSetColor(); - void doLDRLogic(); - void ledSetFrameColor(); - - void rainbow(); - void rainbowCycle(); - void scrollingText(const char *buf); - void showIp(const char *buf); - - void showWifiSignalStrength(int strength); - void ledShowNumbers(const char d1, const char d2); - - void ledShowSeconds(); + void initBootLed(); + void initBootLedBlink(); + void initBootLedSweep(); + void initBootShowIp(const char *buf); + void initBootWifiSignalStrength(int strength); }; diff --git a/include/clockWork.hpp b/include/clockWork.hpp index ae717ae5..c4950261 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -5,6 +5,8 @@ #include "clockWork.h" #include "font.h" #include "icons.h" +#include "mqtt.h" +#include "openwmap.h" #include extern NeoPixelBus *strip_RGB; @@ -12,6 +14,7 @@ extern NeoPixelBus *strip_RGBW; extern iUhrType *usedUhrType; extern Animation *animation; +extern Mqtt mqtt; void ClockWork::ledSetPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { @@ -294,7 +297,7 @@ void ClockWork::ledSetColor() { // Routine Helligkeitsregelung //------------------------------------------------------------------------------ -void ClockWork::doLDRLogic() { +void ClockWork::loopLdrLogic() { int16_t lux = analogRead(A0); // Range 0-1023 uint8_t ldrValOld = ldrVal; @@ -433,7 +436,7 @@ void ClockWork::scrollingText(const char *buf) { //------------------------------------------------------------------------------ -void ClockWork::showIp(const char *buf) { +void ClockWork::initBootShowIp(const char *buf) { uint8_t StringLength = strlen(buf); StringLength = StringLength * 6; // Times 6, because thats the length of a // char in the 7x5 font plus spacing @@ -460,7 +463,7 @@ void ClockWork::ledSetPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, // show signal-strenght by using different brightness for the individual rings //------------------------------------------------------------------------------ -void ClockWork::showWifiSignalStrength(int strength) { +void ClockWork::initBootWifiSignalStrength(int strength) { if (strength <= 100) { ledSetIcon(WLAN100, 100); } else if (strength <= 60) { @@ -1389,3 +1392,507 @@ void ClockWork::calcClockFace() { clockShowWeather(); } } + +//------------------------------------------------------------------------------ + +iUhrType *ClockWork::getPointer(uint8_t type) { + switch (type) { + case 1: + return &Uhr_114_type; + case 2: + return &Uhr_114_Alternative_type; + case 6: + return &Uhr_114_2Clock_type; + case 9: + return &Uhr_114_dutch_type; + case 3: + return &Uhr_125_type; + case 8: + return &Uhr_125_type2_type; + case 4: + return &Uhr_169_type; + case 5: + return &Uhr_242_type; + case 7: + return &Uhr_291_type; + default: + return nullptr; + } +} + +//------------------------------------------------------------------------------ + +void ClockWork::initLedStrip(uint8_t num) { + NeoMultiFeature::setColortype(num); + if (num == Grbw) { + if (strip_RGB != NULL) { + delete strip_RGB; // delete the previous dynamically created strip + strip_RGB = NULL; + } + if (strip_RGBW == NULL) { + strip_RGBW = new NeoPixelBus( + usedUhrType->NUM_PIXELS()); + strip_RGBW->Begin(); + } + } else { + if (strip_RGBW != NULL) { + delete strip_RGBW; // delete the previous dynamically created strip + strip_RGBW = NULL; + } + if (strip_RGB == NULL) { + strip_RGB = new NeoPixelBus( + usedUhrType->NUM_PIXELS()); + strip_RGB->Begin(); + } + } +} + +//------------------------------------------------------------------------------ + +void ClockWork::loop(struct tm &tm) { + unsigned long currentMillis = millis(); + count_delay += currentMillis - previousMillis; + if (usedUhrType->hasSecondsFrame()) { + count_millis48 += currentMillis - previousMillis; + } + previousMillis = currentMillis; + + // lass die Zeit im Demo Mode der Animation schneller ablaufen + animation->demoMode(_minute, _sekunde); + + //------------------------------------------------ + // SecondsFrame + //------------------------------------------------ + if (usedUhrType->hasSecondsFrame()) { + loopSecondsFrame(); + } + + //------------------------------------------------ + // Sekunde und LDR Regelung + //------------------------------------------------ + if (last_sekunde != _sekunde) { + + if (DEBUG == true) { + char currentTime[80]; + strftime(currentTime, sizeof(currentTime), "%F %T (%z)\n", &tm); + Serial.printf(currentTime); + } + + // Wetteruhr + if (usedUhrType->hasWeatherLayout()) { + weather_tag++; + } + + //--- LDR Regelung + if ((G.ldr == 1) || G.autoLdrEnabled) { + loopLdrLogic(); + } + + if (G.prog == 0 && G.conf == 0) { + ledClear(); + G.prog = COMMAND_MODE_WORD_CLOCK; + } + + last_sekunde = _sekunde; + + if (usedUhrType->hasWeatherLayout()) { + loopWeather(); + } + } + + //------------------------------------------------ + // Minute + //------------------------------------------------ + if (last_minute != _minute) { + _sekunde48 = 0; + last_minute = _minute; + } + + //------------------------------------------------ + // Wetterdaten abrufen + //------------------------------------------------ + if (usedUhrType->hasWeatherLayout() && + weather_tag >= 600) { // @Eisbaeeer changed for Debug (soll 600) + weather_tag = 0; + if (WiFi.status() == WL_CONNECTED) { + getweather(); + } + } + + switch (G.conf) { + + case COMMAND_RESET: { + delay(500); + ESP.reset(); + ESP.restart(); + while (true) { + } + break; + } + + case COMMAND_REQUEST_MQTT_VALUES: { + DynamicJsonDocument config(1024); + config["command"] = "mqtt"; + config["MQTT_State"] = G.mqtt.state; + config["MQTT_Port"] = G.mqtt.port; + config["MQTT_Server"] = G.mqtt.serverAdress; + config["MQTT_User"] = G.mqtt.user; + config["MQTT_Pass"] = G.mqtt.password; + config["MQTT_ClientId"] = G.mqtt.clientId; + config["MQTT_Topic"] = G.mqtt.topic; + serializeJson(config, str); + Serial.print("Sending Payload:"); + Serial.println(str); + webSocket.sendTXT(G.client_nr, str, strlen(str)); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_REQUEST_CONFIG_VALUES: { + DynamicJsonDocument config(1024); + config["command"] = "config"; + config["ssid"] = Network_getSSID(); + config["zeitserver"] = G.zeitserver; + config["hostname"] = G.hostname; + config["ltext"] = G.ltext; + config["h6"] = G.h6; + config["h8"] = G.h8; + config["h12"] = G.h12; + config["h16"] = G.h16; + config["h18"] = G.h18; + config["h20"] = G.h20; + config["h22"] = G.h22; + config["h24"] = G.h24; + for (uint8_t i = 0; i < 5; i++) { + sprintf(s, "spv%d", i); + config[s] = static_cast(G.Sprachvariation[i]); + } + config["hell"] = G.hell; + config["zeige_sek"] = G.zeige_sek; + config["zeige_min"] = G.zeige_min; + config["ldr"] = G.ldr; + config["ldrCal"] = G.ldrCal; + config["cityid"] = G.openWeatherMap.cityid; + config["apikey"] = G.openWeatherMap.apikey; + config["colortype"] = G.Colortype; + config["UhrtypeDef"] = G.UhrtypeDef; + config["bootLedBlink"] = G.bootLedBlink; + config["bootLedSweep"] = G.bootLedSweep; + config["bootShowWifi"] = G.bootShowWifi; + config["bootShowIP"] = G.bootShowIP; + config["autoLdrEnabled"] = G.autoLdrEnabled; + config["hasDreiviertel"] = usedUhrType->hasDreiviertel(); + config["hasZwanzig"] = usedUhrType->hasZwanzig(); + config["hasWeatherLayout"] = usedUhrType->hasWeatherLayout(); + config["hasSecondsFrame"] = usedUhrType->hasSecondsFrame(); + serializeJson(config, str); + Serial.print("Sending Payload:"); + Serial.println(str); + webSocket.sendTXT(G.client_nr, str, strlen(str)); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_REQUEST_COLOR_VALUES: { + DynamicJsonDocument config(1024); + config["command"] = "set"; + for (uint8_t i = 0; i < 4; i++) { + for (uint8_t ii = 0; ii < 4; ii++) { + sprintf(s, "rgb%d%d", i, ii); + config[s] = G.rgb[i][ii]; + } + } + config["hell"] = G.hell; + config["geschw"] = G.geschw; + config["colortype"] = G.Colortype; + config["prog"] = G.prog; + serializeJson(config, str); + webSocket.sendTXT(G.client_nr, str, strlen(str)); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_REQUEST_AUTO_LDR: { + DynamicJsonDocument config(1024); + config["command"] = "autoLdr"; + if (G.param1 == 0) { + config["autoLdrEnabled"] = G.autoLdrEnabled; + config["autoLdrBright"] = G.autoLdrBright; + config["autoLdrDark"] = G.autoLdrDark; + } + config["autoLdrValue"] = map(analogRead(A0), 0, 1023, 0, 255); + serializeJson(config, str); + webSocket.sendTXT(G.client_nr, str, strlen(str)); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_REQUEST_ANIMATION: { + DynamicJsonDocument config(1024); + config["command"] = "animation"; + config["animType"] = G.animType; + config["animDuration"] = G.animDuration; + config["animSpeed"] = G.animSpeed; + config["animDemo"] = G.animDemo; + config["animColorize"] = G.animColorize; + JsonArray types = config.createNestedArray("animTypes"); + // Reihenfolge muss zu enum Ani passen! + types.add("keine"); + types.add("Hoch rollen"); + types.add("Runter rollen"); + types.add("Links schieben"); + types.add("Rechts schieben"); + types.add("Überblenden"); + types.add("Laser"); + types.add("Matrix"); + types.add("Baelle"); + types.add("Feuerwerk"); + types.add("Schlange"); + types.add("zufällig"); + serializeJson(config, str); + webSocket.sendTXT(G.client_nr, str, strlen(str)); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_TIME: + case COMMAND_SET_INITIAL_VALUES: + case COMMAND_SET_WEATHER_DATA: + case COMMAND_SET_MARQUEE_TEXT: + case COMMAND_SET_BOOT: { + eeprom_write(); + delay(100); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_MINUTE: + case COMMAND_SET_BRIGHTNESS: + case COMMAND_SET_LDR: + case COMMAND_SET_AUTO_LDR: + case COMMAND_SET_LANGUAGE_VARIANT: + case COMMAND_SET_SETTING_SECOND: + case COMMAND_SET_TIME_MANUAL: { + eeprom_write(); + ledClear(); + parameters_changed = true; + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_MQTT: { + if (G.mqtt.state && !mqtt.getConnected()) { + mqtt.reInit(); + } + + eeprom_write(); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_COLORTYPE: { + // G.param1 enthält den neuen Colortype + Serial.printf("LED Colortype: %u\n", G.param1); + + // if ((G.param1 != G.Colortype) && ((G.param1 == Grbw) || + // (G.Colortype == Grbw))) { + // G.conf = COMMAND_RESET; + // } else { + G.conf = COMMAND_IDLE; + // } + + // der G.Colortype muss zeitgleich zu initLedStrip erfolgen, + // sonst wird über einen null-pointer referenziert + G.Colortype = G.param1; + eeprom_write(); + initLedStrip(G.Colortype); + ledSetIcon(RGB_I, 100, true); + break; + } + + case COMMAND_SET_UHRTYPE: { + eeprom_write(); + Serial.printf("Uhrtype: %u\n", G.UhrtypeDef); + usedUhrType = getPointer(G.UhrtypeDef); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_HOSTNAME: { + Serial.print("Hostname: "); + Serial.println(G.hostname); + eeprom_write(); + Network_reboot(); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_WIFI_DISABLED: { + eeprom_write(); + delay(100); + Serial.println("Conf: WLAN Abgeschaltet"); + Network_disable(); + G.conf = COMMAND_IDLE; + break; + } + + case COMMAND_SET_WIFI_AND_RESTART: { + Serial.println("Conf: WLAN neu konfiguriert"); + Network_resetSettings(); + G.conf = COMMAND_IDLE; + break; + } + + default: + break; + } + + switch (G.prog) { + + case COMMAND_MODE_SECONDS: { + if (G.prog_init == 1) { + ledClear(); + G.prog_init = 0; + } + char d1[5]; + char d2[5]; + sprintf(d1, "%d", (int)(_sekunde / 10)); + sprintf(d2, "%d", (int)(_sekunde % 10)); + ledShowNumbers(d1[0], d2[0]); + break; + } + + case COMMAND_MODE_SCROLLINGTEXT: + case COMMAND_MODE_RAINBOWCYCLE: + case COMMAND_MODE_RAINBOW: { + if (G.prog_init == 1) { + G.prog_init = 0; + ledClear(); + count_delay = (11u - G.geschw) * 30u; + } + if (count_delay >= (11u - G.geschw) * 30u) { + switch (G.prog) { + case COMMAND_MODE_SCROLLINGTEXT: { + scrollingText(G.ltext); + break; + } + case COMMAND_MODE_RAINBOWCYCLE: { + rainbowCycle(); + break; + } + case COMMAND_MODE_RAINBOW: { + rainbow(); + break; + } + default: + break; + } + count_delay = 0; + } + break; + } + + case COMMAND_MODE_COLOR: { + if (G.prog_init == 1) { + G.prog_init = 0; + ledSetColor(); + ledShow(); + } + break; + } + + case COMMAND_MODE_ANIMATION: { + if (G.prog_init == 1) { + G.prog_init = 0; + eeprom_write(); + delay(100); + } + // Hier ist mit Absicht kein break, direkt nach dem Call + // COMMAND_MODE_ANIMATION muss COMMAND_MODE_WORD_CLOCK aufgerufen + // werden. + } + + case COMMAND_MODE_WORD_CLOCK: { + calcClockFace(); + + if (changesInClockface()) { + copyClockface(Word_array, Word_array_old); + ledSet(true); + } else if (parameters_changed) { + ledSet(); + } + parameters_changed = false; + + if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && + G.zeige_min < 2) { + ledSetFrameColor(); + } + G.prog = COMMAND_IDLE; + } + default: + break; + } + + if (count_delay > 10000) { + count_delay = 0; + } +} + +//------------------------------------------------------------------------------ + +void ClockWork::loopSecondsFrame() { + if (count_millis48 >= interval48) { + count_millis48 = 0; + _sekunde48++; + if (_sekunde48 > 47) { + _sekunde48 = 0; + } + } + if (last_sekunde48 != _sekunde48) { + if (G.prog == 0 && G.conf == 0) { + if (G.zeige_sek == 1 || G.zeige_min == 2) { + ledClearFrame(); + } + if (G.zeige_sek > 0) { + ledShowSeconds(); + } + ledShow(); + } + last_sekunde48 = _sekunde48; + } +} + +//------------------------------------------------------------------------------ + +void ClockWork::loopWeather() { + if ((_sekunde == 0) | (_sekunde == 10) | (_sekunde == 20) | + (_sekunde == 30) | (_sekunde == 40) | (_sekunde == 50)) { + wetterswitch++; + ledClear(); + if (wetterswitch > 4) { + wetterswitch = 1; + } + Serial.print("Wetterswitch: "); + Serial.println(wetterswitch); + Serial.print("WStunde: "); + Serial.println(wstunde); + } +} + +//------------------------------------------------------------------------------ + +void ClockWork::initBootLedBlink() { + ledSetAllPixels(50, 50, 50, 50); + ledShow(); +} + +//------------------------------------------------------------------------------ + +void ClockWork::initBootLedSweep() { clockWork.ledSingle(20); } + +//------------------------------------------------------------------------------ + +void ClockWork::initBootLed() { + ledClear(); + ledShow(); +} diff --git a/include/wifi_func.hpp b/include/wifi_func.hpp index 150bd924..24efb8ff 100644 --- a/include/wifi_func.hpp +++ b/include/wifi_func.hpp @@ -37,7 +37,7 @@ void WlanStart() { Serial.println(""); // IP-Adresse als Laufschrift anzeigen if (G.bootShowIP) { - clockWork.showIp(ip_adress); + clockWork.initBootShowIp(ip_adress); } Serial.printf("-- Ende WlanStart -- \n\n"); diff --git a/package.json b/package.json index 5462817a..632c444a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Wortuhr", - "version": "2.6.2", + "version": "2.6.3", "description": "For building a german layouted wordclock with an esp8266 module and WS2812/SK2812.", "license": "BSD-3-Clause", "contributors": [ @@ -20,6 +20,10 @@ "name": "David Panusch", "url": "https://github.com/dbambus" }, + { + "name": "shortN0te", + "url": "https://github.com/shortN0te" + }, { "name": "Flo455", "url": "https://github.com/Flo455" diff --git a/platformio.ini b/platformio.ini index 7a94428a..65d1988f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,7 @@ default_envs = nodemcuv2 [env:nodemcuv2] platform = espressif8266 board = nodemcuv2 +board_build.f_cpu = 160000000L framework = arduino upload_speed = 230400 monitor_speed = 115200 diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 0c1a50d3..964dcc0d 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -120,66 +120,14 @@ Mqtt mqtt; #include "clockWork.hpp" #include "icons.h" #include "mqtt.hpp" -#include "openwmap.h" #include "wifi_func.hpp" #define EEPROM_SIZE 512 _Static_assert(sizeof(G) <= EEPROM_SIZE, "Datenstruktur G zu gross für reservierten EEPROM Bereich"); -//------------------------------------------------------------------------------ - -iUhrType *getPointer(uint8_t num) { - switch (num) { - case 1: - return reinterpret_cast(&Uhr_114_type); - case 2: - return reinterpret_cast(&Uhr_114_Alternative_type); - case 6: - return reinterpret_cast(&Uhr_114_2Clock_type); - case 9: - return reinterpret_cast(&Uhr_114_dutch_type); - case 3: - return reinterpret_cast(&Uhr_125_type); - case 8: - return reinterpret_cast(&Uhr_125_type2_type); - case 4: - return reinterpret_cast(&Uhr_169_type); - case 5: - return reinterpret_cast(&Uhr_242_type); - case 7: - return reinterpret_cast(&Uhr_291_type); - default: - return nullptr; - } -} //------------------------------------------------------------------------------ -void InitLedStrip(uint8_t num) { - NeoMultiFeature::setColortype(num); - if (num == Grbw) { - if (strip_RGB != NULL) { - delete strip_RGB; // delete the previous dynamically created strip - strip_RGB = NULL; - } - if (strip_RGBW == NULL) { - strip_RGBW = new NeoPixelBus( - usedUhrType->NUM_PIXELS()); - strip_RGBW->Begin(); - } - } else { - if (strip_RGBW != NULL) { - delete strip_RGBW; // delete the previous dynamically created strip - strip_RGBW = NULL; - } - if (strip_RGB == NULL) { - strip_RGB = new NeoPixelBus( - usedUhrType->NUM_PIXELS()); - strip_RGB->Begin(); - } - } -} - uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000() { if (externalRTC) { Serial.println("SNTP startup delay 1min"); @@ -192,6 +140,8 @@ uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000() { } } +//------------------------------------------------------------------------------ + void time_is_set() { time_t utc = time(nullptr); if (externalRTC) { @@ -324,7 +274,7 @@ void setup() { // Get Pointer for Uhrtype //------------------------------------- - usedUhrType = getPointer(G.UhrtypeDef); + usedUhrType = clockWork.getPointer(G.UhrtypeDef); // Bereich der animiert wird: // LED-Rahmen horizontal @@ -339,17 +289,15 @@ void setup() { // LEDs initialisieren //------------------------------------- Serial.println("LED Init"); - InitLedStrip(G.Colortype); + clockWork.initLedStrip(G.Colortype); if (G.bootLedBlink) { - clockWork.ledSetAllPixels(0x40, 0x40, 0x40, 0x40); - clockWork.ledShow(); + clockWork.initBootLedBlink(); delay(20); } if (G.bootLedSweep) { - clockWork.ledSingle(20); + clockWork.initBootLedSweep(); } - clockWork.ledClear(); - clockWork.ledShow(); + clockWork.initBootLed(); G.conf = COMMAND_IDLE; @@ -382,13 +330,13 @@ void setup() { // Start WiFi //------------------------------------- if (G.bootShowWifi) { - clockWork.showWifiSignalStrength(0); + clockWork.initBootWifiSignalStrength(0); } Network_setup(G.hostname); int strength = Network_getQuality(); Serial.printf("Signal strength: %i\n", strength); if (G.bootShowWifi) { - clockWork.showWifiSignalStrength(strength); + clockWork.initBootWifiSignalStrength(strength); } WlanStart(); configTime(0, 0, G.zeitserver); @@ -431,10 +379,12 @@ void setup() { MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 81); + /* // setup frame if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && G.zeige_min < 2) { clockWork.ledSetFrameColor(); } + */ //------------------------------------- Serial.println("--------------------------------------"); @@ -473,13 +423,6 @@ void setup() { //------------------------------------------------------------------------------ void loop() { - unsigned long currentMillis = millis(); - count_delay += currentMillis - previousMillis; - if (usedUhrType->hasSecondsFrame()) { - count_millis48 += currentMillis - previousMillis; - } - previousMillis = currentMillis; - time_t utc = time(nullptr); struct tm tm; localtime_r(&utc, &tm); @@ -489,8 +432,7 @@ void loop() { _stunde = tm.tm_hour; } - // lass die Zeit im Demo Mode der Animation schneller ablaufen - animation->demoMode(_minute, _sekunde); + Network_loop(); MDNS.update(); @@ -505,426 +447,10 @@ void loop() { mqtt.loop(); } - //------------------------------------------------ - // SecondsFrame - //------------------------------------------------ - if (usedUhrType->hasSecondsFrame()) { - if (count_millis48 >= interval48) { - count_millis48 = 0; - _sekunde48++; - if (_sekunde48 > 47) { - _sekunde48 = 0; - } - } - if (last_sekunde48 != _sekunde48) { - if (G.prog == 0 && G.conf == 0) { - if (G.zeige_sek == 1 || G.zeige_min == 2) { - clockWork.ledClearFrame(); - } - if (G.zeige_sek > 0) { - clockWork.ledShowSeconds(); - } - clockWork.ledShow(); - } - last_sekunde48 = _sekunde48; - } - } - - //------------------------------------------------ - // Sekunde und LDR Regelung - //------------------------------------------------ - if (last_sekunde != _sekunde) { - - // Wetteruhr - if (usedUhrType->hasWeatherLayout()) { - weather_tag++; - } - - //--- LDR Regelung - if ((G.ldr == 1) || G.autoLdrEnabled) { - clockWork.doLDRLogic(); - } - - if (G.prog == 0 && G.conf == 0) { - clockWork.ledClear(); - G.prog = COMMAND_MODE_WORD_CLOCK; - } - last_sekunde = _sekunde; - - if (usedUhrType->hasWeatherLayout()) { - if ((_sekunde == 0) | (_sekunde == 10) | (_sekunde == 20) | - (_sekunde == 30) | (_sekunde == 40) | (_sekunde == 50)) { - wetterswitch++; - clockWork.ledClear(); - if (wetterswitch > 4) { - wetterswitch = 1; - } - Serial.print("Wetterswitch: "); - Serial.println(wetterswitch); - Serial.print("WStunde: "); - Serial.println(wstunde); - } - } - - char currentTime[80]; - strftime(currentTime, sizeof(currentTime), "%F %T (%z)\n", &tm); - Serial.printf(currentTime); - } - animation->loop(tm); // muss periodisch aufgerufen werden - //------------------------------------------------ - // Minute - //------------------------------------------------ - if (last_minute != _minute) { - _sekunde48 = 0; - last_minute = _minute; - } - - //------------------------------------------------ - // Wetterdaten abrufen - //------------------------------------------------ - if (usedUhrType->hasWeatherLayout() && - weather_tag >= 600) { // Eisbaeeer changed for Debug (soll 600) - weather_tag = 0; - if (WiFi.status() == WL_CONNECTED) { - getweather(); - } - } - - Network_loop(); - - switch (G.conf) { - - case COMMAND_RESET: // Reset - { - delay(500); - ESP.reset(); - ESP.restart(); - while (true) { - } - break; - } - - case COMMAND_REQUEST_MQTT_VALUES: // MQTT Config Senden - { - DynamicJsonDocument config(1024); - config["command"] = "mqtt"; - config["MQTT_State"] = G.mqtt.state; - config["MQTT_Port"] = G.mqtt.port; - config["MQTT_Server"] = G.mqtt.serverAdress; - config["MQTT_User"] = G.mqtt.user; - config["MQTT_Pass"] = G.mqtt.password; - config["MQTT_ClientId"] = G.mqtt.clientId; - config["MQTT_Topic"] = G.mqtt.topic; - serializeJson(config, str); - Serial.print("Sending Payload:"); - Serial.println(str); - webSocket.sendTXT(G.client_nr, str, strlen(str)); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_REQUEST_CONFIG_VALUES: // Config Senden - { - DynamicJsonDocument config(1024); - config["command"] = "config"; - config["ssid"] = Network_getSSID(); - config["zeitserver"] = G.zeitserver; - config["hostname"] = G.hostname; - config["ltext"] = G.ltext; - config["h6"] = G.h6; - config["h8"] = G.h8; - config["h12"] = G.h12; - config["h16"] = G.h16; - config["h18"] = G.h18; - config["h20"] = G.h20; - config["h22"] = G.h22; - config["h24"] = G.h24; - for (uint8_t i = 0; i < 5; i++) { - sprintf(s, "spv%d", i); - config[s] = static_cast(G.Sprachvariation[i]); - } - config["hell"] = G.hell; - config["zeige_sek"] = G.zeige_sek; - config["zeige_min"] = G.zeige_min; - config["ldr"] = G.ldr; - config["ldrCal"] = G.ldrCal; - config["cityid"] = G.openWeatherMap.cityid; - config["apikey"] = G.openWeatherMap.apikey; - config["colortype"] = G.Colortype; - config["UhrtypeDef"] = G.UhrtypeDef; - config["bootLedBlink"] = G.bootLedBlink; - config["bootLedSweep"] = G.bootLedSweep; - config["bootShowWifi"] = G.bootShowWifi; - config["bootShowIP"] = G.bootShowIP; - config["autoLdrEnabled"] = G.autoLdrEnabled; - config["hasDreiviertel"] = usedUhrType->hasDreiviertel(); - config["hasZwanzig"] = usedUhrType->hasZwanzig(); - config["hasWeatherLayout"] = usedUhrType->hasWeatherLayout(); - config["hasSecondsFrame"] = usedUhrType->hasSecondsFrame(); - serializeJson(config, str); - Serial.print("Sending Payload:"); - Serial.println(str); - webSocket.sendTXT(G.client_nr, str, strlen(str)); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_REQUEST_COLOR_VALUES: // Config Farbwerte senden - { - DynamicJsonDocument config(1024); - config["command"] = "set"; - for (uint8_t i = 0; i < 4; i++) { - for (uint8_t ii = 0; ii < 4; ii++) { - sprintf(s, "rgb%d%d", i, ii); - config[s] = G.rgb[i][ii]; - } - } - config["hell"] = G.hell; - config["geschw"] = G.geschw; - config["colortype"] = G.Colortype; - config["prog"] = G.prog; - serializeJson(config, str); - webSocket.sendTXT(G.client_nr, str, strlen(str)); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_REQUEST_AUTO_LDR: // Automatische Helligkeit - { - DynamicJsonDocument config(1024); - config["command"] = "autoLdr"; - if (G.param1 == 0) { - config["autoLdrEnabled"] = G.autoLdrEnabled; - config["autoLdrBright"] = G.autoLdrBright; - config["autoLdrDark"] = G.autoLdrDark; - } - config["autoLdrValue"] = map(analogRead(A0), 0, 1023, 0, 255); - serializeJson(config, str); - webSocket.sendTXT(G.client_nr, str, strlen(str)); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_REQUEST_ANIMATION: // Animation - { - DynamicJsonDocument config(1024); - config["command"] = "animation"; - config["animType"] = G.animType; - config["animDuration"] = G.animDuration; - config["animSpeed"] = G.animSpeed; - config["animDemo"] = G.animDemo; - config["animColorize"] = G.animColorize; - JsonArray types = config.createNestedArray("animTypes"); - // Reihenfolge muss zu enum Ani passen! - types.add("keine"); - types.add("Hoch rollen"); - types.add("Runter rollen"); - types.add("Links schieben"); - types.add("Rechts schieben"); - types.add("Überblenden"); - types.add("Laser"); - types.add("Matrix"); - types.add("Baelle"); - types.add("Feuerwerk"); - types.add("Schlange"); - types.add("zufällig"); - serializeJson(config, str); - webSocket.sendTXT(G.client_nr, str, strlen(str)); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_TIME: // Uhrzeit setzen - case COMMAND_SET_INITIAL_VALUES: // Startwerte speichern - case COMMAND_SET_WEATHER_DATA: // OpenWeathermap Einstellung speichern - case COMMAND_SET_MARQUEE_TEXT: // Lauftext speichern - case COMMAND_SET_BOOT: // Bootoptionen speichern - { - eeprom_write(); - delay(100); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_MINUTE: // Anzeige Minuten speichern - case COMMAND_SET_BRIGHTNESS: // Helligkeit speichern - case COMMAND_SET_LDR: // LDR Einstellung speichern - case COMMAND_SET_AUTO_LDR: // Auto LDR Parameter speichern - case COMMAND_SET_LANGUAGE_VARIANT: // Sprachvarianten Einstellungen - case COMMAND_SET_SETTING_SECOND: // Anzeige Sekunde speichern - case COMMAND_SET_TIME_MANUAL: // Uhrzeit manuell einstellen - { - eeprom_write(); - clockWork.ledClear(); - parameters_changed = true; - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_MQTT: // MQTT Einstellungen - { - if (G.mqtt.state && !mqtt.getConnected()) { - mqtt.reInit(); - } - eeprom_write(); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_COLORTYPE: // Colortype der LED einstellen - { - // G.param1 enthält den neuen Colortype - Serial.printf("LED Colortype: %u\n", G.param1); - - // if ((G.param1 != G.Colortype) && ((G.param1 == Grbw) || - // (G.Colortype == Grbw))) { - // G.conf = COMMAND_RESET; - // } else { - G.conf = COMMAND_IDLE; - // } - - // der G.Colortype muss zeitgleich zu InitLedStrip erfolgen, - // sonst wird über einen null-pointer referenziert - G.Colortype = G.param1; - eeprom_write(); - InitLedStrip(G.Colortype); - clockWork.ledSetIcon(RGB_I, 100, true); - break; - } - - case COMMAND_SET_UHRTYPE: // Uhrtype Layout einstellen - { - eeprom_write(); - Serial.printf("Uhrtype: %u\n", G.UhrtypeDef); - usedUhrType = getPointer(G.UhrtypeDef); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_HOSTNAME: // Hostname speichern - { - Serial.print("Hostname: "); - Serial.println(G.hostname); - eeprom_write(); - Network_reboot(); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_WIFI_DISABLED: // WLAN-Daten speichern und neu starten - { - eeprom_write(); - delay(100); - Serial.println("Conf: WLAN Abgeschaltet"); - Network_disable(); - G.conf = COMMAND_IDLE; - break; - } - - case COMMAND_SET_WIFI_AND_RESTART: // WLAN-Daten speichern und neu starten - { - Serial.println("Conf: WLAN neu konfiguriert"); - Network_resetSettings(); - G.conf = COMMAND_IDLE; - break; - } - - default: - break; - } - - switch (G.prog) { - - case COMMAND_MODE_SECONDS: // Sekundenanzeige - { - if (G.prog_init == 1) { - clockWork.ledClear(); - G.prog_init = 0; - } - char d1[5]; - char d2[5]; - sprintf(d1, "%d", (int)(_sekunde / 10)); - sprintf(d2, "%d", (int)(_sekunde % 10)); - clockWork.ledShowNumbers(d1[0], d2[0]); - break; - } - - case COMMAND_MODE_SCROLLINGTEXT: - case COMMAND_MODE_RAINBOWCYCLE: - case COMMAND_MODE_RAINBOW: { - if (G.prog_init == 1) { - G.prog_init = 0; - clockWork.ledClear(); - count_delay = (11u - G.geschw) * 30u; - } - if (count_delay >= (11u - G.geschw) * 30u) { - switch (G.prog) { - case COMMAND_MODE_SCROLLINGTEXT: { - clockWork.scrollingText(G.ltext); - break; - } - case COMMAND_MODE_RAINBOWCYCLE: { - clockWork.rainbowCycle(); - break; - } - case COMMAND_MODE_RAINBOW: { - clockWork.rainbow(); - break; - } - default: - break; - } - count_delay = 0; - } - break; - } - - case COMMAND_MODE_COLOR: // Farbe Rahmen - { - if (G.prog_init == 1) { - G.prog_init = 0; - clockWork.ledSetColor(); - clockWork.ledShow(); - } - break; - } - - case COMMAND_MODE_ANIMATION: // Animation - { - if (G.prog_init == 1) { - G.prog_init = 0; - eeprom_write(); - delay(100); - } - // Hier ist mit Absicht kein break, direkt nach dem Call - // COMMAND_MODE_ANIMATION muss COMMAND_MODE_WORD_CLOCK aufgerufen - // werden. - } - - case COMMAND_MODE_WORD_CLOCK: { - clockWork.calcClockFace(); - - if (clockWork.changesInClockface()) { - clockWork.copyClockface(Word_array, Word_array_old); - clockWork.ledSet(true); - } else if (parameters_changed) { - clockWork.ledSet(); - } - parameters_changed = false; - - if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && - G.zeige_min < 2) { - clockWork.ledSetFrameColor(); - } - G.prog = COMMAND_IDLE; - } - default: - break; - } + // lass die Zeit im Demo Mode der Animation schneller ablaufen + animation->demoMode(_minute, _sekunde); - if (count_delay > 10000) { - count_delay = 0; - } + clockWork.loop(tm); } diff --git a/webpage/index.html b/webpage/index.html index 658ca60b..344130d9 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -767,7 +767,7 @@

Über

Die Software dieser Wortuhr basiert auf der Wortuhr von (Stand 2019) Ulrich Radig und wird nun weiterentwickelt auf GitHub von Lars Weimar, Pascal Wagler, dbambus, + href="https://github.com/Eisbaeeer">Lars Weimar, Pascal Wagler, dbambus, shortN0te, Flo455, Elektron79, tali, ATho95 und masju1.

Ein Update der Software ist möglich, dazu bitte hier klicken.

This project is open source licensed under the BSD 3-Clause License.

From 629961cd95340d6d97268de6c01588bd17a092a6 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Sun, 8 Jan 2023 14:05:41 +0100 Subject: [PATCH 13/15] Refactored led funtions out of clockWork.h/hpp to own class Led in files leh.h and led.hpp. Translated all Comments in clockwork.h/hpp and led.h/hpp to english. no further changes to code. Clang formated WebPage_Adapter.h and EEPROMAnything.h Changes to be committed: modified: include/Animation.hpp modified: include/EEPROMAnything.h modified: include/WebPage_Adapter.h modified: include/clockWork.h modified: include/clockWork.hpp new file: include/led.h new file: include/led.hpp modified: src/Wortuhr.cpp --- include/Animation.hpp | 28 +- include/EEPROMAnything.h | 2 +- include/WebPage_Adapter.h | 6 +- include/clockWork.h | 64 +---- include/clockWork.hpp | 526 ++++++-------------------------------- include/led.h | 49 ++++ include/led.hpp | 350 +++++++++++++++++++++++++ src/Wortuhr.cpp | 7 +- 8 files changed, 515 insertions(+), 517 deletions(-) create mode 100644 include/led.h create mode 100644 include/led.hpp diff --git a/include/Animation.hpp b/include/Animation.hpp index 6afecb03..3f1289ca 100644 --- a/include/Animation.hpp +++ b/include/Animation.hpp @@ -242,7 +242,7 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source, for (int r = 0; r < max_rows; r++) { for (int c = 0; c < max_cols; c++) { if (source == STRIPE) { - color = clockWork.ledGetPixel( + color = led.getPixel( usedUhrType->getFrontMatrix(r + row_start, c + col_start)); } else { color = source[r][c]; @@ -293,25 +293,21 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source, void Animation::set_minutes() { if (G.zeige_min > 0) { uint8_t m = lastMinute % 5; - clockWork.ledSetPixelColorObject( - usedUhrType->getMinArr(G.zeige_min - 1, 0), - m > 0 ? foregroundMinute : background); - clockWork.ledSetPixelColorObject( - usedUhrType->getMinArr(G.zeige_min - 1, 1), - m > 1 ? foregroundMinute : background); - clockWork.ledSetPixelColorObject( - usedUhrType->getMinArr(G.zeige_min - 1, 2), - m > 2 ? foregroundMinute : background); - clockWork.ledSetPixelColorObject( - usedUhrType->getMinArr(G.zeige_min - 1, 3), - m > 3 ? foregroundMinute : background); + led.setPixelColorObject(usedUhrType->getMinArr(G.zeige_min - 1, 0), + m > 0 ? foregroundMinute : background); + led.setPixelColorObject(usedUhrType->getMinArr(G.zeige_min - 1, 1), + m > 1 ? foregroundMinute : background); + led.setPixelColorObject(usedUhrType->getMinArr(G.zeige_min - 1, 2), + m > 2 ? foregroundMinute : background); + led.setPixelColorObject(usedUhrType->getMinArr(G.zeige_min - 1, 3), + m > 3 ? foregroundMinute : background); } } // Ueberschreibe die LEDs mit interner Matrix void Animation::copy2Stripe(RgbfColor **source) { for (uint8_t row = 0; row < max_rows; row++) { for (uint8_t col = 0; col < max_cols; col++) { - clockWork.ledSetPixelColorObject( + led.setPixelColorObject( usedUhrType->getFrontMatrix(row + row_start, col + col_start), source[row][col]); } @@ -408,7 +404,7 @@ void Animation::loop(struct tm &tm) { copyMatrix(work, act); colorize(work); copy2Stripe(work); - clockWork.ledShow(); + led.show(); } } else { if ((animType != lastAnimType) || @@ -470,7 +466,7 @@ void Animation::loop(struct tm &tm) { } animColorChange(); copy2Stripe(work); - clockWork.ledShow(); + led.show(); } } } diff --git a/include/EEPROMAnything.h b/include/EEPROMAnything.h index 131f3839..306f6a50 100644 --- a/include/EEPROMAnything.h +++ b/include/EEPROMAnything.h @@ -62,7 +62,7 @@ void eeprom_read() { Serial.printf("LDR : %u\n", G.ldr); Serial.printf("LDRCal : %u\n", G.ldrCal); Serial.printf("Uhrtype : %u\n", G.UhrtypeDef); - + Serial.printf("MQTT_State : %u\n", G.mqtt.state); Serial.printf("MQTT_Server : %s\n", G.mqtt.serverAdress); Serial.printf("MQTT_User : %s\n", G.mqtt.user); diff --git a/include/WebPage_Adapter.h b/include/WebPage_Adapter.h index ea868eb6..adc56c5d 100644 --- a/include/WebPage_Adapter.h +++ b/include/WebPage_Adapter.h @@ -204,7 +204,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, case COMMAND_MODE_SECONDS: { // Sekunden G.prog = COMMAND_MODE_SECONDS; - G.prog_init = 1; + G.prog_init = 1; G.rgb[Effect][0] = split(payload, 3); G.rgb[Effect][1] = split(payload, 6); @@ -217,9 +217,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_MODE_SCROLLINGTEXT: { + case COMMAND_MODE_SCROLLINGTEXT: { G.prog = COMMAND_MODE_SCROLLINGTEXT; - G.prog_init = 1; + G.prog_init = 1; G.rgb[Effect][0] = split(payload, 3); G.rgb[Effect][1] = split(payload, 6); diff --git a/include/clockWork.h b/include/clockWork.h index 924d36a6..c842d453 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -4,43 +4,6 @@ class ClockWork { private: - inline void checkIfHueIsOutOfBound(float &hue) { - if (hue > 360) { - hue = 0; - } - } - - void ledSetPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, - uint16_t i); - void ledSetPixelHsb(uint16_t ledIndex, float hue, float sat, float bri, - uint8_t alpha); - - void ledSetPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, - uint8_t offsetRow, unsigned char unsigned_d1); - - uint8_t setBrightnessAuto(uint8_t val); - void setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, - uint8_t position); - void setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, - uint8_t position, uint8_t percentage); - - inline void ledClearClock(); - inline void ledClearPixel(uint16_t i); - inline void ledClearRow(uint8_t row); - inline void ledClearFrontExeptofFontspace(uint8_t offsetRow); - inline void ledClearFrame(); - void ledShiftColumnToRight(); - void ledShowSeconds(); - void ledShowNumbers(const char d1, const char d2); - void ledSet(bool changed = false); - void ledSetColor(); - void ledSetIcon(uint8_t num_icon, uint8_t brightness, bool rgb_icon); - void ledSetFrameColor(); - - void ledClear(); - void ledSingle(uint8_t wait); - void ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww); - void loopSecondsFrame(); void loopWeather(); void loopLdrLogic(); @@ -51,34 +14,27 @@ class ClockWork { bool changesInClockface(); void copyClockface(const uint16_t source[], uint16_t destination[]); - void calcClockFace(); + void calcClockface(); - void clockSetHour(const uint8_t std, const uint8_t voll); - void clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll); - void clockShowMinute(uint8_t min); - void clockSetClock(); - void clockShowWeather(); + void setClock(); + void setHour(const uint8_t std, const uint8_t voll); + void setMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll); + void showMinute(uint8_t min); + void showWeather(); public: ClockWork() = default; ~ClockWork() = default; - iUhrType *getPointer(uint8_t num); - void initLedStrip(uint8_t num); - - void ledShow(); - - RgbColor ledGetPixel(uint16_t i); - RgbwColor ledGetPixelRgbw(uint16_t i); - - void ledSetPixelColorObject(uint16_t i, RgbColor color); - void ledSetPixelColorObjectRgbw(uint16_t i, RgbwColor color); + iUhrType *getPointer(uint8_t type); void loop(struct tm &tm); void initBootLed(); void initBootLedBlink(); - void initBootLedSweep(); + void initBootLedSweep(uint32_t delay); void initBootShowIp(const char *buf); void initBootWifiSignalStrength(int strength); + + void initLedStrip(uint8_t num); }; diff --git a/include/clockWork.hpp b/include/clockWork.hpp index c4950261..8a2e74a8 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -3,217 +3,9 @@ #include "Uhr.h" #include "Uhrtypes/Uhrtype.hpp" #include "clockWork.h" -#include "font.h" -#include "icons.h" -#include "mqtt.h" #include "openwmap.h" #include -extern NeoPixelBus *strip_RGB; -extern NeoPixelBus *strip_RGBW; - -extern iUhrType *usedUhrType; -extern Animation *animation; -extern Mqtt mqtt; - -void ClockWork::ledSetPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, - uint16_t i) { - - if (G.Colortype == Grbw) { - strip_RGBW->SetPixelColor(i, RgbwColor(rr, gg, bb, ww)); - } else { - strip_RGB->SetPixelColor(i, RgbColor(rr, gg, bb)); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetPixelHsb(uint16_t ledIndex, float hue, float sat, - float bri, uint8_t alpha = 0) { - HsbColor hsbColor = HsbColor(hue / 360, sat / 100, bri / 100); - - if (G.Colortype == Grbw) { - RgbColor rgbColor = RgbColor(hsbColor); - - strip_RGBW->SetPixelColor( - ledIndex, RgbwColor(rgbColor.R, rgbColor.G, rgbColor.B, alpha)); - } else { - strip_RGB->SetPixelColor(ledIndex, hsbColor); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetPixelColorObject(uint16_t i, RgbColor color) { - - if (G.Colortype == Grbw) { - strip_RGBW->SetPixelColor(i, RgbwColor(color)); - } else { - strip_RGB->SetPixelColor(i, color); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetPixelColorObjectRgbw(uint16_t i, RgbwColor color) { - strip_RGBW->SetPixelColor(i, RgbwColor(color)); -} - -//------------------------------------------------------------------------------ - -RgbColor ClockWork::ledGetPixel(uint16_t i) { - if (G.Colortype == Grbw) { - RgbwColor rgbw = strip_RGBW->GetPixelColor(i); - return RgbColor(rgbw.R, rgbw.G, rgbw.B); - } - return strip_RGB->GetPixelColor(i); -} - -//------------------------------------------------------------------------------ - -RgbwColor ClockWork::ledGetPixelRgbw(uint16_t i) { - return strip_RGBW->GetPixelColor(i); -} - -//------------------------------------------------------------------------------ -// Helligkeitsregelung nach Uhrzeiten oder per LDR -//------------------------------------------------------------------------------ -uint8_t ClockWork::setBrightnessAuto(uint8_t val) { - // G.hh enthaelt zeitabhaengige Helligkeitswerte in % - uint16_t u16 = (val * G.hh) / 100; - return (static_cast((u16 * ldrVal) / 100)); -} - -//------------------------------------------------------------------------------ - -void ClockWork::setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, - uint8_t &ww, uint8_t position) { - if (G.autoLdrEnabled) { - rr = setBrightnessAuto(G.rgb[position][0]); - gg = setBrightnessAuto(G.rgb[position][1]); - bb = setBrightnessAuto(G.rgb[position][2]); - ww = setBrightnessAuto(G.rgb[position][3]); - } else { - if (G.ldr == 1) { - rr = G.rgb[position][0] * ldrVal / 100; - gg = G.rgb[position][1] * ldrVal / 100; - bb = G.rgb[position][2] * ldrVal / 100; - ww = G.rgb[position][3] * ldrVal / 100; - } else { - rr = G.rgb[position][0] * G.hh / 100; - gg = G.rgb[position][1] * G.hh / 100; - bb = G.rgb[position][2] * G.hh / 100; - ww = G.rgb[position][3] * G.hh / 100; - } - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, - uint8_t &ww, uint8_t position, - uint8_t percentage = 100) { - rr = G.rgb[position][0] * percentage / 100; - gg = G.rgb[position][1] * percentage / 100; - bb = G.rgb[position][2] * percentage / 100; - ww = G.rgb[position][3] * percentage / 100; - uint16_t zz = rr + gg + bb; - if (zz > 150) { - zz = zz * 10 / 150; - rr = rr * 10 / zz; - gg = gg * 10 / zz; - bb = bb * 10 / zz; - ww = ww * 10 / zz; - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledShow() { - if (G.Colortype == Grbw) { - strip_RGBW->Show(); - } else { - strip_RGB->Show(); - } -} - -//------------------------------------------------------------------------------ - -inline void ClockWork::ledClearPixel(uint16_t i) { - if (G.Colortype == Grbw) { - strip_RGBW->SetPixelColor(i, 0); - } else { - strip_RGB->SetPixelColor(i, 0); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledClear() { - for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - Word_array[i] = 500; - ledClearPixel(i); - } -} - -//------------------------------------------------------------------------------ - -inline void ClockWork::ledClearClock() { - for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - ledClearPixel(usedUhrType->getSMatrix(i)); - } -} - -//------------------------------------------------------------------------------ - -inline void ClockWork::ledClearRow(uint8_t row) { - for (uint8_t i = 0; i < usedUhrType->COLS_MATRIX(); i++) { - ledClearPixel(usedUhrType->getFrontMatrix(row, i)); - } -} - -//------------------------------------------------------------------------------ - -inline void ClockWork::ledClearFrontExeptofFontspace(uint8_t offsetRow) { - for (uint8_t i = 0; i < offsetRow; i++) { - ledClearRow(i); - } - - for (uint8_t i = usedUhrType->ROWS_MATRIX() - 1; i > offsetRow + fontHeight; - i--) { - ledClearRow(i - 1); - } -} - -//------------------------------------------------------------------------------ - -inline void ClockWork::ledClearFrame() { - for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { - ledClearPixel(usedUhrType->getRMatrix(i)); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSet(bool changed) { - uint8_t rr, gg, bb, ww; - uint8_t r2, g2, b2, w2; - setBrightnessLdr(rr, gg, bb, ww, Foreground); - setBrightnessLdr(r2, g2, b2, w2, Background); - for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - if (Word_array_old[i] < usedUhrType->NUM_PIXELS()) { - // foreground - ledSetPixel(rr, gg, bb, ww, i); - } else { - // background - ledSetPixel(r2, g2, b2, w2, i); - } - } - if (animation->led_show_notify(changed, _minute)) { - ledShow(); - } -} - //------------------------------------------------------------------------------ void ClockWork::copyClockface(const uint16_t source[], uint16_t destination[]) { @@ -235,68 +27,6 @@ bool ClockWork::changesInClockface() { //------------------------------------------------------------------------------ -void ClockWork::ledSetIcon(uint8_t num_icon, uint8_t brightness = 100, - bool rgb_icon = false) { - uint8_t rr, gg, bb, ww; - setBrightness(rr, gg, bb, ww, Foreground, brightness); - for (uint8_t col = 0; col < GRAFIK_11X10_COLS; col++) { - if (rgb_icon) { - rr = col < 3 ? 255 : 0; - gg = (col > 3) && (col < 7) ? 255 : 0; - bb = col > 7 ? 255 : 0; - ww = 0; - } - for (uint8_t row = 0; row < GRAFIK_11X10_ROWS; row++) { - if (pgm_read_word(&(grafik_11x10[num_icon][row])) & - (1 << (GRAFIK_11X10_COLS - 1 - col))) { - ledSetPixel(rr, gg, bb, ww, - usedUhrType->getFrontMatrix(row, col)); - } else { - ledClearPixel(usedUhrType->getFrontMatrix(row, col)); - } - } - } - ledShow(); -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSingle(uint8_t wait) { - float hue; - - for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - hue = 360.0 * i / (usedUhrType->NUM_PIXELS() - 1); - hue = hue + 360.0 / usedUhrType->NUM_PIXELS(); - checkIfHueIsOutOfBound(hue); - - ledClear(); - ledSetPixelHsb(i, hue, 100, 100); - ledShow(); - delay(wait); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, - uint8_t ww) { - for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - ledSetPixel(rr, gg, bb, ww, i); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetColor() { - uint8_t rr, gg, bb, ww; - setBrightness(rr, gg, bb, ww, Effect); - ledSetAllPixels(rr, gg, bb, ww); -} - -//------------------------------------------------------------------------------ -// Routine Helligkeitsregelung -//------------------------------------------------------------------------------ - void ClockWork::loopLdrLogic() { int16_t lux = analogRead(A0); // Range 0-1023 uint8_t ldrValOld = ldrVal; @@ -310,7 +40,7 @@ void ClockWork::loopLdrLogic() { if (lux <= minimum) lux = minimum; if (G.autoLdrDark == G.autoLdrBright) { - // map() wuerde mit division durch 0 crashen + // map() //Would crash with division by zero ldrVal = 100; } else { ldrVal = map(lux, G.autoLdrDark, G.autoLdrBright, 10, 100); @@ -320,27 +50,15 @@ void ClockWork::loopLdrLogic() { lux = lux - (G.ldrCal * 20); if (lux >= 900) { lux = 900; - } // Maximale Helligkeit + } // Max Brightness if (lux <= 1) { lux = 1; - } // Minimale Helligkeit + } // Min Brightness ldrVal = map(lux, 1, 900, 1, 100); } } if (ldrValOld != ldrVal) { - // lass den LDR sofort wirken - ledSet(); - } -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledSetFrameColor() { - uint8_t rr, gg, bb, ww; - setBrightness(rr, gg, bb, ww, Frame); - - for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { - ledSetPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(i)); + led.set(); } } @@ -350,11 +68,11 @@ void ClockWork::rainbow() { static float hue = 0; for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - ledSetPixelHsb(i, hue, 100, G.hell); + led.setPixelHsb(i, hue, 100, G.hell); } - ledShow(); + led.show(); hue++; - checkIfHueIsOutOfBound(hue); + led.checkIfHueIsOutOfBound(hue); } //----------------------------------------------------------------------------- @@ -365,32 +83,13 @@ void ClockWork::rainbowCycle() { displayedHue = hue; for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { - ledSetPixelHsb(usedUhrType->getSMatrix(i), displayedHue, 100, G.hell); + led.setPixelHsb(usedUhrType->getSMatrix(i), displayedHue, 100, G.hell); displayedHue = displayedHue + 360.0 / usedUhrType->NUM_SMATRIX(); - checkIfHueIsOutOfBound(displayedHue); + led.checkIfHueIsOutOfBound(displayedHue); } - ledShow(); + led.show(); hue++; - checkIfHueIsOutOfBound(hue); -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledShiftColumnToRight() { - for (uint8_t col = 0; col < usedUhrType->COLS_MATRIX() - 1; col++) { - for (uint8_t row = 0; - row < usedUhrType->ROWS_MATRIX() - 1 /* Only Front*/; row++) { - if (G.Colortype == Grbw) { - ledSetPixelColorObjectRgbw( - usedUhrType->getFrontMatrix(row, col), - ledGetPixelRgbw(usedUhrType->getFrontMatrix(row, col + 1))); - } else { - ledSetPixelColorObject( - usedUhrType->getFrontMatrix(row, col), - ledGetPixel(usedUhrType->getFrontMatrix(row, col + 1))); - } - } - } + led.checkIfHueIsOutOfBound(hue); } //------------------------------------------------------------------------------ @@ -400,29 +99,29 @@ void ClockWork::scrollingText(const char *buf) { uint8_t offsetRow = (usedUhrType->ROWS_MATRIX() - fontHeight - 1) / 2; uint8_t fontIndex = buf[ii]; - ledShiftColumnToRight(); - ledClearFrontExeptofFontspace(offsetRow); + led.shiftColumnToRight(); + led.clearFrontExeptofFontspace(offsetRow); if (i < fontWidth) { for (uint8_t row = 0; row < fontHeight; row++) { if (pgm_read_byte(&(font_7x5[fontIndex][i])) & (1u << row)) { - ledSetPixel( + led.setPixel( G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], G.rgb[Effect][3], usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } else { - ledClearPixel(usedUhrType->getFrontMatrix( + led.clearPixel(usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } } } else { for (uint8_t row = 0; row < fontHeight; row++) { - ledClearPixel(usedUhrType->getFrontMatrix( + led.clearPixel(usedUhrType->getFrontMatrix( row + offsetRow, usedUhrType->COLS_MATRIX() - 1)); } } - ledShow(); + led.show(); i++; if (i > fontWidth) { @@ -448,60 +147,19 @@ void ClockWork::initBootShowIp(const char *buf) { //------------------------------------------------------------------------------ -void ClockWork::ledSetPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, - uint8_t offsetRow, - unsigned char unsigned_d1) { - if (pgm_read_byte(&(font_7x5[unsigned_d1][col])) & (1u << row)) { - ledSetPixel( - G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], - G.rgb[Effect][3], - usedUhrType->getFrontMatrix(row + offsetRow, col + offsetCol)); - } -} - -//------------------------------------------------------------------------------ -// show signal-strenght by using different brightness for the individual rings -//------------------------------------------------------------------------------ - void ClockWork::initBootWifiSignalStrength(int strength) { if (strength <= 100) { - ledSetIcon(WLAN100, 100); + led.setIcon(WLAN100, 100); } else if (strength <= 60) { - ledSetIcon(WLAN60, 60); + led.setIcon(WLAN60, 60); } else if (strength <= 30) { - ledSetIcon(WLAN30, 30); + led.setIcon(WLAN30, 30); } } //------------------------------------------------------------------------------ -void ClockWork::ledShowNumbers(const char d1, const char d2) { - ledClearClock(); - static uint8_t offsetLetter0 = 0; - static uint8_t offsetLetter1 = fontWidth + 1; - uint8_t offsetRow = (usedUhrType->ROWS_MATRIX() - fontHeight - 1) / 2; - - if (usedUhrType->has24HourLayout()) { - offsetLetter0 = 3; - offsetLetter1 = fontWidth + 4; - } - - for (uint8_t col = 0; col < fontWidth; col++) { - for (uint8_t row = 0; row < fontHeight; row++) { - // 1. Zahl ohne Offset - ledSetPixelForChar(col, row, offsetLetter0, offsetRow, - static_cast(d1)); - // 2. Zahl mit Offset - ledSetPixelForChar(col, row, offsetLetter1, offsetRow, - static_cast(d2)); - } - } - ledShow(); -} - -//------------------------------------------------------------------------------ - -void ClockWork::clockSetHour(const uint8_t std, const uint8_t voll) { +void ClockWork::setHour(const uint8_t std, const uint8_t voll) { switch (std) { case 0: usedUhrType->show(h_zwoelf); @@ -593,10 +251,8 @@ void ClockWork::clockSetHour(const uint8_t std, const uint8_t voll) { //------------------------------------------------------------------------------ -void ClockWork::clockShowMinute(uint8_t min) { +void ClockWork::showMinute(uint8_t min) { if (G.zeige_min > 0) { - // Minuten / Sekunden-Animation - // Minute (1-4) ermitteln while (min > 4) { min -= 5; } @@ -622,14 +278,14 @@ void ClockWork::clockShowMinute(uint8_t min) { //------------------------------------------------------------------------------ -void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { +void ClockWork::setMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { if (!usedUhrType->has24HourLayout()) { - clockShowMinute(min); + showMinute(min); min /= 5; min *= 5; } switch (min) { - case 0: // volle Stunde + case 0: // full hour usedUhrType->show(uhr); voll = 1; break; @@ -655,7 +311,7 @@ void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { usedUhrType->show(minuten); usedUhrType->show(nach); break; - case 15: // viertel nach + case 15: // quarter past if (G.Sprachvariation[ItIs15]) { usedUhrType->show(viertel); offsetH = 1; @@ -671,7 +327,7 @@ void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { usedUhrType->show(min); usedUhrType->show(nach); break; - case 20: // 20 nach + case 20: // 20 past if (!usedUhrType->hasZwanzig() || G.Sprachvariation[ItIs20]) { usedUhrType->show(zehn); usedUhrType->show(vor); @@ -702,7 +358,7 @@ void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { usedUhrType->show(halb); offsetH = 1; break; - case 30: // halb + case 30: // half usedUhrType->show(halb); offsetH = 1; break; @@ -726,7 +382,7 @@ void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { usedUhrType->show(halb); offsetH = 1; break; - case 40: // 20 vor + case 40: // 20 to if (!usedUhrType->hasZwanzig() || G.Sprachvariation[ItIs40]) { usedUhrType->show(zehn); usedUhrType->show(nach); @@ -745,7 +401,7 @@ void ClockWork::clockSetMinute(uint8_t min, uint8_t &offsetH, uint8_t &voll) { usedUhrType->show(vor); offsetH = 1; break; - case 45: // viertel vor + case 45: // quarter to if (usedUhrType->hasDreiviertel() && G.Sprachvariation[ItIs45]) { usedUhrType->show(dreiviertel); } else { @@ -829,7 +485,7 @@ static void countdownToMidnight() { //------------------------------------------------------------------------------ -void ClockWork::clockSetClock() { +void ClockWork::setClock() { uhrzeit = 0; if (!G.Sprachvariation[NotShowItIs]) { @@ -839,24 +495,13 @@ void ClockWork::clockSetClock() { uint8_t offsetH = 0; uint8_t voll = 0; - clockSetMinute(_minute, offsetH, voll); - clockSetHour(_stunde + offsetH, voll); -} - -//------------------------------------------------------------------------------ - -void ClockWork::ledShowSeconds() { - uint8_t rr, gg, bb, ww; - setBrightness(rr, gg, bb, ww, Effect); - - ledSetPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(_sekunde48)); + setMinute(_minute, offsetH, voll); + setHour(_stunde + offsetH, voll); } -//------------------------------------------------------------------------------ -// Wetterdaten anzeigen //------------------------------------------------------------------------------ -void ClockWork::clockShowWeather() { +void ClockWork::showWeather() { switch (wetterswitch) { // +6h @@ -1353,16 +998,16 @@ void ClockWork::clockShowWeather() { //------------------------------------------------------------------------------ -void ClockWork::calcClockFace() { +void ClockWork::calcClockface() { uint8_t rr, gg, bb, ww; if (_stunde == 23 && _minute == 59 && _sekunde >= 50) { countdownToMidnight(); } else { - clockSetClock(); + setClock(); } - // Helligkeitswert ermitteln + // Set Brighness hour dependent if (_stunde < 6) { G.hh = G.h24; } else if (_stunde < 8) { @@ -1381,15 +1026,15 @@ void ClockWork::calcClockFace() { G.hh = G.h22; } - setBrightnessLdr(rr, gg, bb, ww, Background); + led.setBrightnessLdr(rr, gg, bb, ww, Background); - // Hintergrund setzen + // set Background color for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { - ledSetPixel(rr, gg, bb, ww, i); + led.setPixel(rr, gg, bb, ww, i); } if (usedUhrType->hasWeatherLayout()) { - clockShowWeather(); + showWeather(); } } @@ -1397,23 +1042,23 @@ void ClockWork::calcClockFace() { iUhrType *ClockWork::getPointer(uint8_t type) { switch (type) { - case 1: + case Uhr_114: return &Uhr_114_type; - case 2: + case Uhr_114_Alternative: return &Uhr_114_Alternative_type; - case 6: + case Uhr_114_2Clock: return &Uhr_114_2Clock_type; - case 9: + case Uhr_114_Dutch: return &Uhr_114_dutch_type; - case 3: + case Uhr_125: return &Uhr_125_type; - case 8: + case Uhr_125_Type2: return &Uhr_125_type2_type; - case 4: + case Uhr_169: return &Uhr_169_type; - case 5: + case Uhr_242: return &Uhr_242_type; - case 7: + case Uhr_291: return &Uhr_291_type; default: return nullptr; @@ -1457,7 +1102,7 @@ void ClockWork::loop(struct tm &tm) { } previousMillis = currentMillis; - // lass die Zeit im Demo Mode der Animation schneller ablaufen + // Faster runtime for demo animation->demoMode(_minute, _sekunde); //------------------------------------------------ @@ -1468,7 +1113,7 @@ void ClockWork::loop(struct tm &tm) { } //------------------------------------------------ - // Sekunde und LDR Regelung + // Secounds and LDR Routine //------------------------------------------------ if (last_sekunde != _sekunde) { @@ -1478,18 +1123,18 @@ void ClockWork::loop(struct tm &tm) { Serial.printf(currentTime); } - // Wetteruhr + // Weather Clock if (usedUhrType->hasWeatherLayout()) { weather_tag++; } - //--- LDR Regelung + // LDR Routine if ((G.ldr == 1) || G.autoLdrEnabled) { loopLdrLogic(); } if (G.prog == 0 && G.conf == 0) { - ledClear(); + led.clear(); G.prog = COMMAND_MODE_WORD_CLOCK; } @@ -1509,10 +1154,10 @@ void ClockWork::loop(struct tm &tm) { } //------------------------------------------------ - // Wetterdaten abrufen + // Pull Waether Data //------------------------------------------------ if (usedUhrType->hasWeatherLayout() && - weather_tag >= 600) { // @Eisbaeeer changed for Debug (soll 600) + weather_tag >= 600) { // @Eisbaeeer changed for Debug (should be 600) weather_tag = 0; if (WiFi.status() == WL_CONNECTED) { getweather(); @@ -1636,7 +1281,7 @@ void ClockWork::loop(struct tm &tm) { config["animDemo"] = G.animDemo; config["animColorize"] = G.animColorize; JsonArray types = config.createNestedArray("animTypes"); - // Reihenfolge muss zu enum Ani passen! + // Sequence must match to 'enum Anim' types.add("keine"); types.add("Hoch rollen"); types.add("Runter rollen"); @@ -1674,7 +1319,7 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_SET_SETTING_SECOND: case COMMAND_SET_TIME_MANUAL: { eeprom_write(); - ledClear(); + led.clear(); parameters_changed = true; G.conf = COMMAND_IDLE; break; @@ -1691,7 +1336,7 @@ void ClockWork::loop(struct tm &tm) { } case COMMAND_SET_COLORTYPE: { - // G.param1 enthält den neuen Colortype + // G.param1 sets new Colortype Serial.printf("LED Colortype: %u\n", G.param1); // if ((G.param1 != G.Colortype) && ((G.param1 == Grbw) || @@ -1701,12 +1346,12 @@ void ClockWork::loop(struct tm &tm) { G.conf = COMMAND_IDLE; // } - // der G.Colortype muss zeitgleich zu initLedStrip erfolgen, - // sonst wird über einen null-pointer referenziert + // the G.Colortype must be called at the same time as initLedStrip, + // otherwise it is referenced via a null-pointer. G.Colortype = G.param1; eeprom_write(); initLedStrip(G.Colortype); - ledSetIcon(RGB_I, 100, true); + led.setIcon(RGB_I, 100, true); break; } @@ -1730,14 +1375,14 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_SET_WIFI_DISABLED: { eeprom_write(); delay(100); - Serial.println("Conf: WLAN Abgeschaltet"); + Serial.println("Conf: WLAN off"); Network_disable(); G.conf = COMMAND_IDLE; break; } case COMMAND_SET_WIFI_AND_RESTART: { - Serial.println("Conf: WLAN neu konfiguriert"); + Serial.println("Conf: new Wifi Config"); Network_resetSettings(); G.conf = COMMAND_IDLE; break; @@ -1751,14 +1396,14 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_MODE_SECONDS: { if (G.prog_init == 1) { - ledClear(); + led.clear(); G.prog_init = 0; } char d1[5]; char d2[5]; sprintf(d1, "%d", (int)(_sekunde / 10)); sprintf(d2, "%d", (int)(_sekunde % 10)); - ledShowNumbers(d1[0], d2[0]); + led.showNumbers(d1[0], d2[0]); break; } @@ -1767,7 +1412,7 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_MODE_RAINBOW: { if (G.prog_init == 1) { G.prog_init = 0; - ledClear(); + led.clear(); count_delay = (11u - G.geschw) * 30u; } if (count_delay >= (11u - G.geschw) * 30u) { @@ -1795,8 +1440,8 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_MODE_COLOR: { if (G.prog_init == 1) { G.prog_init = 0; - ledSetColor(); - ledShow(); + led.setColor(); + led.show(); } break; } @@ -1807,25 +1452,24 @@ void ClockWork::loop(struct tm &tm) { eeprom_write(); delay(100); } - // Hier ist mit Absicht kein break, direkt nach dem Call - // COMMAND_MODE_ANIMATION muss COMMAND_MODE_WORD_CLOCK aufgerufen - // werden. + // There is no break here on purpose, directly after the call + // COMMAND_MODE_ANIMATION, COMMAND_MODE_WORD_CLOCK must be called } case COMMAND_MODE_WORD_CLOCK: { - calcClockFace(); + calcClockface(); if (changesInClockface()) { copyClockface(Word_array, Word_array_old); - ledSet(true); + led.set(true); } else if (parameters_changed) { - ledSet(); + led.set(); } parameters_changed = false; if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && G.zeige_min < 2) { - ledSetFrameColor(); + led.setFrameColor(); } G.prog = COMMAND_IDLE; } @@ -1851,12 +1495,12 @@ void ClockWork::loopSecondsFrame() { if (last_sekunde48 != _sekunde48) { if (G.prog == 0 && G.conf == 0) { if (G.zeige_sek == 1 || G.zeige_min == 2) { - ledClearFrame(); + led.clearFrame(); } if (G.zeige_sek > 0) { - ledShowSeconds(); + led.showSeconds(); } - ledShow(); + led.show(); } last_sekunde48 = _sekunde48; } @@ -1868,7 +1512,7 @@ void ClockWork::loopWeather() { if ((_sekunde == 0) | (_sekunde == 10) | (_sekunde == 20) | (_sekunde == 30) | (_sekunde == 40) | (_sekunde == 50)) { wetterswitch++; - ledClear(); + led.clear(); if (wetterswitch > 4) { wetterswitch = 1; } @@ -1882,17 +1526,17 @@ void ClockWork::loopWeather() { //------------------------------------------------------------------------------ void ClockWork::initBootLedBlink() { - ledSetAllPixels(50, 50, 50, 50); - ledShow(); + led.setAllPixels(50, 50, 50, 50); + led.show(); } //------------------------------------------------------------------------------ -void ClockWork::initBootLedSweep() { clockWork.ledSingle(20); } +void ClockWork::initBootLedSweep(uint32_t delay) { led.setSingle(delay); } //------------------------------------------------------------------------------ void ClockWork::initBootLed() { - ledClear(); - ledShow(); + led.clear(); + led.show(); } diff --git a/include/led.h b/include/led.h new file mode 100644 index 00000000..ad71787c --- /dev/null +++ b/include/led.h @@ -0,0 +1,49 @@ +#pragma once + +#include + +class Led { +private: +public: + Led(/* args */) = default; + ~Led() = default; + + inline void checkIfHueIsOutOfBound(float &hue); + + void set(bool changed = false); + void setColor(); + void setIcon(uint8_t num_icon, uint8_t brightness, bool rgb_icon = false); + void setFrameColor(); + void setSingle(uint8_t wait); + void setAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww); + void setPixelColorObject(uint16_t i, RgbColor color); + void setPixelColorObject(uint16_t i, RgbwColor color); + void setPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i); + void setPixelHsb(uint16_t ledIndex, float hue, float sat, float bri, + uint8_t alpha = 0); + + void setPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, + uint8_t offsetRow, unsigned char unsigned_d1); + + uint8_t setBrightnessAuto(uint8_t val); + void setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position); + void setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position, uint8_t percentage); + + inline void clear(); + inline void clearFrame(); + inline void clearPixel(uint16_t i); + inline void clearFrontExeptofFontspace(uint8_t offsetRow); + inline void clearClock(); + inline void clearRow(uint8_t row); + + void shiftColumnToRight(); + + void show(); + void showSeconds(); + void showNumbers(const char d1, const char d2); + + RgbColor getPixel(uint16_t i); + RgbwColor getPixelRgbw(uint16_t i); +}; diff --git a/include/led.hpp b/include/led.hpp new file mode 100644 index 00000000..ce09c508 --- /dev/null +++ b/include/led.hpp @@ -0,0 +1,350 @@ +#include "Animation.h" +#include "NeoMultiFeature.hpp" +#include "Uhr.h" +#include "Uhrtypes/Uhrtype.hpp" +#include "font.h" +#include "icons.h" +#include "led.h" +#include + +extern NeoPixelBus *strip_RGB; +extern NeoPixelBus *strip_RGBW; + +extern iUhrType *usedUhrType; +extern Animation *animation; + +//------------------------------------------------------------------------------ + +void Led::setPixel(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww, uint16_t i) { + + if (G.Colortype == Grbw) { + strip_RGBW->SetPixelColor(i, RgbwColor(rr, gg, bb, ww)); + } else { + strip_RGB->SetPixelColor(i, RgbColor(rr, gg, bb)); + } +} + +//------------------------------------------------------------------------------ + +void Led::setPixelHsb(uint16_t ledIndex, float hue, float sat, float bri, + uint8_t alpha) { + HsbColor hsbColor = HsbColor(hue / 360, sat / 100, bri / 100); + + if (G.Colortype == Grbw) { + RgbColor rgbColor = RgbColor(hsbColor); + + strip_RGBW->SetPixelColor( + ledIndex, RgbwColor(rgbColor.R, rgbColor.G, rgbColor.B, alpha)); + } else { + strip_RGB->SetPixelColor(ledIndex, hsbColor); + } +} + +//------------------------------------------------------------------------------ + +void Led::setPixelColorObject(uint16_t i, RgbColor color) { + + if (G.Colortype == Grbw) { + strip_RGBW->SetPixelColor(i, RgbwColor(color)); + } else { + strip_RGB->SetPixelColor(i, color); + } +} + +//------------------------------------------------------------------------------ + +void Led::setPixelColorObject(uint16_t i, RgbwColor color) { + strip_RGBW->SetPixelColor(i, color); +} + +//------------------------------------------------------------------------------ + +RgbColor Led::getPixel(uint16_t i) { + if (G.Colortype == Grbw) { + RgbwColor rgbw = strip_RGBW->GetPixelColor(i); + return RgbColor(rgbw.R, rgbw.G, rgbw.B); + } + return strip_RGB->GetPixelColor(i); +} + +//------------------------------------------------------------------------------ + +RgbwColor Led::getPixelRgbw(uint16_t i) { return strip_RGBW->GetPixelColor(i); } + +//------------------------------------------------------------------------------ + +uint8_t Led::setBrightnessAuto(uint8_t val) { + // G.hh contains time-dependent brightness values in %. + uint16_t u16 = (val * G.hh) / 100; + return (static_cast((u16 * ldrVal) / 100)); +} + +//------------------------------------------------------------------------------ + +void Led::setBrightnessLdr(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position) { + if (G.autoLdrEnabled) { + rr = setBrightnessAuto(G.rgb[position][0]); + gg = setBrightnessAuto(G.rgb[position][1]); + bb = setBrightnessAuto(G.rgb[position][2]); + ww = setBrightnessAuto(G.rgb[position][3]); + } else { + if (G.ldr == 1) { + rr = G.rgb[position][0] * ldrVal / 100; + gg = G.rgb[position][1] * ldrVal / 100; + bb = G.rgb[position][2] * ldrVal / 100; + ww = G.rgb[position][3] * ldrVal / 100; + } else { + rr = G.rgb[position][0] * G.hh / 100; + gg = G.rgb[position][1] * G.hh / 100; + bb = G.rgb[position][2] * G.hh / 100; + ww = G.rgb[position][3] * G.hh / 100; + } + } +} + +//------------------------------------------------------------------------------ + +void Led::setBrightness(uint8_t &rr, uint8_t &gg, uint8_t &bb, uint8_t &ww, + uint8_t position, uint8_t percentage = 100) { + rr = G.rgb[position][0] * percentage / 100; + gg = G.rgb[position][1] * percentage / 100; + bb = G.rgb[position][2] * percentage / 100; + ww = G.rgb[position][3] * percentage / 100; + uint16_t zz = rr + gg + bb; + if (zz > 150) { + zz = zz * 10 / 150; + rr = rr * 10 / zz; + gg = gg * 10 / zz; + bb = bb * 10 / zz; + ww = ww * 10 / zz; + } +} + +//------------------------------------------------------------------------------ + +void Led::show() { + if (G.Colortype == Grbw) { + strip_RGBW->Show(); + } else { + strip_RGB->Show(); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clearPixel(uint16_t i) { + if (G.Colortype == Grbw) { + strip_RGBW->SetPixelColor(i, 0); + } else { + strip_RGB->SetPixelColor(i, 0); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clear() { + for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { + Word_array[i] = 500; + clearPixel(i); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clearClock() { + for (uint16_t i = 0; i < usedUhrType->NUM_SMATRIX(); i++) { + clearPixel(usedUhrType->getSMatrix(i)); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clearRow(uint8_t row) { + for (uint8_t i = 0; i < usedUhrType->COLS_MATRIX(); i++) { + clearPixel(usedUhrType->getFrontMatrix(row, i)); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clearFrontExeptofFontspace(uint8_t offsetRow) { + for (uint8_t i = 0; i < offsetRow; i++) { + clearRow(i); + } + + for (uint8_t i = usedUhrType->ROWS_MATRIX() - 1; i > offsetRow + fontHeight; + i--) { + clearRow(i - 1); + } +} + +//------------------------------------------------------------------------------ + +inline void Led::clearFrame() { + for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { + clearPixel(usedUhrType->getRMatrix(i)); + } +} + +//------------------------------------------------------------------------------ + +void Led::set(bool changed) { + uint8_t rr, gg, bb, ww; + uint8_t r2, g2, b2, w2; + setBrightnessLdr(rr, gg, bb, ww, Foreground); + setBrightnessLdr(r2, g2, b2, w2, Background); + for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { + if (Word_array_old[i] < usedUhrType->NUM_PIXELS()) { + // foreground + setPixel(rr, gg, bb, ww, i); + } else { + // background + setPixel(r2, g2, b2, w2, i); + } + } + if (animation->led_show_notify(changed, _minute)) { + show(); + } +} + +//------------------------------------------------------------------------------ + +void Led::setIcon(uint8_t num_icon, uint8_t brightness = 100, bool rgb_icon) { + uint8_t rr, gg, bb, ww; + setBrightness(rr, gg, bb, ww, Foreground, brightness); + for (uint8_t col = 0; col < GRAFIK_11X10_COLS; col++) { + if (rgb_icon) { + rr = col < 3 ? 255 : 0; + gg = (col > 3) && (col < 7) ? 255 : 0; + bb = col > 7 ? 255 : 0; + ww = 0; + } + for (uint8_t row = 0; row < GRAFIK_11X10_ROWS; row++) { + if (pgm_read_word(&(grafik_11x10[num_icon][row])) & + (1 << (GRAFIK_11X10_COLS - 1 - col))) { + setPixel(rr, gg, bb, ww, usedUhrType->getFrontMatrix(row, col)); + } else { + clearPixel(usedUhrType->getFrontMatrix(row, col)); + } + } + } + show(); +} + +//------------------------------------------------------------------------------ + +void Led::setSingle(uint8_t wait) { + float hue; + + for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { + hue = 360.0 * i / (usedUhrType->NUM_PIXELS() - 1); + hue = hue + 360.0 / usedUhrType->NUM_PIXELS(); + checkIfHueIsOutOfBound(hue); + + clear(); + setPixelHsb(i, hue, 100, 100); + show(); + delay(wait); + } +} + +//------------------------------------------------------------------------------ + +void Led::setAllPixels(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t ww) { + for (uint16_t i = 0; i < usedUhrType->NUM_PIXELS(); i++) { + setPixel(rr, gg, bb, ww, i); + } +} + +//------------------------------------------------------------------------------ + +void Led::setColor() { + uint8_t rr, gg, bb, ww; + setBrightness(rr, gg, bb, ww, Effect); + setAllPixels(rr, gg, bb, ww); +} + +//------------------------------------------------------------------------------ + +void Led::setFrameColor() { + uint8_t rr, gg, bb, ww; + setBrightness(rr, gg, bb, ww, Frame); + + for (uint16_t i = 0; i < usedUhrType->NUM_RMATRIX(); i++) { + setPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(i)); + } +} + +//------------------------------------------------------------------------------ + +void Led::shiftColumnToRight() { + for (uint8_t col = 0; col < usedUhrType->COLS_MATRIX() - 1; col++) { + for (uint8_t row = 0; + row < usedUhrType->ROWS_MATRIX() - 1 /* Only Front*/; row++) { + if (G.Colortype == Grbw) { + setPixelColorObject( + usedUhrType->getFrontMatrix(row, col), + getPixelRgbw(usedUhrType->getFrontMatrix(row, col + 1))); + } else { + setPixelColorObject( + usedUhrType->getFrontMatrix(row, col), + getPixel(usedUhrType->getFrontMatrix(row, col + 1))); + } + } + } +} + +//------------------------------------------------------------------------------ + +void Led::setPixelForChar(uint8_t col, uint8_t row, uint8_t offsetCol, + uint8_t offsetRow, unsigned char unsigned_d1) { + if (pgm_read_byte(&(font_7x5[unsigned_d1][col])) & (1u << row)) { + setPixel(G.rgb[Effect][0], G.rgb[Effect][1], G.rgb[Effect][2], + G.rgb[Effect][3], + usedUhrType->getFrontMatrix(row + offsetRow, col + offsetCol)); + } +} + +//------------------------------------------------------------------------------ + +void Led::showNumbers(const char d1, const char d2) { + clearClock(); + static uint8_t offsetLetter0 = 0; + static uint8_t offsetLetter1 = fontWidth + 1; + uint8_t offsetRow = (usedUhrType->ROWS_MATRIX() - fontHeight - 1) / 2; + + if (usedUhrType->has24HourLayout()) { + offsetLetter0 = 3; + offsetLetter1 = fontWidth + 4; + } + + for (uint8_t col = 0; col < fontWidth; col++) { + for (uint8_t row = 0; row < fontHeight; row++) { + // 1. Number without Offset + setPixelForChar(col, row, offsetLetter0, offsetRow, + static_cast(d1)); + // 2. Number with Offset + setPixelForChar(col, row, offsetLetter1, offsetRow, + static_cast(d2)); + } + } + show(); +} + +//------------------------------------------------------------------------------ + +void Led::showSeconds() { + uint8_t rr, gg, bb, ww; + setBrightness(rr, gg, bb, ww, Effect); + + setPixel(rr, gg, bb, ww, usedUhrType->getRMatrix(_sekunde48)); +} + +//------------------------------------------------------------------------------ + +inline void Led::checkIfHueIsOutOfBound(float &hue) { + if (hue > 360) { + hue = 0; + } +} \ No newline at end of file diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 964dcc0d..7e1c04ab 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -110,15 +110,18 @@ RTC_Type RTC; #include "Animation.h" #include "clockWork.h" +#include "led.h" #include "mqtt.h" Animation *animation; +Led led; ClockWork clockWork; Mqtt mqtt; #include "Animation.hpp" #include "clockWork.hpp" #include "icons.h" +#include "led.hpp" #include "mqtt.hpp" #include "wifi_func.hpp" @@ -295,7 +298,7 @@ void setup() { delay(20); } if (G.bootLedSweep) { - clockWork.initBootLedSweep(); + clockWork.initBootLedSweep(20); } clockWork.initBootLed(); @@ -382,7 +385,7 @@ void setup() { /* // setup frame if (usedUhrType->hasSecondsFrame() && G.zeige_sek < 1 && G.zeige_min < 2) { - clockWork.ledSetFrameColor(); + led.setFrameColor(); } */ From 322c1ef2ad92fbec26ce1ac511997f975045ecaf Mon Sep 17 00:00:00 2001 From: David Panusch Date: Sun, 8 Jan 2023 14:16:17 +0100 Subject: [PATCH 14/15] Renamed the file Network.cpp to network.hpp and moved it to include folder. Created a Class Network in header to create a coommon Namespace for all Network related funktions. Changes to be committed: modified: include/Network.h modified: include/WebPage_Adapter.h modified: include/clockWork.hpp new file: include/network.hpp deleted: src/Network.cpp modified: src/Wortuhr.cpp --- include/Network.h | 33 ++++++++++++++++++------------ include/WebPage_Adapter.h | 1 - include/clockWork.hpp | 8 ++++---- include/network.hpp | 40 +++++++++++++++++++++++++++++++++++++ src/Network.cpp | 42 --------------------------------------- src/Wortuhr.cpp | 11 ++++++---- 6 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 include/network.hpp delete mode 100644 src/Network.cpp diff --git a/include/Network.h b/include/Network.h index b4c02cd9..71f2220e 100644 --- a/include/Network.h +++ b/include/Network.h @@ -1,15 +1,22 @@ #pragma once -#include - -void Network_info(); -int Network_getQuality(); -void Network_disable(); -void Network_reboot(); -void Network_resetSettings(); -String Network_getSSID(); -void Network_rtcMode(); -void Network_changeHostname(const char *hostname); - -void Network_setup(const char *hostname); -void Network_loop(); +class Network { +private: + const char *connectionSSID = "WortUhr_verbinden"; + +public: + Network(/* args */) = default; + ~Network() = default; + + void info(); + int getQuality(); + void disable(); + void reboot(); + void resetSettings(); + String getSSID(); + void rtcMode(); + void changeHostname(const char *hostname); + + void setup(const char *hostname); + void loop(); +}; diff --git a/include/WebPage_Adapter.h b/include/WebPage_Adapter.h index adc56c5d..5f0610cd 100644 --- a/include/WebPage_Adapter.h +++ b/include/WebPage_Adapter.h @@ -1,6 +1,5 @@ #pragma once -#include "Network.h" #include "Uhr.h" #include "WebPageContent.h" #include "WebSocketsServer.h" diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 8a2e74a8..0d2a3450 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -1196,7 +1196,7 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_REQUEST_CONFIG_VALUES: { DynamicJsonDocument config(1024); config["command"] = "config"; - config["ssid"] = Network_getSSID(); + config["ssid"] = network.getSSID(); config["zeitserver"] = G.zeitserver; config["hostname"] = G.hostname; config["ltext"] = G.ltext; @@ -1367,7 +1367,7 @@ void ClockWork::loop(struct tm &tm) { Serial.print("Hostname: "); Serial.println(G.hostname); eeprom_write(); - Network_reboot(); + network.reboot(); G.conf = COMMAND_IDLE; break; } @@ -1376,14 +1376,14 @@ void ClockWork::loop(struct tm &tm) { eeprom_write(); delay(100); Serial.println("Conf: WLAN off"); - Network_disable(); + network.disable(); G.conf = COMMAND_IDLE; break; } case COMMAND_SET_WIFI_AND_RESTART: { Serial.println("Conf: new Wifi Config"); - Network_resetSettings(); + network.resetSettings(); G.conf = COMMAND_IDLE; break; } diff --git a/include/network.hpp b/include/network.hpp new file mode 100644 index 00000000..4d727936 --- /dev/null +++ b/include/network.hpp @@ -0,0 +1,40 @@ +#include "network.h" + +#include +#include +#include + +WiFiManager wifiManager(Serial); + +void Network::info() { WiFi.printDiag(Serial); } + +int Network::getQuality() { + int rssi = WiFi.RSSI(); + return wifiManager.getRSSIasQuality(rssi); +} + +void Network::rtcMode() { wifiManager.setConfigPortalTimeout(120); } + +void Network::disable() { wifiManager.disconnect(); } + +void Network::reboot() { wifiManager.reboot(); } + +void Network::resetSettings() { + wifiManager.resetSettings(); + wifiManager.reboot(); +} + +String Network::getSSID() { return wifiManager.getWiFiSSID(); } + +void Network::setup(const char *hostname) { + wifiManager.setHostname(hostname); +#ifdef MANUAL_WIFI_SETTINGS + wifiManager.preloadWiFi(WIFI_SSID, WIFI_PASSWORD); +#endif + wifiManager.autoConnect(connectionSSID); + // explicitly disable AP, esp defaults to STA+AP + WiFi.enableAP(false); + Network::info(); +} + +void Network::loop() { wifiManager.process(); } diff --git a/src/Network.cpp b/src/Network.cpp deleted file mode 100644 index d3aeb0b9..00000000 --- a/src/Network.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "Network.h" - -#include -#include -#include - -WiFiManager wifiManager(Serial); - -const char *connectionSSID = "WortUhr_verbinden"; - -void Network_info() { WiFi.printDiag(Serial); } - -int Network_getQuality() { - int rssi = WiFi.RSSI(); - return wifiManager.getRSSIasQuality(rssi); -} - -void Network_rtcMode() { wifiManager.setConfigPortalTimeout(120); } - -void Network_disable() { wifiManager.disconnect(); } - -void Network_reboot() { wifiManager.reboot(); } - -void Network_resetSettings() { - wifiManager.resetSettings(); - wifiManager.reboot(); -} - -String Network_getSSID() { return wifiManager.getWiFiSSID(); } - -void Network_setup(const char *hostname) { - wifiManager.setHostname(hostname); -#ifdef MANUAL_WIFI_SETTINGS - wifiManager.preloadWiFi(WIFI_SSID, WIFI_PASSWORD); -#endif - wifiManager.autoConnect(connectionSSID); - // explicitly disable AP, esp defaults to STA+AP - WiFi.enableAP(false); - Network_info(); -} - -void Network_loop() { wifiManager.process(); } diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 7e1c04ab..7051e3d6 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -112,17 +112,20 @@ RTC_Type RTC; #include "clockWork.h" #include "led.h" #include "mqtt.h" +#include "network.h" Animation *animation; Led led; ClockWork clockWork; Mqtt mqtt; +Network network; #include "Animation.hpp" #include "clockWork.hpp" #include "icons.h" #include "led.hpp" #include "mqtt.hpp" +#include "network.hpp" #include "wifi_func.hpp" #define EEPROM_SIZE 512 @@ -313,7 +316,7 @@ void setup() { struct timeval tv; tv.tv_sec = RTC.now().unixtime(); settimeofday(&tv, nullptr); - Network_rtcMode(); + network.rtcMode(); externalRTC = true; } else { Serial.println("No external RealtimeClock found"); @@ -335,8 +338,8 @@ void setup() { if (G.bootShowWifi) { clockWork.initBootWifiSignalStrength(0); } - Network_setup(G.hostname); - int strength = Network_getQuality(); + network.setup(G.hostname); + int strength = network.getQuality(); Serial.printf("Signal strength: %i\n", strength); if (G.bootShowWifi) { clockWork.initBootWifiSignalStrength(strength); @@ -435,7 +438,7 @@ void loop() { _stunde = tm.tm_hour; } - Network_loop(); + network.loop(); MDNS.update(); From ea6db1439ca78425d5436f8e9a9690a4e3278bdb Mon Sep 17 00:00:00 2001 From: David Panusch Date: Sun, 8 Jan 2023 15:24:25 +0100 Subject: [PATCH 15/15] Renamed Network.h -> network.h ... My system is not case sensitive. The was basicly "Works on my machine" :-) Changes to be committed: renamed: include/Network.h -> include/network.h --- include/{Network.h => network.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename include/{Network.h => network.h} (100%) diff --git a/include/Network.h b/include/network.h similarity index 100% rename from include/Network.h rename to include/network.h