Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,29 @@ void Segment::startTransition(uint16_t dur, bool segmentCopy) {
}
if (isInTransition()) {
if (segmentCopy && !_t->_oldSegment) {
// already in transition but segment copy requested and not yet created
_t->_oldSegment = new(std::nothrow) Segment(*this); // store/copy current segment settings
_t->_start = millis(); // restart countdown
_t->_dur = dur;
_t->_prevPaletteBlends = 0;
if (_t->_oldSegment) {
_t->_oldSegment->palette = _t->_palette; // restore original palette and colors (from start of transition)
for (unsigned i = 0; i < NUM_COLORS; i++) _t->_oldSegment->colors[i] = _t->_colors[i];
DEBUGFX_PRINTF_P(PSTR("-- Updated transition with segment copy: S=%p T(%p) O[%p] OP[%p]\n"), this, _t, _t->_oldSegment, _t->_oldSegment->pixels);
if (!_t->_oldSegment->isActive()) stopTransition();
if (blendingStyle != TRANSITION_FADE) {
// transition without a copy means we are in a segment brightness transition
// need to cancel the transition to not interfere with the next one (or global brightness change)
stopTransition();
} else {
// already in FADE transition but segment copy requested and not yet created (for example color change during brightness transition)
// create segment copy and restart timer so currentBri() can interpolate correctly
_t->_oldSegment = new(std::nothrow) Segment(*this); // store/copy current segment settings
_t->_start = millis(); // restart countdown
_t->_dur = dur;
_t->_prevPaletteBlends = 0;
if (_t->_oldSegment) {
_t->_oldSegment->palette = _t->_palette; // restore original palette and colors (from start of transition)
for (unsigned i = 0; i < NUM_COLORS; i++) _t->_oldSegment->colors[i] = _t->_colors[i];
DEBUGFX_PRINTF_P(PSTR("-- Updated transition with segment copy: S=%p T(%p) O[%p] OP[%p]\n"), this, _t, _t->_oldSegment, _t->_oldSegment->pixels);
if (!_t->_oldSegment->isActive()) stopTransition();
}
return;
}
} else {
// already in transition and no segment copy requested, just continue
return;
}
Comment thread
DedeHai marked this conversation as resolved.
return;
}

// no previous transition running, start by allocating memory for segment copy
Expand Down Expand Up @@ -354,9 +364,11 @@ uint8_t Segment::currentBri() const {
unsigned prog = progress();
unsigned curBri = on ? opacity : 0;
if (prog < 0xFFFFU) {
// this will blend opacity in new mode if style is FADE (single effect call)
if (blendingStyle == TRANSITION_FADE) curBri = (prog * curBri + _t->_bri * (0xFFFFU - prog)) / 0xFFFFU;
else curBri = Segment::isPreviousMode() ? _t->_bri : curBri;
// this will blend opacity in new mode if style is FADE (single effect call)
if (blendingStyle == TRANSITION_FADE || !_t->_oldSegment)
curBri = (prog * curBri + _t->_bri * (0xFFFFU - prog)) / 0xFFFFU;
else
curBri = std::max((unsigned)curBri, (unsigned)_t->_bri); // non-FADE on/off transition: use the higher of old and new brightness so it is correct for both turn-on and turn-off
Comment thread
DedeHai marked this conversation as resolved.
Outdated
}
return curBri;
}
Expand Down Expand Up @@ -530,7 +542,7 @@ Segment &Segment::setCCT(uint16_t k) {
Segment &Segment::setOpacity(uint8_t o) {
if (opacity != o) {
//DEBUG_PRINTF_P(PSTR("- Starting opacity transition: %d\n"), o);
startTransition(strip.getTransition(), blendingStyle != TRANSITION_FADE); // start transition prior to change
startTransition(strip.getTransition(), false); // opacity change always fades (no segment copy needed)
opacity = o;
stateChanged = true; // send UDP/WS broadcast
}
Expand Down Expand Up @@ -1588,10 +1600,12 @@ void WS2812FX::blendSegment(const Segment &topSegment) const {
c_a = color_blend16(c_a, segO->getPixelColorRaw(x + y*oCols), progInv);
} else if (blendingStyle != TRANSITION_FADE) {
// if we have global brightness change (not On/Off change) we will ignore transition style and just fade brightness (see led.cpp)
// workaround for On/Off transition
// workaround for global On/Off transition
// (bri != briT) && !bri => from On to Off
// (bri != briT) && bri => from Off to On
if ((briOld == 0 || bri == 0) && ((!clipped && (bri != briT) && !bri) || (clipped && (bri != briT) && bri))) c_a = BLACK;
// per-segment on/off: the area belonging to the off-state segment must be black
if (segO && !seg->on) c_a = BLACK;
}
// map it into frame buffer
x = c; // restore coordiates if we were PUSHing
Expand Down Expand Up @@ -1660,10 +1674,12 @@ void WS2812FX::blendSegment(const Segment &topSegment) const {
c_a = color_blend16(c_a, segO->getPixelColorRaw(i), progInv);
} else if (blendingStyle != TRANSITION_FADE) {
// if we have global brightness change (not On/Off change) we will ignore transition style and just fade brightness (see led.cpp)
// workaround for On/Off transition
// workaround for global On/Off transition
// (bri != briT) && !bri => from On to Off
// (bri != briT) && bri => from Off to On
if ((briOld == 0 || bri == 0) && ((!clipped && (bri != briT) && !bri) || (clipped && (bri != briT) && bri))) c_a = BLACK;
// per-segment on/off: the area belonging to the off-state segment must be black
if (segO && !seg->on) c_a = BLACK;
}
// map into frame buffer
i = k; // restore index if we were PUSHing
Expand Down
14 changes: 12 additions & 2 deletions wled00/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,20 @@ void stateUpdated(byte callMode) {
} else {
if (transitionActive) {
briOld = briT;
} else if (bri != briOld || stateChanged)
/* } else if (bri != briOld || stateChanged)
strip.setTransitionMode(true); // force all segments to transition mode
transitionActive = true;
transitionStartTime = now;
transitionStartTime = now;*/

} else if (bri != briOld)
strip.setTransitionMode(true); // force all segments to transition mode on global brightness change
if (bri != briOld) {
transitionActive = true; // global brightness changed, (re)start global transition
transitionStartTime = now;
} else if (jsonTransitionOnce) {
strip.setTransition(transitionDelay);
jsonTransitionOnce = false;
}
Comment thread
DedeHai marked this conversation as resolved.
Outdated
}
stateChanged = false;
}
Expand Down
Loading