From 94cf2c18aadd8b9f984c8ad069296a6fcd27ad2b Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 14 Nov 2020 18:26:30 +0100 Subject: [PATCH] Fix light bug --- src/hasp_attribute.cpp | 7 ------- src/hasp_dispatch.cpp | 18 +++++++++++------- src/hasp_dispatch.h | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/hasp_attribute.cpp b/src/hasp_attribute.cpp index 0a5f4c20..c4ed9d88 100644 --- a/src/hasp_attribute.cpp +++ b/src/hasp_attribute.cpp @@ -11,7 +11,6 @@ LV_FONT_DECLARE(unscii_8_icon); extern lv_font_t * haspFonts[8]; -static bool is_true(const char * s); static inline bool only_digits(const char * s); /* 16-bit hashing function http://www.cse.yorku.ca/~oz/hash.html */ @@ -909,12 +908,6 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char /* ************************** * Static Inline functions * **************************/ -static bool is_true(const char * s) -{ - return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) || - !strcmp_P(s, PSTR("1"))); -} - static inline bool only_digits(const char * s) { size_t digits = 0; diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp index f62f4d3d..50f77695 100644 --- a/src/hasp_dispatch.cpp +++ b/src/hasp_dispatch.cpp @@ -13,9 +13,10 @@ #include "hasp_hal.h" #include "hasp.h" -inline bool isON(const char * payload) + bool is_true(const char * s) { - return strcasecmp_P(payload, PSTR("ON")) == 0; + return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) || + !strcmp_P(s, PSTR("1"))); } void dispatchSetup() @@ -71,7 +72,7 @@ void dispatchGpioOutput(String strTopic, const char * payload) String strTemp((char *)0); strTemp.reserve(128); strTemp = strTopic.substring(7, strTopic.length()); - dispatchGpioOutput(strTemp.toInt(), isON(payload)); + dispatchGpioOutput(strTemp.toInt(), is_true(payload)); } void dispatchParseJson(char * payload) @@ -311,15 +312,18 @@ void dispatchBacklight(const char * payload) // dispatchPrintln(F("LIGHT"), strPayload); // Set the current state - if(strlen(payload) != 0) guiSetBacklight(isON(payload)); + if(strlen(payload) != 0) guiSetBacklight(is_true(payload)); + + // Return the current state + char buffer[4]; + memcpy_P(buffer, guiGetBacklight() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer)); - // Return the current state #if HASP_USE_MQTT > 0 - mqtt_send_state(F("light"), guiGetBacklight() ? PSTR("ON") : PSTR("OFF")); + mqtt_send_state(F("light"), buffer); #endif #if HASP_USE_TASMOTA_SLAVE > 0 - slave_send_state(F("light"), guiGetBacklight() ? PSTR("ON") : PSTR("OFF")); + slave_send_state(F("light"), buffer); #endif } diff --git a/src/hasp_dispatch.h b/src/hasp_dispatch.h index 35103e3c..55b60f2c 100644 --- a/src/hasp_dispatch.h +++ b/src/hasp_dispatch.h @@ -5,6 +5,8 @@ #define LOG_CMND_CTR "CMND: " +bool is_true(const char * s); + void dispatchSetup(void); void dispatchLoop(void);