From c7379df6eaadbe3fb440a097045d10abe1fc28cc Mon Sep 17 00:00:00 2001 From: Igor Dulevich Date: Fri, 6 Sep 2024 17:27:28 +0300 Subject: [PATCH 1/2] First upload fix and clockfaces new line char fix --- EleksTubeHAX_pio/src/TFTs.cpp | 1 + EleksTubeHAX_pio/src/main.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/EleksTubeHAX_pio/src/TFTs.cpp b/EleksTubeHAX_pio/src/TFTs.cpp index d8a2a87..17f1874 100644 --- a/EleksTubeHAX_pio/src/TFTs.cpp +++ b/EleksTubeHAX_pio/src/TFTs.cpp @@ -57,6 +57,7 @@ void TFTs::loadClockFacesNames() { } while(f.available() && i<9) { patterns_str[i] = f.readStringUntil('\n'); + patterns_str[i].replace(String(char(13)), ""); Serial.println(patterns_str[i]); i++; } diff --git a/EleksTubeHAX_pio/src/main.cpp b/EleksTubeHAX_pio/src/main.cpp index d942c1e..00ab517 100644 --- a/EleksTubeHAX_pio/src/main.cpp +++ b/EleksTubeHAX_pio/src/main.cpp @@ -127,6 +127,10 @@ void setup() { uclock.setActiveGraphicIdx(tfts.NumberOfClockFaces); Serial.println("Last selected index of clock face is larger than currently available number of image sets."); } + if (uclock.getActiveGraphicIdx() < 1) { + uclock.setActiveGraphicIdx(1); + Serial.println("Last selected index of clock face is less than 1."); + } tfts.current_graphic = uclock.getActiveGraphicIdx(); tfts.println("Done with setup."); From b77fce8696d11e68ee7271769bd0691934a40112 Mon Sep 17 00:00:00 2001 From: Igor Dulevich Date: Mon, 9 Sep 2024 21:03:36 +0300 Subject: [PATCH 2/2] 3 additional attributes to backlight, code cleanup, small fixes --- EleksTubeHAX_pio/src/Mqtt_client_ips.cpp | 56 ++++++++++-------------- EleksTubeHAX_pio/src/TFTs.cpp | 2 +- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/EleksTubeHAX_pio/src/Mqtt_client_ips.cpp b/EleksTubeHAX_pio/src/Mqtt_client_ips.cpp index a44d414..45ce712 100644 --- a/EleksTubeHAX_pio/src/Mqtt_client_ips.cpp +++ b/EleksTubeHAX_pio/src/Mqtt_client_ips.cpp @@ -11,7 +11,7 @@ */ #include "Mqtt_client_ips.h" -#include "WiFi.h" // for ESP32 +#include "WiFi.h" // for ESP32 #include // Download and install this library first from: https://www.arduinolibraries.info/libraries/pub-sub-client #include #include "TempSensor.h" @@ -57,7 +57,7 @@ uint32_t lastTimeSent = (uint32_t)(MQTT_REPORT_STATUS_EVERY_SEC * -1000); uint8_t LastNotificationChecksum = 0; uint32_t LastTimeTriedToConnect = 0; -bool MqttConnected = true; // skip error meggase if disabled +bool MqttConnected = true; // skip error message if disabled // commands from server // = "directive/status" bool MqttCommandPower = true; bool MqttCommandMainPower = true; @@ -71,12 +71,12 @@ bool MqttCommandUseTwelveHoursReceived = false; bool MqttCommandBlankZeroHours = false; bool MqttCommandBlankZeroHoursReceived = false; -int MqttCommandState = 1; +int MqttCommandState = 1; bool MqttCommandStateReceived = false; uint8_t MqttCommandBrightness = -1; uint8_t MqttCommandMainBrightness = -1; -uint8_t MqttCommandBackBrightness = -1; +uint8_t MqttCommandBackBrightness = -1; bool MqttCommandBrightnessReceived = false; bool MqttCommandMainBrightnessReceived = false; bool MqttCommandBackBrightnessReceived = false; @@ -89,18 +89,18 @@ bool MqttCommandBackPatternReceived = false; uint16_t MqttCommandBackColorPhase = -1; bool MqttCommandBackColorPhaseReceived = false; -uint8_t MqttCommandGraphic = -1; +uint8_t MqttCommandGraphic = -1; bool MqttCommandGraphicReceived = false; -uint8_t MqttCommandMainGraphic = -1; +uint8_t MqttCommandMainGraphic = -1; bool MqttCommandMainGraphicReceived = false; -uint8_t MqttCommandPulseBpm = -1; +uint8_t MqttCommandPulseBpm = -1; bool MqttCommandPulseBpmReceived = false; -uint8_t MqttCommandBreathBpm = -1; +uint8_t MqttCommandBreathBpm = -1; bool MqttCommandBreathBpmReceived = false; -float MqttCommandRainbowSec = -1; +float MqttCommandRainbowSec = -1; bool MqttCommandRainbowSecReceived = false; // status to server @@ -143,7 +143,7 @@ uint8_t LastSentBreathBpm = -1; float LastSentRainbowSec = -1; double round1(double value) { - return (int)(value * 10 + 0.5) / 10.0; + return (int)(value * 10 + 0.5) / 10.0; } void sendToBroker(const char* topic, const char* message) { @@ -161,20 +161,14 @@ void sendToBroker(const char* topic, const char* message) { Serial.print(topicArr); Serial.print(" "); Serial.println(message); -#endif - delay (120); +#endif + delay (120); } } void MqttReportState(bool force) { #ifdef MQTT_HOME_ASSISTANT if(MQTTclient.connected()) { - // time_t rawtime; - // struct tm * timeinfo; - // char last_seen [80]; - // rawtime = uclock.local_time; - // timeinfo = localtime (&rawtime); - // strftime (last_seen, 80, "%Y-%m-%dT%H:%M:%SZ", timeinfo); if(force || MqttStatusMainPower != LastSentMainPowerState @@ -185,7 +179,6 @@ void MqttReportState(bool force) { state["state"] = MqttStatusMainPower == 0 ? MQTT_STATE_OFF : MQTT_STATE_ON; state["brightness"] = MqttStatusMainBrightness; state["effect"] = tfts.clockFaceToName(MqttStatusMainGraphic); - // state["Last seen"] = last_seen; char buffer[256]; size_t n = serializeJson(state, buffer); @@ -205,17 +198,21 @@ void MqttReportState(bool force) { || MqttStatusBackPower != LastSentBackPowerState || MqttStatusBackBrightness != LastSentBackBrightness || strcmp(MqttStatusBackPattern, LastSentBackPattern) != 0 - || MqttStatusBackColorPhase != LastSentBackColorPhase ) { + || MqttStatusBackColorPhase != LastSentBackColorPhase + || MqttStatusPulseBpm != LastSentPulseBpm + || MqttStatusBreathBpm != LastSentBreathBpm + || MqttStatusRainbowSec != LastSentRainbowSec ) { JsonDocument state; state["state"] = MqttStatusBackPower == 0 ? MQTT_STATE_OFF : MQTT_STATE_ON; - state["brightness"] = MqttStatusBackBrightness; //map(MqttStatusBackBrightness, MQTT_ITENSITY_MIN, MQTT_ITENSITY_MAX, MQTT_BRIGHTNESS_MIN, MQTT_BRIGHTNESS_MAX); + state["brightness"] = MqttStatusBackBrightness; state["effect"] = MqttStatusBackPattern; state["color_mode"] = "hs"; - state["color"]["h"] = backlights.phaseToHue(MqttStatusBackColorPhase); + state["color"]["h"] = backlights.phaseToHue(MqttStatusBackColorPhase); state["color"]["s"] = 100.f; - // state["color"]["b"] = backlights.phaseToIntensity((MqttStatusBackColorPhase + 512) % backlights.max_phase); - // state["Last seen"] = last_seen; + state["pulse_bpm"] = MqttStatusPulseBpm; + state["beath_bpm"] = MqttStatusBreathBpm; + state["rainbow_sec"] = round1(MqttStatusRainbowSec); char buffer[256]; size_t n = serializeJson(state, buffer); @@ -237,7 +234,6 @@ void MqttReportState(bool force) { JsonDocument state; state["state"] = MqttStatusUseTwelveHours ? MQTT_STATE_ON : MQTT_STATE_OFF; - // state["Last seen"] = last_seen; char buffer[256]; size_t n = serializeJson(state, buffer); @@ -256,7 +252,6 @@ void MqttReportState(bool force) { JsonDocument state; state["state"] = MqttStatusBlankZeroHours ? MQTT_STATE_ON : MQTT_STATE_OFF; - // state["Last seen"] = last_seen; char buffer[256]; size_t n = serializeJson(state, buffer); @@ -275,7 +270,6 @@ void MqttReportState(bool force) { JsonDocument state; state["state"] = MqttStatusPulseBpm; - // state["Last seen"] = last_seen; char buffer[256]; size_t n = serializeJson(state, buffer); @@ -294,7 +288,6 @@ void MqttReportState(bool force) { JsonDocument state; state["state"] = MqttStatusBreathBpm; - // state["Last seen"] = last_seen; char buffer[256]; size_t n = serializeJson(state, buffer); @@ -313,7 +306,6 @@ void MqttReportState(bool force) { JsonDocument state; state["state"] = round1(MqttStatusRainbowSec); - // state["Last seen"] = last_seen; char buffer[256]; serializeJson(state, buffer); @@ -423,7 +415,7 @@ void checkMqtt() { } } -void callback(char* topic, byte* payload, unsigned int length) { //A new message has been received +void callback(char* topic, byte* payload, unsigned int length) { // A new message has been received #ifdef DEBUG_OUTPUT Serial.print("Received MQTT topic: "); Serial.print(topic); // long output @@ -456,7 +448,7 @@ void callback(char* topic, byte* payload, unsigned int length) { //A new messag return; } - //------------------Decide what to do depending on the topic and message--------------------------------- + //------------------Decide what to do depending on the topic and message--------------------------------- if (strcmp(command[0], "directive") == 0 && strcmp(command[1], "powerState") == 0) { // Turn On or OFF if (strcmp(message, "ON") == 0) { MqttCommandPower = true; @@ -512,7 +504,7 @@ void callback(char* topic, byte* payload, unsigned int length) { //A new messag MqttCommandBackPowerReceived = true; } if(doc.containsKey("brightness")) { - MqttCommandBackBrightness = doc["brightness"]; //map(doc["brightness"], MQTT_BRIGHTNESS_MIN, MQTT_BRIGHTNESS_MAX, MQTT_ITENSITY_MIN, MQTT_ITENSITY_MAX); + MqttCommandBackBrightness = doc["brightness"]; MqttCommandBackBrightnessReceived = true; } if(doc.containsKey("effect")) { diff --git a/EleksTubeHAX_pio/src/TFTs.cpp b/EleksTubeHAX_pio/src/TFTs.cpp index 17f1874..05dcf83 100644 --- a/EleksTubeHAX_pio/src/TFTs.cpp +++ b/EleksTubeHAX_pio/src/TFTs.cpp @@ -57,7 +57,7 @@ void TFTs::loadClockFacesNames() { } while(f.available() && i<9) { patterns_str[i] = f.readStringUntil('\n'); - patterns_str[i].replace(String(char(13)), ""); + patterns_str[i].replace("\r", ""); Serial.println(patterns_str[i]); i++; }