Fixed presets using wrong call mode (e.g. causing buttons to send UDP under direct change type)

Increased hue buffer
This commit is contained in:
cschwinne 2021-07-09 18:42:52 +02:00
parent 5da47636cf
commit 2c6850f6e4
11 changed files with 56 additions and 49 deletions

View File

@ -2,6 +2,11 @@
### Builds after release 0.12.0 ### Builds after release 0.12.0
#### Build 2107091
- Fixed presets using wrong call mode (e.g. causing buttons to send UDP under direct change type)
- Increased hue buffer
#### Build 2107090 #### Build 2107090
- Busses extend total configured LEDs if required - Busses extend total configured LEDs if required

View File

@ -47,7 +47,7 @@ void onAlexaChange(EspalexaDevice* dev)
colorUpdated(NOTIFIER_CALL_MODE_ALEXA); colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
} }
} else { } else {
applyPreset(macroAlexaOn); applyPreset(macroAlexaOn, NOTIFIER_CALL_MODE_ALEXA);
if (bri == 0) espalexaDevice->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on if (bri == 0) espalexaDevice->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on
} }
} else if (m == EspalexaDeviceProperty::off) } else if (m == EspalexaDeviceProperty::off)
@ -61,7 +61,7 @@ void onAlexaChange(EspalexaDevice* dev)
colorUpdated(NOTIFIER_CALL_MODE_ALEXA); colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
} }
} else { } else {
applyPreset(macroAlexaOff); applyPreset(macroAlexaOff, NOTIFIER_CALL_MODE_ALEXA);
if (bri != 0) espalexaDevice->setValue(0); //stop Alexa from complaining if macroAlexaOff does not actually turn off if (bri != 0) espalexaDevice->setValue(0); //stop Alexa from complaining if macroAlexaOff does not actually turn off
} }
} else if (m == EspalexaDeviceProperty::bri) } else if (m == EspalexaDeviceProperty::bri)

View File

@ -15,7 +15,7 @@ void shortPressAction(uint8_t b)
toggleOnOff(); toggleOnOff();
colorUpdated(NOTIFIER_CALL_MODE_BUTTON); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
} else { } else {
applyPreset(macroButton[b]); applyPreset(macroButton[b], NOTIFIER_CALL_MODE_BUTTON);
} }
// publish MQTT message // publish MQTT message
@ -62,12 +62,12 @@ void handleSwitch(uint8_t b)
if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce) if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
if (!buttonPressedBefore[b]) { // on -> off if (!buttonPressedBefore[b]) { // on -> off
if (macroButton[b]) applyPreset(macroButton[b]); if (macroButton[b]) applyPreset(macroButton[b], NOTIFIER_CALL_MODE_BUTTON);
else { //turn on else { //turn on
if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);} if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
} }
} else { // off -> on } else { // off -> on
if (macroLongPress[b]) applyPreset(macroLongPress[b]); if (macroLongPress[b]) applyPreset(macroLongPress[b], NOTIFIER_CALL_MODE_BUTTON);
else { //turn off else { //turn off
if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);} if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);}
} }
@ -195,7 +195,7 @@ void handleButton()
{ {
if (!buttonLongPressed[b]) if (!buttonLongPressed[b])
{ {
if (macroLongPress[b]) {applyPreset(macroLongPress[b]);} if (macroLongPress[b]) {applyPreset(macroLongPress[b], NOTIFIER_CALL_MODE_BUTTON);}
else _setRandomColor(false,true); else _setRandomColor(false,true);
// publish MQTT message // publish MQTT message
@ -224,7 +224,7 @@ void handleButton()
if (macroDoublePress[b]) if (macroDoublePress[b])
{ {
if (doublePress) { if (doublePress) {
applyPreset(macroDoublePress[b]); applyPreset(macroDoublePress[b], NOTIFIER_CALL_MODE_BUTTON);
// publish MQTT message // publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) { if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {

View File

@ -120,7 +120,7 @@ void handleIR();
#include "FX.h" #include "FX.h"
void deserializeSegment(JsonObject elem, byte it, byte presetId = 0); void deserializeSegment(JsonObject elem, byte it, byte presetId = 0);
bool deserializeState(JsonObject root, byte presetId = 0); bool deserializeState(JsonObject root, byte callMode = NOTIFIER_CALL_MODE_DIRECT_CHANGE, byte presetId = 0);
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true); void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true);
void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true); void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true);
void serializeInfo(JsonObject root); void serializeInfo(JsonObject root);
@ -181,7 +181,7 @@ void loadPlaylist(JsonObject playlistObject, byte presetId = 0);
void handlePlaylist(); void handlePlaylist();
//presets.cpp //presets.cpp
bool applyPreset(byte index); bool applyPreset(byte index, byte callMode = NOTIFIER_CALL_MODE_DIRECT_CHANGE);
void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject()); void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
void deletePreset(byte index); void deletePreset(byte index);

View File

@ -92,7 +92,7 @@ void onHueData(void* arg, AsyncClient* client, void *data, size_t len)
if (str == nullptr) return; if (str == nullptr) return;
str += 4; str += 4;
StaticJsonDocument<512> root; StaticJsonDocument<1024> root;
if (str[0] == '[') //is JSON array if (str[0] == '[') //is JSON array
{ {
auto error = deserializeJson(root, str); auto error = deserializeJson(root, str);

View File

@ -69,9 +69,9 @@ void decBrightness()
} }
// apply preset or fallback to a effect and palette if it doesn't exist // apply preset or fallback to a effect and palette if it doesn't exist
void presetFallback(int8_t presetID, int8_t effectID, int8_t paletteID) void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID)
{ {
if (!applyPreset(presetID)) { if (!applyPreset(presetID, NOTIFIER_CALL_MODE_BUTTON)) {
effectCurrent = effectID; effectCurrent = effectID;
effectPalette = paletteID; effectPalette = paletteID;
} }
@ -85,7 +85,7 @@ bool decodeIRCustom(uint32_t code)
{ {
//just examples, feel free to modify or remove //just examples, feel free to modify or remove
case IRCUSTOM_ONOFF : toggleOnOff(); break; case IRCUSTOM_ONOFF : toggleOnOff(); break;
case IRCUSTOM_MACRO1 : applyPreset(1); break; case IRCUSTOM_MACRO1 : applyPreset(1, NOTIFIER_CALL_MODE_BUTTON); break;
default: return false; default: return false;
} }
@ -257,11 +257,11 @@ void decodeIR24(uint32_t code)
case IR24_PURPLE : colorFromUint32(COLOR_PURPLE); break; case IR24_PURPLE : colorFromUint32(COLOR_PURPLE); break;
case IR24_MAGENTA : colorFromUint32(COLOR_MAGENTA); break; case IR24_MAGENTA : colorFromUint32(COLOR_MAGENTA); break;
case IR24_PINK : colorFromUint32(COLOR_PINK); break; case IR24_PINK : colorFromUint32(COLOR_PINK); break;
case IR24_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break; case IR24_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
case IR24_FLASH : if (!applyPreset(1)) effectCurrent = FX_MODE_COLORTWINKLE; break; case IR24_FLASH : presetFallback(1, FX_MODE_COLORTWINKLE, effectPalette); break;
case IR24_STROBE : if (!applyPreset(2)) effectCurrent = FX_MODE_RAINBOW_CYCLE; break; case IR24_STROBE : presetFallback(2, FX_MODE_RAINBOW_CYCLE, effectPalette); break;
case IR24_FADE : if (!applyPreset(3)) effectCurrent = FX_MODE_BREATH; break; case IR24_FADE : presetFallback(3, FX_MODE_BREATH, effectPalette); break;
case IR24_SMOOTH : if (!applyPreset(4)) effectCurrent = FX_MODE_RAINBOW; break; case IR24_SMOOTH : presetFallback(4, FX_MODE_RAINBOW, effectPalette); break;
default: return; default: return;
} }
lastValidCode = code; lastValidCode = code;
@ -289,11 +289,11 @@ void decodeIR24OLD(uint32_t code)
case IR24_OLD_PURPLE : colorFromUint32(COLOR_PURPLE); break; case IR24_OLD_PURPLE : colorFromUint32(COLOR_PURPLE); break;
case IR24_OLD_MAGENTA : colorFromUint32(COLOR_MAGENTA); break; case IR24_OLD_MAGENTA : colorFromUint32(COLOR_MAGENTA); break;
case IR24_OLD_PINK : colorFromUint32(COLOR_PINK); break; case IR24_OLD_PINK : colorFromUint32(COLOR_PINK); break;
case IR24_OLD_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break; case IR24_OLD_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
case IR24_OLD_FLASH : if (!applyPreset(1)) { effectCurrent = FX_MODE_COLORTWINKLE; effectPalette = 0; } break; case IR24_OLD_FLASH : presetFallback(1, FX_MODE_COLORTWINKLE, 0); break;
case IR24_OLD_STROBE : if (!applyPreset(2)) { effectCurrent = FX_MODE_RAINBOW_CYCLE; effectPalette = 0; } break; case IR24_OLD_STROBE : presetFallback(2, FX_MODE_RAINBOW_CYCLE, 0); break;
case IR24_OLD_FADE : if (!applyPreset(3)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break; case IR24_OLD_FADE : presetFallback(3, FX_MODE_BREATH, 0); break;
case IR24_OLD_SMOOTH : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break; case IR24_OLD_SMOOTH : presetFallback(4, FX_MODE_RAINBOW, 0); break;
default: return; default: return;
} }
lastValidCode = code; lastValidCode = code;
@ -382,10 +382,10 @@ void decodeIR40(uint32_t code)
case IR40_SLOW : changeEffectSpeed(-16); break; case IR40_SLOW : changeEffectSpeed(-16); break;
case IR40_JUMP7 : changeEffectIntensity( 16); break; case IR40_JUMP7 : changeEffectIntensity( 16); break;
case IR40_AUTO : changeEffectIntensity(-16); break; case IR40_AUTO : changeEffectIntensity(-16); break;
case IR40_JUMP3 : if (!applyPreset(1)) { effectCurrent = FX_MODE_STATIC; effectPalette = 0; } break; case IR40_JUMP3 : presetFallback(1, FX_MODE_STATIC, 0); break;
case IR40_FADE3 : if (!applyPreset(2)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break; case IR40_FADE3 : presetFallback(2, FX_MODE_BREATH, 0); break;
case IR40_FADE7 : if (!applyPreset(3)) { effectCurrent = FX_MODE_FIRE_FLICKER; effectPalette = 0; } break; case IR40_FADE7 : presetFallback(3, FX_MODE_FIRE_FLICKER, 0); break;
case IR40_FLASH : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break; case IR40_FLASH : presetFallback(4, FX_MODE_RAINBOW, 0); break;
} }
lastValidCode = code; lastValidCode = code;
} }
@ -437,12 +437,12 @@ void decodeIR44(uint32_t code)
case IR44_BLUEMINUS : changeEffectIntensity(-16); break; case IR44_BLUEMINUS : changeEffectIntensity(-16); break;
case IR44_QUICK : changeEffectSpeed( 16); break; case IR44_QUICK : changeEffectSpeed( 16); break;
case IR44_SLOW : changeEffectSpeed(-16); break; case IR44_SLOW : changeEffectSpeed(-16); break;
case IR44_DIY1 : if (!applyPreset(1)) { effectCurrent = FX_MODE_STATIC; effectPalette = 0; } break; case IR44_DIY1 : presetFallback(1, FX_MODE_STATIC, 0); break;
case IR44_DIY2 : if (!applyPreset(2)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break; case IR44_DIY2 : presetFallback(2, FX_MODE_BREATH, 0); break;
case IR44_DIY3 : if (!applyPreset(3)) { effectCurrent = FX_MODE_FIRE_FLICKER; effectPalette = 0; } break; case IR44_DIY3 : presetFallback(3, FX_MODE_FIRE_FLICKER, 0); break;
case IR44_DIY4 : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break; case IR44_DIY4 : presetFallback(4, FX_MODE_RAINBOW, 0); break;
case IR44_DIY5 : if (!applyPreset(5)) { effectCurrent = FX_MODE_METEOR_SMOOTH; effectPalette = 0; } break; case IR44_DIY5 : presetFallback(5, FX_MODE_METEOR_SMOOTH, 0); break;
case IR44_DIY6 : if (!applyPreset(6)) { effectCurrent = FX_MODE_RAIN; effectPalette = 0; } break; case IR44_DIY6 : presetFallback(6, FX_MODE_RAIN, 0); break;
case IR44_AUTO : effectCurrent = FX_MODE_STATIC; break; case IR44_AUTO : effectCurrent = FX_MODE_STATIC; break;
case IR44_FLASH : effectCurrent = FX_MODE_PALETTE; break; case IR44_FLASH : effectCurrent = FX_MODE_PALETTE; break;
case IR44_JUMP3 : bri = 63; break; case IR44_JUMP3 : bri = 63; break;
@ -473,10 +473,10 @@ void decodeIR21(uint32_t code)
case IR21_PURPLE: colorFromUint32(COLOR_PURPLE); break; case IR21_PURPLE: colorFromUint32(COLOR_PURPLE); break;
case IR21_PINK: colorFromUint32(COLOR_PINK); break; case IR21_PINK: colorFromUint32(COLOR_PINK); break;
case IR21_WHITE: colorFromUint32(COLOR_WHITE); effectCurrent = 0; break; case IR21_WHITE: colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
case IR21_FLASH: if (!applyPreset(1)) { effectCurrent = FX_MODE_COLORTWINKLE; effectPalette = 0; } break; case IR21_FLASH: presetFallback(1, FX_MODE_COLORTWINKLE, 0); break;
case IR21_STROBE: if (!applyPreset(2)) { effectCurrent = FX_MODE_RAINBOW_CYCLE; effectPalette = 0; } break; case IR21_STROBE: presetFallback(2, FX_MODE_RAINBOW_CYCLE, 0); break;
case IR21_FADE: if (!applyPreset(3)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break; case IR21_FADE: presetFallback(3, FX_MODE_BREATH, 0); break;
case IR21_SMOOTH: if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break; case IR21_SMOOTH: presetFallback(4, FX_MODE_RAINBOW, 0); break;
default: return; default: return;
} }
lastValidCode = code; lastValidCode = code;
@ -518,9 +518,9 @@ void decodeIR9(uint32_t code)
{ {
switch (code) { switch (code) {
case IR9_POWER : toggleOnOff(); break; case IR9_POWER : toggleOnOff(); break;
case IR9_A : if (!applyPreset(1)) effectCurrent = FX_MODE_COLORTWINKLE; break; case IR9_A : presetFallback(1, FX_MODE_COLORTWINKLE, effectPalette); break;
case IR9_B : if (!applyPreset(2)) effectCurrent = FX_MODE_RAINBOW_CYCLE; break; case IR9_B : presetFallback(2, FX_MODE_RAINBOW_CYCLE, effectPalette); break;
case IR9_C : if (!applyPreset(3)) effectCurrent = FX_MODE_BREATH; break; case IR9_C : presetFallback(3, FX_MODE_BREATH, effectPalette); break;
case IR9_UP : incBrightness(); break; case IR9_UP : incBrightness(); break;
case IR9_DOWN : decBrightness(); break; case IR9_DOWN : decBrightness(); break;
//case IR9_UP : changeEffectIntensity(16); break; //case IR9_UP : changeEffectIntensity(16); break;
@ -612,7 +612,7 @@ void decodeIRJson(uint32_t code)
// command is JSON object // command is JSON object
//allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem. //allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem.
fileDoc = &irDoc; fileDoc = &irDoc;
deserializeState(jsonCmdObj); deserializeState(jsonCmdObj, NOTIFIER_CALL_MODE_BUTTON);
fileDoc = nullptr; fileDoc = nullptr;
} }
} }

View File

@ -174,7 +174,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
return; // seg.hasChanged(prev); return; // seg.hasChanged(prev);
} }
bool deserializeState(JsonObject root, byte presetId) bool deserializeState(JsonObject root, byte callMode, byte presetId)
{ {
strip.applyToAllSelected = false; strip.applyToAllSelected = false;
bool stateResponse = root[F("v")] | false; bool stateResponse = root[F("v")] | false;
@ -294,7 +294,7 @@ bool deserializeState(JsonObject root, byte presetId)
ps = root["ps"] | -1; //load preset (clears state request!) ps = root["ps"] | -1; //load preset (clears state request!)
if (ps >= 0) { if (ps >= 0) {
if (!presetId) unloadPlaylist(); //stop playlist if preset changed manually if (!presetId) unloadPlaylist(); //stop playlist if preset changed manually
applyPreset(ps); applyPreset(ps, callMode);
return stateResponse; return stateResponse;
} }
@ -315,7 +315,7 @@ bool deserializeState(JsonObject root, byte presetId)
interfaceUpdateCallMode = NOTIFIER_CALL_MODE_WS_SEND; interfaceUpdateCallMode = NOTIFIER_CALL_MODE_WS_SEND;
} }
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE); colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : callMode);
return stateResponse; return stateResponse;
} }

View File

@ -93,7 +93,9 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
if (payload[0] == '{') { //JSON API if (payload[0] == '{') { //JSON API
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, payloadStr); deserializeJson(doc, payloadStr);
fileDoc = &doc;
deserializeState(doc.as<JsonObject>()); deserializeState(doc.as<JsonObject>());
fileDoc = nullptr;
} else { //HTTP API } else { //HTTP API
String apireq = "win&"; String apireq = "win&";
apireq += (char*)payloadStr; apireq += (char*)payloadStr;

View File

@ -4,7 +4,7 @@
* Methods to handle saving and loading presets to/from the filesystem * Methods to handle saving and loading presets to/from the filesystem
*/ */
bool applyPreset(byte index) bool applyPreset(byte index, byte callMode)
{ {
if (index == 0) return false; if (index == 0) return false;
if (fileDoc) { if (fileDoc) {
@ -14,7 +14,7 @@ bool applyPreset(byte index)
#ifdef WLED_DEBUG_FS #ifdef WLED_DEBUG_FS
serializeJson(*fileDoc, Serial); serializeJson(*fileDoc, Serial);
#endif #endif
deserializeState(fdo, index); deserializeState(fdo, callMode, index);
} else { } else {
DEBUGFS_PRINTLN(F("Make read buf")); DEBUGFS_PRINTLN(F("Make read buf"));
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE); DynamicJsonDocument fDoc(JSON_BUFFER_SIZE);
@ -24,7 +24,7 @@ bool applyPreset(byte index)
#ifdef WLED_DEBUG_FS #ifdef WLED_DEBUG_FS
serializeJson(fDoc, Serial); serializeJson(fDoc, Serial);
#endif #endif
deserializeState(fdo, index); deserializeState(fdo, callMode, index);
} }
if (!errorFlag) { if (!errorFlag) {

View File

@ -387,7 +387,7 @@ void WLED::beginStrip()
strip.setShowCallback(handleOverlayDraw); strip.setShowCallback(handleOverlayDraw);
if (bootPreset > 0) { if (bootPreset > 0) {
applyPreset(bootPreset); applyPreset(bootPreset, NOTIFIER_CALL_MODE_INIT);
} else if (turnOnAtBoot) { } else if (turnOnAtBoot) {
if (briS > 0) bri = briS; if (briS > 0) bri = briS;
else if (bri == 0) bri = 128; else if (bri == 0) bri = 128;

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2107090 #define VERSION 2107091
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG