Possible fix for #3541
This commit is contained in:
		| @@ -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, | ||||
|   | ||||
| @@ -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")]); | ||||
|  | ||||
|   | ||||
| @@ -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<bool>()) { | ||||
|       transitionDelayTemp = 0; | ||||
|       jsonTransitionOnce = true; | ||||
|       strip.setTransition(0); | ||||
|       realtimeLock(65000); | ||||
|     } else { | ||||
|       exitRealtime(); | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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); | ||||
|   } | ||||
|   | ||||
| @@ -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=")); | ||||
|   | ||||
| @@ -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]; | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Blaz Kristan
					Blaz Kristan