diff --git a/wled00/src/dependencies/espalexa/Espalexa.h b/wled00/src/dependencies/espalexa/Espalexa.h index b55f3b25c..997fada22 100644 --- a/wled00/src/dependencies/espalexa/Espalexa.h +++ b/wled00/src/dependencies/espalexa/Espalexa.h @@ -10,7 +10,7 @@ */ /* * @title Espalexa library - * @version 2.4.0 + * @version 2.4.2 * @author Christian Schwinne * @license MIT * @contributors d-999 @@ -49,7 +49,7 @@ #include #ifdef ESPALEXA_DEBUG - #pragma message "Espalexa 2.4.0 debug mode" + #pragma message "Espalexa 2.4.2 debug mode" #define EA_DEBUG(x) Serial.print (x) #define EA_DEBUGLN(x) Serial.println (x) #else @@ -118,7 +118,7 @@ private: case EspalexaDeviceType::color: return "LST001"; case EspalexaDeviceType::extendedcolor: return "LCT015"; } - return "Plug 01"; + return "Plug"; } //device JSON string: color+temperature device emulates LCT015, dimmable device LWB010, (TODO: on/off Plug 01, color temperature device LWT010, color device LST001) @@ -148,9 +148,9 @@ private: json += "\"type\":\"" + typeString(dev->getType()); json += "\",\"name\":\"" + dev->getName(); json += "\",\"modelid\":\"" + modelidString(dev->getType()); - json += "\",\"manufacturername\":\"Espalexa\",\"productname\":\"E" + String(static_cast(dev->getType())); + json += "\",\"manufacturername\":\"Philips\",\"productname\":\"E" + String(static_cast(dev->getType())); json += "\",\"uniqueid\":\""+ WiFi.macAddress() +"-"+ (deviceId+1); - json += "\",\"swversion\":\"2.4.0\"}"; + json += "\",\"swversion\":\"espalexa-2.4.2\"}"; return json; } @@ -174,7 +174,7 @@ private: } res += "\r\nFree Heap: " + (String)ESP.getFreeHeap(); res += "\r\nUptime: " + (String)millis(); - res += "\r\n\r\nEspalexa library v2.4.0 by Christian Schwinne 2019"; + res += "\r\n\r\nEspalexa library v2.4.2 by Christian Schwinne 2019"; server->send(200, "text/plain", res); } #endif @@ -386,7 +386,7 @@ public: return true; } - //deprecated brightness-only callback + //brightness-only callback bool addDevice(String deviceName, BrightnessCallbackFunction callback, uint8_t initialValue = 0) { EA_DEBUG("Constructing device "); @@ -395,6 +395,17 @@ public: EspalexaDevice* d = new EspalexaDevice(deviceName, callback, initialValue); return addDevice(d); } + + //brightness-only callback + bool addDevice(String deviceName, ColorCallbackFunction callback, uint8_t initialValue = 0) + { + EA_DEBUG("Constructing device "); + EA_DEBUGLN((currentDeviceCount+1)); + if (currentDeviceCount >= ESPALEXA_MAXDEVICES) return false; + EspalexaDevice* d = new EspalexaDevice(deviceName, callback, initialValue); + return addDevice(d); + } + bool addDevice(String deviceName, DeviceCallbackFunction callback, EspalexaDeviceType t = EspalexaDeviceType::dimmable, uint8_t initialValue = 0) { @@ -546,6 +557,13 @@ public: return escapedMac; } + //convert brightness (0-255) to percentage + uint8_t toPercent(uint8_t bri) + { + uint16_t perc = bri * 100; + return perc / 255; + } + ~Espalexa(){delete devices;} //note: Espalexa is NOT meant to be destructed }; diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.cpp b/wled00/src/dependencies/espalexa/EspalexaDevice.cpp index f440b800a..43ad6f02f 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.cpp +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.cpp @@ -4,7 +4,7 @@ EspalexaDevice::EspalexaDevice(){} -EspalexaDevice::EspalexaDevice(String deviceName, BrightnessCallbackFunction gnCallback, uint8_t initialValue) { //constructor +EspalexaDevice::EspalexaDevice(String deviceName, BrightnessCallbackFunction gnCallback, uint8_t initialValue) { //constructor for dimmable device _deviceName = deviceName; _callback = gnCallback; @@ -13,12 +13,21 @@ EspalexaDevice::EspalexaDevice(String deviceName, BrightnessCallbackFunction gnC _type = EspalexaDeviceType::dimmable; } -EspalexaDevice::EspalexaDevice(String deviceName, DeviceCallbackFunction gnCallback, EspalexaDeviceType t, uint8_t initialValue) { //constructor for color device +EspalexaDevice::EspalexaDevice(String deviceName, ColorCallbackFunction gnCallback, uint8_t initialValue) { //constructor for color device + + _deviceName = deviceName; + _callbackCol = gnCallback; + _val = initialValue; + _val_last = _val; + _type = EspalexaDeviceType::extendedcolor; +} + +EspalexaDevice::EspalexaDevice(String deviceName, DeviceCallbackFunction gnCallback, EspalexaDeviceType t, uint8_t initialValue) { //constructor for general device _deviceName = deviceName; _callbackDev = gnCallback; - _callback = nullptr; _type = t; + if (t == EspalexaDeviceType::onoff) _type = EspalexaDeviceType::dimmable; //on/off is broken, so make dimmable device instead _val = initialValue; _val_last = _val; } @@ -305,5 +314,7 @@ void EspalexaDevice::setColor(uint8_t r, uint8_t g, uint8_t b) void EspalexaDevice::doCallback() { - (_callback != nullptr) ? _callback(_val) : _callbackDev(this); + if (_callback != nullptr) {_callback(_val); return;} + if (_callbackDev != nullptr) {_callbackDev(this); return;} + if (_callbackCol != nullptr) _callbackCol(_val, getRGB()); } \ No newline at end of file diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.h b/wled00/src/dependencies/espalexa/EspalexaDevice.h index 07708d073..8d7be8736 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.h +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.h @@ -7,6 +7,7 @@ typedef class EspalexaDevice; typedef void (*BrightnessCallbackFunction) (uint8_t b); typedef void (*DeviceCallbackFunction) (EspalexaDevice* d); +typedef void (*ColorCallbackFunction) (uint8_t br, uint32_t col); enum class EspalexaColorMode : uint8_t { none = 0, ct = 1, hs = 2, xy = 3 }; enum class EspalexaDeviceType : uint8_t { onoff = 0, dimmable = 1, whitespectrum = 2, color = 3, extendedcolor = 4 }; @@ -15,22 +16,24 @@ enum class EspalexaDeviceProperty : uint8_t { none = 0, on = 1, off = 2, bri = 3 class EspalexaDevice { private: String _deviceName; - BrightnessCallbackFunction _callback; - DeviceCallbackFunction _callbackDev; + BrightnessCallbackFunction _callback = nullptr; + DeviceCallbackFunction _callbackDev = nullptr; + ColorCallbackFunction _callbackCol = nullptr; uint8_t _val, _val_last, _sat = 0; uint16_t _hue = 0, _ct = 0; - float _x = 0, _y = 0; + float _x = 0.5, _y = 0.5; uint32_t _rgb = 0; uint8_t _id = 0; EspalexaDeviceType _type; EspalexaDeviceProperty _changed = EspalexaDeviceProperty::none; - EspalexaColorMode _mode; + EspalexaColorMode _mode = EspalexaColorMode::xy; public: EspalexaDevice(); ~EspalexaDevice(); EspalexaDevice(String deviceName, BrightnessCallbackFunction bcb, uint8_t initialValue =0); EspalexaDevice(String deviceName, DeviceCallbackFunction dcb, EspalexaDeviceType t =EspalexaDeviceType::dimmable, uint8_t initialValue =0); + EspalexaDevice(String deviceName, ColorCallbackFunction ccb, uint8_t initialValue =0); String getName(); uint8_t getId(); diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 08d1a9b28..3f7516f6e 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -98,7 +98,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1903272 +#define VERSION 1904141 char versionString[] = "0.8.4"; diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index ad1c78a54..4e3d2399a 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -31,7 +31,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) int t = request->arg("AT").toInt(); if (t > 9 && t <= 255) apWaitTimeSecs = t; strcpy(apSSID, request->arg("AS").c_str()); apHide = request->hasArg("AH"); - if (request->arg("AP").charAt(0) != '*') strcpy(apPass, request->arg("AP").c_str()); + int passlen = request->arg("AP").length(); + if (passlen == 0 || (passlen > 7 && request->arg("AP").charAt(0) != '*')) strcpy(apPass, request->arg("AP").c_str()); t = request->arg("AC").toInt(); if (t > 0 && t < 14) apChannel = t; char k[3]; k[2] = 0; diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index d6a6a9abb..d54c80d02 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -64,9 +64,10 @@ void arlsLock(uint32_t timeoutMs) strip.setPixelColor(i,0,0,0,0); } strip.unlockAll(); + realtimeActive = true; } - realtimeActive = true; realtimeTimeout = millis() + timeoutMs; + if (timeoutMs == 255001 || timeoutMs == 65000) realtimeTimeout = UINT32_MAX; if (arlsForceMaxBri) strip.setBrightness(255); } @@ -206,10 +207,10 @@ void handleNotifications() if (packetSize > 1) { if (udpIn[1] == 0) { - realtimeActive = false; + realtimeTimeout = 0; return; } else { - arlsLock(udpIn[1]*1000); + arlsLock(udpIn[1]*1000 +1); } if (udpIn[0] == 1) //warls { diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index 00476d4c6..2395c5db2 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -87,11 +87,16 @@ void colorUpdated(int callMode) { if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5) { - notify(4); return; + notify(4); interfaceUpdateCallMode = 4; return; + } + else if (fxChanged) { + notify(6); + if (callMode != 8) interfaceUpdateCallMode = 6; + if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; } - else if (fxChanged) notify(6); return; //no change } + if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; if (callMode != 5 && nightlightActive && nightlightFade) { briNlT = bri; @@ -134,13 +139,8 @@ void colorUpdated(int callMode) } if (callMode == 8) return; - //only update Blynk and mqtt every 2 seconds to reduce lag - if (millis() - lastInterfaceUpdate <= 2000) - { - interfaceUpdateCallMode = callMode; - return; - } - updateInterfaces(callMode); + //set flag to update blynk and mqtt + interfaceUpdateCallMode = callMode; } diff --git a/wled00/wled17_mqtt.ino b/wled00/wled17_mqtt.ino index 4d018803e..92b203ac9 100644 --- a/wled00/wled17_mqtt.ino +++ b/wled00/wled17_mqtt.ino @@ -6,7 +6,7 @@ void parseMQTTBriPayload(char* payload) { - if (strstr(payload, "ON") || strstr(payload, "on")) {bri = briLast; colorUpdated(1);} + if (strstr(payload, "ON") || strstr(payload, "on") || strstr(payload, "true")) {bri = briLast; colorUpdated(1);} else if (strstr(payload, "T" ) || strstr(payload, "t" )) {toggleOnOff(); colorUpdated(1);} else { uint8_t in = strtoul(payload, NULL, 10);