diff --git a/usermods/Animated_Staircase/Animated_Staircase.h b/usermods/Animated_Staircase/Animated_Staircase.h index 6d02dce7a2..49b081d0c7 100644 --- a/usermods/Animated_Staircase/Animated_Staircase.h +++ b/usermods/Animated_Staircase/Animated_Staircase.h @@ -297,7 +297,7 @@ 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; + transitionDelay = segment_delay_ms; strip.setTransition(segment_delay_ms/100); strip.trigger(); } else { diff --git a/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h b/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h index 238ec7d9ca..e4876073f4 100644 --- a/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h +++ b/usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h @@ -91,7 +91,7 @@ class StairwayWipeUsermod : public Usermod { void startWipe() { bri = briLast; //turn on - transitionDelayTemp = 0; //no transition + strip.setTransition(0); //no transition effectCurrent = FX_MODE_COLOR_WIPE; resetTimebase(); //make sure wipe starts from beginning @@ -106,9 +106,9 @@ class StairwayWipeUsermod : public Usermod { void turnOff() { #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/FX.h b/wled00/FX.h index 00dddf8c26..8cd6641113 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -779,6 +779,7 @@ class WS2812FX { // 96 bytes inline void appendSegment(const Segment &seg = Segment()) { if (_segments.size() < getMaxSegments()) _segments.push_back(seg); } bool + paletteFade, checkSegmentAlignment(void), hasRGBWBus(void), hasCCTBus(void), @@ -791,7 +792,6 @@ class WS2812FX { // 96 bytes inline bool isOffRefreshRequired(void) {return _isOffRefreshRequired;} uint8_t - paletteFade, paletteBlend, milliampsPerLed, cctBlending, diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 1c57afeff2..e36b2f61d8 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -377,6 +377,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 d3b1ca250c..a91404cb2c 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -240,8 +240,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 @@ -323,23 +324,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(); @@ -375,8 +371,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 37e77d1edc..3d1f11a510 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -134,11 +134,11 @@ 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 + // restore (global) transition time if not called from UDP notifier or single/temporary transition from JSON (also playlist) + if (!(callMode == CALL_MODE_NOTIFICATION || jsonTransitionOnce)) strip.setTransition(transitionDelay); jsonTransitionOnce = false; - strip.setTransition(transitionDelayTemp); - if (transitionDelayTemp == 0) { + if (strip.getTransition() == 0) { + transitionActive = false; applyFinalBri(); strip.trigger(); return; @@ -152,7 +152,6 @@ void stateUpdated(byte callMode) { transitionActive = true; transitionStartTime = millis(); } else { - strip.setTransition(0); applyFinalBri(); strip.trigger(); } @@ -187,12 +186,10 @@ 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 transitionActive = false; tperLast = 0; applyFinalBri(); diff --git a/wled00/playlist.cpp b/wled00/playlist.cpp index 8a6227e1df..bcbcb4516f 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 0c9863af1c..a12ecd30b9 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -1089,6 +1089,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 181400bd0e..a6c0689603 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -211,6 +211,11 @@ void parseNotifyPacket(uint8_t *udpIn) { bool someSel = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects); + // set transition time before making any segment changes + if (version > 3) { + if (fadeTransition) 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) @@ -365,10 +370,6 @@ void parseNotifyPacket(uint8_t *udpIn) { } } - 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 346f0ef154..f246083eb5 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -354,9 +354,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) @@ -534,13 +531,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);