Skip to content

Commit

Permalink
Possible fix for #3541
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Nov 27, 2023
1 parent 0227f79 commit 426ac29
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion usermods/Animated_Staircase/Animated_Staircase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -791,7 +792,6 @@ class WS2812FX { // 96 bytes
inline bool isOffRefreshRequired(void) {return _isOffRefreshRequired;}

uint8_t
paletteFade,
paletteBlend,
milliampsPerLed,
cctBlending,
Expand Down
1 change: 1 addition & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")]);

Expand Down
20 changes: 8 additions & 12 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 8 additions & 11 deletions wled00/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -152,7 +152,6 @@ void stateUpdated(byte callMode) {
transitionActive = true;
transitionStartTime = millis();
} else {
strip.setTransition(0);
applyFinalBri();
strip.trigger();
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion wled00/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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="));
Expand Down
9 changes: 5 additions & 4 deletions wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];

Expand Down
15 changes: 7 additions & 8 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 426ac29

Please sign in to comment.