From f66b343edde1df1b64d6c82b8d4c156b1767498b Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Tue, 28 Nov 2023 10:42:18 +0100 Subject: [PATCH] Possible fix for #3541 --- .../Animated_Staircase/Animated_Staircase.h | 4 ++-- .../stairway-wipe-usermod-v2.h | 8 ++++--- wled00/cfg.cpp | 1 + wled00/json.cpp | 20 +++++++--------- wled00/led.cpp | 24 ++++++++----------- wled00/playlist.cpp | 2 +- wled00/set.cpp | 1 + wled00/udp.cpp | 13 ++++++---- wled00/wled.h | 17 +++++++------ 9 files changed, 44 insertions(+), 46 deletions(-) diff --git a/usermods/Animated_Staircase/Animated_Staircase.h b/usermods/Animated_Staircase/Animated_Staircase.h index 6d02dce7a..147497211 100644 --- a/usermods/Animated_Staircase/Animated_Staircase.h +++ b/usermods/Animated_Staircase/Animated_Staircase.h @@ -297,8 +297,8 @@ class Animated_Staircase : public Usermod { offIndex = maxSegmentId = strip.getLastActiveSegmentId() + 1; // shorten the strip transition time to be equal or shorter than segment delay - transitionDelayTemp = transitionDelay = segment_delay_ms; - strip.setTransition(segment_delay_ms/100); + transitionDelay = segment_delay_ms; + strip.setTransition(segment_delay_ms); strip.trigger(); } else { if (togglePower && !on && offMode) toggleOnOff(); // toggle power on if off diff --git a/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h b/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h index 238ec7d9c..9cc0bea4c 100644 --- a/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h +++ b/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h @@ -91,7 +91,8 @@ class StairwayWipeUsermod : public Usermod { void startWipe() { bri = briLast; //turn on - transitionDelayTemp = 0; //no transition + jsonTransitionOnce = true; + strip.setTransition(0); //no transition effectCurrent = FX_MODE_COLOR_WIPE; resetTimebase(); //make sure wipe starts from beginning @@ -105,10 +106,11 @@ class StairwayWipeUsermod : public Usermod { void turnOff() { + jsonTransitionOnce = true; #ifdef STAIRCASE_WIPE_OFF - transitionDelayTemp = 0; //turn off immediately after wipe completed + strip.setTransition(0); //turn off immediately after wipe completed #else - transitionDelayTemp = 4000; //fade out slowly + strip.setTransition(4000); //fade out slowly #endif bri = 0; stateUpdated(CALL_MODE_NOTIFICATION); diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 5c00b0a55..04a2fa475 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -362,6 +362,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(modeBlending, light_tr["fx"]); int tdd = light_tr["dur"] | -1; if (tdd >= 0) transitionDelay = transitionDelayDefault = tdd * 100; + strip.setTransition(fadeTransition ? transitionDelayDefault : 0); CJSON(strip.paletteFade, light_tr["pal"]); CJSON(randomPaletteChangeTime, light_tr[F("rpc")]); diff --git a/wled00/json.cpp b/wled00/json.cpp index 6a28a19dd..dbf76cb1d 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -244,8 +244,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId) seg.map1D2D = M12_Pixels; // no mapping // set brightness immediately and disable transition - transitionDelayTemp = 0; jsonTransitionOnce = true; + seg.stopTransition(); + strip.setTransition(0); strip.setBrightness(scaledBri(bri), true); // freeze and init to black @@ -327,23 +328,18 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) int tr = -1; if (!presetId || currentPlaylist < 0) { //do not apply transition time from preset if playlist active, as it would override playlist transition times tr = root[F("transition")] | -1; - if (tr >= 0) - { - transitionDelay = tr; - transitionDelay *= 100; - transitionDelayTemp = transitionDelay; + if (tr >= 0) { + transitionDelay = tr * 100; + if (fadeTransition) strip.setTransition(transitionDelay); } } // temporary transition (applies only once) tr = root[F("tt")] | -1; - if (tr >= 0) - { - transitionDelayTemp = tr; - transitionDelayTemp *= 100; + if (tr >= 0) { jsonTransitionOnce = true; + if (fadeTransition) strip.setTransition(tr * 100); } - strip.setTransition(transitionDelayTemp); // required here for color transitions to have correct duration tr = root[F("tb")] | -1; if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis(); @@ -380,8 +376,8 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) if (root.containsKey("live")) { if (root["live"].as()) { - transitionDelayTemp = 0; jsonTransitionOnce = true; + strip.setTransition(0); realtimeLock(65000); } else { exitRealtime(); diff --git a/wled00/led.cpp b/wled00/led.cpp index f3fe2d0be..e668f3340 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -134,13 +134,9 @@ void stateUpdated(byte callMode) { usermods.onStateChange(callMode); if (fadeTransition) { - //set correct delay if not using notification delay - if (callMode != CALL_MODE_NOTIFICATION && !jsonTransitionOnce) transitionDelayTemp = transitionDelay; // load actual transition duration - jsonTransitionOnce = false; - strip.setTransition(transitionDelayTemp); - if (transitionDelayTemp == 0) { - applyFinalBri(); - strip.trigger(); + if (strip.getTransition() == 0) { + jsonTransitionOnce = false; + transitionActive = false; return; } @@ -152,7 +148,6 @@ void stateUpdated(byte callMode) { transitionActive = true; transitionStartTime = millis(); } else { - strip.setTransition(0); applyFinalBri(); strip.trigger(); } @@ -187,13 +182,14 @@ void handleTransitions() if (doPublishMqtt) publishMqtt(); #endif - if (transitionActive && transitionDelayTemp > 0) - { - float tper = (millis() - transitionStartTime)/(float)transitionDelayTemp; - if (tper >= 1.0f) - { - strip.setTransitionMode(false); + if (transitionActive && strip.getTransition() > 0) { + float tper = (millis() - transitionStartTime)/(float)strip.getTransition(); + if (tper >= 1.0f) { + strip.setTransitionMode(false); // stop all transitions + // restore (global) transition time if not called from UDP notifier or single/temporary transition from JSON (also playlist) + if (jsonTransitionOnce) strip.setTransition(transitionDelay); transitionActive = false; + jsonTransitionOnce = false; tperLast = 0; applyFinalBri(); return; diff --git a/wled00/playlist.cpp b/wled00/playlist.cpp index 8a6227e1d..bcbcb4516 100644 --- a/wled00/playlist.cpp +++ b/wled00/playlist.cpp @@ -144,7 +144,7 @@ void handlePlaylist() { } jsonTransitionOnce = true; - transitionDelayTemp = playlistEntries[playlistIndex].tr * 100; + strip.setTransition(fadeTransition ? playlistEntries[playlistIndex].tr * 100 : 0); playlistEntryDur = playlistEntries[playlistIndex].dur; applyPreset(playlistEntries[playlistIndex].preset); } diff --git a/wled00/set.cpp b/wled00/set.cpp index efc0813c0..db1b6085a 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -1063,6 +1063,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply) pos = req.indexOf(F("TT=")); if (pos > 0) transitionDelay = getNumVal(&req, pos); + if (fadeTransition) strip.setTransition(transitionDelay); //set time (unix timestamp) pos = req.indexOf(F("ST=")); diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 585ab8b0a..ff623faec 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -323,6 +323,14 @@ void handleNotifications() bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); + // set transition time before making any segment changes + if (version > 3) { + if (fadeTransition) { + jsonTransitionOnce = true; + strip.setTransition(((udpIn[17] << 0) & 0xFF) + ((udpIn[18] << 8) & 0xFF00)); + } + } + //apply colors from notification to main segment, only if not syncing full segments if ((receiveNotificationColor || !someSel) && (version < 11 || !receiveSegmentOptions)) { // primary color, only apply white if intented (version > 0) @@ -451,11 +459,6 @@ void handleNotifications() } } - if (version > 3) - { - transitionDelayTemp = ((udpIn[17] << 0) & 0xFF) + ((udpIn[18] << 8) & 0xFF00); - } - nightlightActive = udpIn[6]; if (nightlightActive) nightlightDelayMins = udpIn[7]; diff --git a/wled00/wled.h b/wled00/wled.h index 2572c73fc..34d853feb 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2311160 +#define VERSION 2311280 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG @@ -350,9 +350,6 @@ WLED_GLOBAL byte briS _INIT(128); // default brightness WLED_GLOBAL byte nightlightTargetBri _INIT(0); // brightness after nightlight is over WLED_GLOBAL byte nightlightDelayMins _INIT(60); WLED_GLOBAL byte nightlightMode _INIT(NL_MODE_FADE); // See const.h for available modes. Was nightlightFade -WLED_GLOBAL bool fadeTransition _INIT(true); // enable crossfading color transition -WLED_GLOBAL bool modeBlending _INIT(true); // enable effect blending -WLED_GLOBAL uint16_t transitionDelay _INIT(750); // default crossfade duration in ms WLED_GLOBAL byte briMultiplier _INIT(100); // % of brightness to set (to limit power, if you set it to 50 and set bri to 255, actual brightness will be 127) @@ -528,13 +525,15 @@ WLED_GLOBAL bool wasConnected _INIT(false); WLED_GLOBAL byte lastRandomIndex _INIT(0); // used to save last random color so the new one is not the same // transitions +WLED_GLOBAL bool fadeTransition _INIT(true); // enable crossfading brightness/color +WLED_GLOBAL bool modeBlending _INIT(true); // enable effect blending WLED_GLOBAL bool transitionActive _INIT(false); -WLED_GLOBAL uint16_t transitionDelayDefault _INIT(transitionDelay); // default transition time (storec in cfg.json) -WLED_GLOBAL uint16_t transitionDelayTemp _INIT(transitionDelay); // actual transition duration (overrides transitionDelay in certain cases) +WLED_GLOBAL uint16_t transitionDelay _INIT(750); // global transition duration +WLED_GLOBAL uint16_t transitionDelayDefault _INIT(750); // default transition time (stored in cfg.json) WLED_GLOBAL unsigned long transitionStartTime; -WLED_GLOBAL float tperLast _INIT(0.0f); // crossfade transition progress, 0.0f - 1.0f -WLED_GLOBAL bool jsonTransitionOnce _INIT(false); // flag to override transitionDelay (playlist, JSON API: "live" & "seg":{"i"} & "tt") -WLED_GLOBAL uint8_t randomPaletteChangeTime _INIT(5); // amount of time [s] between random palette changes (min: 1s, max: 255s) +WLED_GLOBAL float tperLast _INIT(0.0f); // crossfade transition progress, 0.0f - 1.0f +WLED_GLOBAL bool jsonTransitionOnce _INIT(false); // flag to override transitionDelay (playlist, JSON API: "live" & "seg":{"i"} & "tt") +WLED_GLOBAL uint8_t randomPaletteChangeTime _INIT(5); // amount of time [s] between random palette changes (min: 1s, max: 255s) // nightlight WLED_GLOBAL bool nightlightActive _INIT(false);