Skip to content

Commit 23a51e0

Browse files
authored
Merge pull request #4658 from wled/layers
Segment layers and better effect transitions (blending)
2 parents 4a3af81 + 125a21d commit 23a51e0

39 files changed

+2758
-2950
lines changed

usermods/Analog_Clock/Analog_Clock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class AnalogClockUsermod : public Usermod {
102102
void secondsEffectSineFade(int16_t secondLed, Toki::Time const& time) {
103103
uint32_t ms = time.ms % 1000;
104104
uint8_t b0 = (cos8_t(ms * 64 / 1000) - 128) * 2;
105-
setPixelColor(secondLed, gamma32(scale32(secondColor, b0)));
105+
setPixelColor(secondLed, scale32(secondColor, b0));
106106
uint8_t b1 = (sin8_t(ms * 64 / 1000) - 128) * 2;
107-
setPixelColor(inc(secondLed, 1, secondsSegment), gamma32(scale32(secondColor, b1)));
107+
setPixelColor(inc(secondLed, 1, secondsSegment), scale32(secondColor, b1));
108108
}
109109

110110
static inline uint32_t qadd32(uint32_t c1, uint32_t c2) {
@@ -191,7 +191,7 @@ class AnalogClockUsermod : public Usermod {
191191
// for (uint16_t i = 1; i < secondsTrail + 1; ++i) {
192192
// uint16_t trailLed = dec(secondLed, i, secondsSegment);
193193
// uint8_t trailBright = 255 / (secondsTrail + 1) * (secondsTrail - i + 1);
194-
// setPixelColor(trailLed, gamma32(scale32(secondColor, trailBright)));
194+
// setPixelColor(trailLed, scale32(secondColor, trailBright));
195195
// }
196196
}
197197

usermods/Cronixie/Cronixie.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class UsermodCronixie : public Usermod {
247247

248248
if (backlight && _digitOut[i] <11)
249249
{
250-
uint32_t col = gamma32(strip.getSegment(0).colors[1]);
250+
uint32_t col = strip.getSegment(0).colors[1];
251251
for (uint16_t j=o; j< o+10; j++) {
252252
if (j != excl) strip.setPixelColor(j, col);
253253
}

usermods/audioreactive/audio_reactive.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ class AudioReactive : public Usermod {
17361736
}
17371737

17381738
void onStateChange(uint8_t callMode) override {
1739-
if (initDone && enabled && addPalettes && palettes==0 && strip.customPalettes.size()<10) {
1739+
if (initDone && enabled && addPalettes && palettes==0 && customPalettes.size()<10) {
17401740
// if palettes were removed during JSON call re-add them
17411741
createAudioPalettes();
17421742
}
@@ -1966,20 +1966,20 @@ class AudioReactive : public Usermod {
19661966
void AudioReactive::removeAudioPalettes(void) {
19671967
DEBUG_PRINTLN(F("Removing audio palettes."));
19681968
while (palettes>0) {
1969-
strip.customPalettes.pop_back();
1969+
customPalettes.pop_back();
19701970
DEBUG_PRINTLN(palettes);
19711971
palettes--;
19721972
}
1973-
DEBUG_PRINT(F("Total # of palettes: ")); DEBUG_PRINTLN(strip.customPalettes.size());
1973+
DEBUG_PRINT(F("Total # of palettes: ")); DEBUG_PRINTLN(customPalettes.size());
19741974
}
19751975

19761976
void AudioReactive::createAudioPalettes(void) {
1977-
DEBUG_PRINT(F("Total # of palettes: ")); DEBUG_PRINTLN(strip.customPalettes.size());
1977+
DEBUG_PRINT(F("Total # of palettes: ")); DEBUG_PRINTLN(customPalettes.size());
19781978
if (palettes) return;
19791979
DEBUG_PRINTLN(F("Adding audio palettes."));
19801980
for (int i=0; i<MAX_PALETTES; i++)
1981-
if (strip.customPalettes.size() < 10) {
1982-
strip.customPalettes.push_back(CRGBPalette16(CRGB(BLACK)));
1981+
if (customPalettes.size() < 10) {
1982+
customPalettes.push_back(CRGBPalette16(CRGB(BLACK)));
19831983
palettes++;
19841984
DEBUG_PRINTLN(palettes);
19851985
} else break;
@@ -2016,7 +2016,7 @@ CRGB AudioReactive::getCRGBForBand(int x, int pal) {
20162016

20172017
void AudioReactive::fillAudioPalettes() {
20182018
if (!palettes) return;
2019-
size_t lastCustPalette = strip.customPalettes.size();
2019+
size_t lastCustPalette = customPalettes.size();
20202020
if (int(lastCustPalette) >= palettes) lastCustPalette -= palettes;
20212021
for (int pal=0; pal<palettes; pal++) {
20222022
uint8_t tcp[16]; // Needs to be 4 times however many colors are being used.
@@ -2045,7 +2045,7 @@ void AudioReactive::fillAudioPalettes() {
20452045
tcp[14] = rgb.g;
20462046
tcp[15] = rgb.b;
20472047

2048-
strip.customPalettes[lastCustPalette+pal].loadDynamicGradientPalette(tcp);
2048+
customPalettes[lastCustPalette+pal].loadDynamicGradientPalette(tcp);
20492049
}
20502050
}
20512051

usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,20 @@ void RotaryEncoderUIUsermod::sortModesAndPalettes() {
400400
modes_alpha_indexes = re_initIndexArray(strip.getModeCount());
401401
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
402402

403-
DEBUG_PRINT(F("Sorting palettes: ")); DEBUG_PRINT(strip.getPaletteCount()); DEBUG_PRINT('/'); DEBUG_PRINTLN(strip.customPalettes.size());
404-
palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount());
405-
palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount());
406-
if (strip.customPalettes.size()) {
407-
for (int i=0; i<strip.customPalettes.size(); i++) {
408-
palettes_alpha_indexes[strip.getPaletteCount()-strip.customPalettes.size()+i] = 255-i;
409-
palettes_qstrings[strip.getPaletteCount()-strip.customPalettes.size()+i] = PSTR("~Custom~");
403+
DEBUG_PRINT(F("Sorting palettes: ")); DEBUG_PRINT(getPaletteCount()); DEBUG_PRINT('/'); DEBUG_PRINTLN(customPalettes.size());
404+
palettes_qstrings = re_findModeStrings(JSON_palette_names, getPaletteCount());
405+
palettes_alpha_indexes = re_initIndexArray(getPaletteCount());
406+
if (customPalettes.size()) {
407+
for (int i=0; i<customPalettes.size(); i++) {
408+
palettes_alpha_indexes[getPaletteCount()-customPalettes.size()+i] = 255-i;
409+
palettes_qstrings[getPaletteCount()-customPalettes.size()+i] = PSTR("~Custom~");
410410
}
411411
}
412412
// How many palette names start with '*' and should not be sorted?
413413
// (Also skipping the first one, 'Default').
414414
int skipPaletteCount = 1;
415415
while (pgm_read_byte_near(palettes_qstrings[skipPaletteCount]) == '*') skipPaletteCount++;
416-
re_sortModes(palettes_qstrings, palettes_alpha_indexes, strip.getPaletteCount()-strip.customPalettes.size(), skipPaletteCount);
416+
re_sortModes(palettes_qstrings, palettes_alpha_indexes, getPaletteCount()-customPalettes.size(), skipPaletteCount);
417417
}
418418

419419
byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) {
@@ -702,7 +702,7 @@ void RotaryEncoderUIUsermod::findCurrentEffectAndPalette() {
702702

703703
effectPaletteIndex = 0;
704704
DEBUG_PRINTLN(effectPalette);
705-
for (unsigned i = 0; i < strip.getPaletteCount()+strip.customPalettes.size(); i++) {
705+
for (unsigned i = 0; i < getPaletteCount()+customPalettes.size(); i++) {
706706
if (palettes_alpha_indexes[i] == effectPalette) {
707707
effectPaletteIndex = i;
708708
DEBUG_PRINTLN(F("Found palette."));
@@ -892,7 +892,7 @@ void RotaryEncoderUIUsermod::changePalette(bool increase) {
892892
}
893893
display->updateRedrawTime();
894894
#endif
895-
effectPaletteIndex = max(min((unsigned)(increase ? effectPaletteIndex+1 : effectPaletteIndex-1), strip.getPaletteCount()+strip.customPalettes.size()-1), 0U);
895+
effectPaletteIndex = max(min((unsigned)(increase ? effectPaletteIndex+1 : effectPaletteIndex-1), getPaletteCount()+customPalettes.size()-1), 0U);
896896
effectPalette = palettes_alpha_indexes[effectPaletteIndex];
897897
stateChanged = true;
898898
if (applyToAll) {

wled00/FX.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,7 +5041,11 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline
50415041
unsigned yscale = SEGMENT.speed*8;
50425042
unsigned indexx = 0;
50435043

5044-
CRGBPalette16 pal = SEGMENT.check1 ? SEGPALETTE : SEGMENT.loadPalette(pal, 35);
5044+
//CRGBPalette16 pal = SEGMENT.check1 ? SEGPALETTE : SEGMENT.loadPalette(pal, 35);
5045+
CRGBPalette16 pal = SEGMENT.check1 ? SEGPALETTE : CRGBPalette16(CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black,
5046+
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::DarkOrange,
5047+
CRGB::DarkOrange,CRGB::DarkOrange, CRGB::Orange, CRGB::Orange,
5048+
CRGB::Yellow, CRGB::Orange, CRGB::Yellow, CRGB::Yellow);
50455049
for (int j=0; j < cols; j++) {
50465050
for (int i=0; i < rows; i++) {
50475051
indexx = perlin8(j*yscale*rows/255, i*xscale+strip.now/4); // We're moving along our Perlin map.
@@ -6076,7 +6080,8 @@ uint16_t mode_2Dscrollingtext(void) {
60766080
case 5: letterWidth = 5; letterHeight = 12; break;
60776081
}
60786082
// letters are rotated
6079-
if (((SEGMENT.custom3+1)>>3) % 2) {
6083+
const int8_t rotate = map(SEGMENT.custom3, 0, 31, -2, 2);
6084+
if (rotate == 1 || rotate == -1) {
60806085
rotLH = letterWidth;
60816086
rotLW = letterHeight;
60826087
} else {
@@ -6114,6 +6119,7 @@ uint16_t mode_2Dscrollingtext(void) {
61146119
else if (!strncmp_P(text,PSTR("#DD"),3)) sprintf (text, zero? ("%02d") : ("%d"), day(localTime));
61156120
else if (!strncmp_P(text,PSTR("#DAY"),4)) sprintf (text, ("%s") , dayShortStr(day(localTime)));
61166121
else if (!strncmp_P(text,PSTR("#DDDD"),5)) sprintf (text, ("%s") , dayStr(day(localTime)));
6122+
else if (!strncmp_P(text,PSTR("#DAYL"),5)) sprintf (text, ("%s") , dayStr(day(localTime)));
61176123
else if (!strncmp_P(text,PSTR("#MO"),3)) sprintf (text, zero? ("%02d") : ("%d"), month(localTime));
61186124
else if (!strncmp_P(text,PSTR("#MON"),4)) sprintf (text, ("%s") , monthShortStr(month(localTime)));
61196125
else if (!strncmp_P(text,PSTR("#MMMM"),5)) sprintf (text, ("%s") , monthStr(month(localTime)));
@@ -6147,27 +6153,28 @@ uint16_t mode_2Dscrollingtext(void) {
61476153
SEGENV.step = strip.now + map(SEGMENT.speed, 0, 255, 250, 50); // shift letters every ~250ms to ~50ms
61486154
}
61496155

6150-
if (!SEGMENT.check2) SEGMENT.fade_out(255 - (SEGMENT.custom1>>4)); // trail
6151-
bool usePaletteGradient = false;
6156+
SEGMENT.fade_out(255 - (SEGMENT.custom1>>4)); // trail
61526157
uint32_t col1 = SEGMENT.color_from_palette(SEGENV.aux1, false, PALETTE_SOLID_WRAP, 0);
61536158
uint32_t col2 = BLACK;
6159+
// if gradient is selected and palette is default (0) drawCharacter() uses gradient from SEGCOLOR(0) to SEGCOLOR(2)
6160+
// otherwise col2 == BLACK means use currently selected palette for gradient
6161+
// if gradient is not selected set both colors the same
61546162
if (SEGMENT.check1) { // use gradient
6155-
if(SEGMENT.palette == 0) { // use colors for gradient
6156-
col1 = SEGCOLOR(0);
6157-
col2 = SEGCOLOR(2);
6163+
if (SEGMENT.palette == 0) { // use colors for gradient
6164+
col1 = SEGCOLOR(0);
6165+
col2 = SEGCOLOR(2);
61586166
}
6159-
else usePaletteGradient = true;
6160-
}
6167+
} else col2 = col1; // force characters to use single color (from palette)
61616168

61626169
for (int i = 0; i < numberOfLetters; i++) {
61636170
int xoffset = int(cols) - int(SEGENV.aux0) + rotLW*i;
61646171
if (xoffset + rotLW < 0) continue; // don't draw characters off-screen
6165-
SEGMENT.drawCharacter(text[i], xoffset, yoffset, letterWidth, letterHeight, col1, col2, map(SEGMENT.custom3, 0, 31, -2, 2), usePaletteGradient);
6172+
SEGMENT.drawCharacter(text[i], xoffset, yoffset, letterWidth, letterHeight, col1, col2, rotate);
61666173
}
61676174

61686175
return FRAMETIME;
61696176
}
6170-
static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size,Rotate,Gradient,Overlay,Reverse;!,!,Gradient;!;2;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0";
6177+
static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size,Rotate,Gradient,,Reverse;!,!,Gradient;!;2;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0";
61716178

61726179

61736180
////////////////////////////

0 commit comments

Comments
 (0)