Bugfix for palette transitions.

This commit is contained in:
Blaz Kristan 2022-07-29 16:26:15 +02:00
parent 191db46c4f
commit 79337a4568
4 changed files with 21 additions and 10 deletions

View File

@ -230,7 +230,7 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
static unsigned long _lastPaletteChange = 0; // perhaps it should be per segment static unsigned long _lastPaletteChange = 0; // perhaps it should be per segment
byte tcp[72]; byte tcp[72];
if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0;
if (pal > 245 && (strip.customPalettes.size() == 0 || 255-pal > strip.customPalettes.size()-1)) pal = 0; if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0;
//default palette. Differs depending on effect //default palette. Differs depending on effect
if (pal == 0) switch (mode) { if (pal == 0) switch (mode) {
case FX_MODE_FIRE_2012 : pal = 35; break; // heat palette case FX_MODE_FIRE_2012 : pal = 35; break; // heat palette
@ -307,9 +307,9 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
CRGBPalette16 &Segment::currentPalette(CRGBPalette16 &targetPalette, uint8_t pal) { CRGBPalette16 &Segment::currentPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
loadPalette(targetPalette, pal); loadPalette(targetPalette, pal);
//if (_t && progress() < 0xFFFFU) { //if (_t && progress() < 0xFFFFU) {
if (paletteFade && getOption(SEG_OPTION_TRANSITIONAL) && progress() < 0xFFFFU) { if (strip.paletteFade && getOption(SEG_OPTION_TRANSITIONAL) && progress() < 0xFFFFU) { // TODO: get rid of
// blend palettes // blend palettes
uint8_t blends = map(_dur, 0, 0xFFFF, 48, 1); // do not blend palettes too quickly (0-65.5s) uint8_t blends = map(_dur, 0, 0xFFFF, 48, 6); // do not blend palettes too quickly (0-65.5s)
nblendPaletteTowardPalette(/*_t->*/_palT, targetPalette, blends); nblendPaletteTowardPalette(/*_t->*/_palT, targetPalette, blends);
targetPalette = /*_t->*/_palT; // copy transitioning/temporary palette targetPalette = /*_t->*/_palT; // copy transitioning/temporary palette
} }
@ -748,7 +748,9 @@ uint32_t IRAM_ATTR Segment::color_from_palette(uint16_t i, bool mapping, bool wr
if (mapping && virtualLength() > 1) paletteIndex = (i*255)/(virtualLength() -1); if (mapping && virtualLength() > 1) paletteIndex = (i*255)/(virtualLength() -1);
if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end" if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end"
CRGB fastled_col; CRGB fastled_col;
CRGBPalette16 curPal = loadPalette(palette); CRGBPalette16 curPal;
if (transitional) curPal = /*_t->*/_palT;
else loadPalette(curPal, palette);
fastled_col = ColorFromPalette(curPal, paletteIndex, pbri, (strip.paletteBlend == 3)? NOBLEND:LINEARBLEND); // NOTE: paletteBlend should be global fastled_col = ColorFromPalette(curPal, paletteIndex, pbri, (strip.paletteBlend == 3)? NOBLEND:LINEARBLEND); // NOTE: paletteBlend should be global
return RGBW32(fastled_col.r, fastled_col.g, fastled_col.b, 0); return RGBW32(fastled_col.r, fastled_col.g, fastled_col.b, 0);
@ -1460,10 +1462,10 @@ void WS2812FX::setRange(uint16_t i, uint16_t i2, uint32_t col)
void WS2812FX::setTransitionMode(bool t) void WS2812FX::setTransitionMode(bool t)
{ {
for (segment &seg : _segments) seg.startTransition(t ? _transitionDur : 0); for (segment &seg : _segments) if (!seg.transitional) seg.startTransition(t ? _transitionDur : 0);
// for (uint8_t i = 0; i < getMaxSegments(); i++) { // for (uint8_t i = 0; i < getMaxSegments(); i++) {
// Segment &seg = getSegment(i); // Segment &seg = getSegment(i);
// seg.startTransition(t ? _transitionDur : 0); // if (!seg.transitional)seg.startTransition(t ? _transitionDur : 0);
// } // }
} }

View File

@ -222,7 +222,13 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
//getVal also supports inc/decrementing and random //getVal also supports inc/decrementing and random
getVal(elem[F("sx")], &seg.speed); getVal(elem[F("sx")], &seg.speed);
getVal(elem[F("ix")], &seg.intensity); getVal(elem[F("ix")], &seg.intensity);
getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount()); uint8_t pal = seg.palette;
if (getVal(elem["pal"], &pal, 1, strip.getPaletteCount())) {
if (pal != seg.palette) {
if (strip.paletteBlend) seg.startTransition(strip.getTransition());
seg.palette = pal;
}
}
getVal(elem[F("c1")], &seg.custom1); getVal(elem[F("c1")], &seg.custom1);
getVal(elem[F("c2")], &seg.custom2); getVal(elem[F("c2")], &seg.custom2);
getVal(elem[F("c3")], &seg.custom3); getVal(elem[F("c3")], &seg.custom3);

View File

@ -826,10 +826,13 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (i != selectedSeg && (singleSegment || !seg.isActive() || !seg.isSelected())) continue; // skip non main segments if not applying to all if (i != selectedSeg && (singleSegment || !seg.isActive() || !seg.isSelected())) continue; // skip non main segments if not applying to all
if (fxModeChanged) strip.setMode(i, effectIn); if (fxModeChanged) { seg.mode = effectIn; seg.markForReset(); }
if (speedChanged) seg.speed = speedIn; if (speedChanged) seg.speed = speedIn;
if (intensityChanged) seg.intensity = intensityIn; if (intensityChanged) seg.intensity = intensityIn;
if (paletteChanged) seg.palette = paletteIn; if (paletteChanged) {
if (strip.paletteBlend) seg.startTransition(strip.getTransition());
seg.palette = paletteIn;
}
} }
//set advanced overlay //set advanced overlay

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2207291 #define VERSION 2207292
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG