Effect change at end of transition.

Compile bugfix.
This commit is contained in:
Blaz Kristan 2022-08-03 22:09:27 +02:00
parent d0a08a55d1
commit cdca715afc
4 changed files with 23 additions and 13 deletions

View File

@ -7272,7 +7272,7 @@ static const char _data_FX_MODE_2DFUNKYPLANK[] PROGMEM = "Funky Plank@Scroll spe
/////////////////////////
// 2D Akemi //
/////////////////////////
static uint8_t akemi[][] PROGMEM = {
static uint8_t akemi[] PROGMEM = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,2,2,3,3,3,3,3,3,2,2,0,0,0,0,0,0,0,0,0,0,0,

View File

@ -454,11 +454,11 @@ typedef struct Segment {
uint8_t _briT; // temporary brightness
uint8_t _cctT; // temporary CCT
CRGBPalette16 _palT; // temporary palette
//uint8_t _modeP; // previous mode/effect (transitioning effects is way more complex than this)
uint8_t _modeP; // previous mode/effect
uint32_t _start;
uint16_t _dur;
Transition(uint16_t dur=750) : _briT(255), _cctT(127), _palT(CRGBPalette16(CRGB::Black)), /*_modeP(FX_MODE_STATIC),*/ _start(millis()), _dur(dur) {}
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o) : _briT(b), _cctT(c), _palT(CRGBPalette16(CRGB::Black)), /*_modeP(FX_MODE_STATIC),*/ _start(millis()), _dur(d) {
Transition(uint16_t dur=750) : _briT(255), _cctT(127), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(dur) {}
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o) : _briT(b), _cctT(c), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(d) {
for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = o[i];
}
} *_t; // this struct will bootloop ESP
@ -567,6 +567,7 @@ typedef struct Segment {
void handleTransition(void);
uint16_t progress(void); //transition progression between 0-65535
uint8_t currentBri(uint8_t briNew, bool useCct = false);
uint8_t currentMode(uint8_t modeNew);
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
CRGBPalette16 &currentPalette(CRGBPalette16 &tgt, uint8_t paletteID);

View File

@ -203,17 +203,17 @@ void Segment::startTransition(uint16_t dur) {
uint8_t _briT = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); // comment out uint8_t if not using Transition struct
uint8_t _cctT = currentBri(cct, true); // comment out uint8_t if not using Transition struct
CRGBPalette16 _palT; loadPalette(_palT, palette);
///*uint8_t*/ _modeP = mode; // comment out uint8_t if not using Transition struct
uint8_t _modeP = mode; // comment out uint8_t if not using Transition struct
uint32_t _colorT[NUM_COLORS]; // comment out if not using Transition struct
for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = currentColor(i, colors[i]);
// using transition struct
if (!_t) _t = new Transition(dur); // no previous transition running
if (!_t) return; // failed to allocat data
if (!_t) return; // failed to allocate data
_t->_briT = _briT;
_t->_cctT = _cctT;
_t->_palT = _palT;
//_t->_modeT = _modeP;
_t->_modeP = _modeP;
for (size_t i=0; i<NUM_COLORS; i++) _t->_colorT[i] = _colorT[i];
// comment out if using transition struct as it is done in constructor
//_dur = dur;
@ -240,6 +240,14 @@ uint8_t Segment::currentBri(uint8_t briNew, bool useCct) {
}
}
uint8_t Segment::currentMode(uint8_t newMode) {
if (transitional && _t) {
return _t->_modeP;
} else {
return newMode;
}
}
uint32_t Segment::currentColor(uint8_t slot, uint32_t colorNew) {
return transitional && _t ? color_blend(_t->_colorT[slot], colorNew, progress(), true) : colorNew;
}
@ -340,6 +348,7 @@ void Segment::handleTransition() {
if (mode == FX_MODE_STATIC && next_time > maxWait) next_time = maxWait;
if (progress() == 0xFFFFU) {
if (_t) {
if (_t->_modeP != mode) markForReset();
delete _t;
_t = nullptr;
}
@ -884,14 +893,14 @@ void WS2812FX::service() {
if (!cctFromRgb || correctWB) busses.setSegmentCCT(seg.currentBri(seg.cct, true), correctWB);
for (uint8_t c = 0; c < NUM_COLORS; c++) _colors_t[c] = gamma32(_colors_t[c]);
seg.handleTransition();
// effect blending (execute previous effect)
// actual code may be a bit more involved as effects have runtime data including allocated memory
//if (getOption(SEG_OPTION_TRANSITIONAL) && seg._modeP) (*_mode[seg._modeP])(progress());
delay = (*_mode[seg.mode])();
delay = (*_mode[seg.currentMode(seg.mode)])();
if (seg.mode != FX_MODE_HALLOWEEN_EYES) seg.call++;
if (seg.transitional && delay > FRAMETIME) delay = FRAMETIME; // foce faster updates during transition
seg.handleTransition();
}
seg.next_time = nowUp + delay;
@ -1457,7 +1466,7 @@ void WS2812FX::printSize()
{
size_t size = 0;
for (Segment seg : _segments) size += seg.getSize();
DEBUG_PRINTF("Segments: %d -> %uB\n", sizeof(Segment), _segments.size(), size);
DEBUG_PRINTF("Segments: %d -> %uB\n", _segments.size(), size);
DEBUG_PRINTF("Modes: %d*%d=%uB\n", sizeof(mode_ptr), _mode.size(), (_mode.capacity()*sizeof(mode_ptr)));
DEBUG_PRINTF("Data: %d*%d=%uB\n", sizeof(const char *), _modeData.size(), (_modeData.capacity()*sizeof(const char *)));
DEBUG_PRINTF("Map: %d*%d=%uB\n", sizeof(uint16_t), (int)customMappingSize, customMappingSize*sizeof(uint16_t));

View File

@ -175,8 +175,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if (getVal(elem["fx"], &fx, 0, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 0-255 exact value)
if (!presetId && currentPlaylist>=0) unloadPlaylist();
if (fx != seg.mode) {
//seg.startTransition(strip.getTransition()); // set effect transitions
seg.markForReset();
seg.startTransition(strip.getTransition()); // set effect transitions
//seg.markForReset();
seg.mode = fx;
// load default values from effect string if effect is selected without
// any other effect parameter (i.e. effect clicked in UI)