diff --git a/wled00/FX.cpp b/wled00/FX.cpp index b3eaca4a..ae5abe0e 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1816,7 +1816,7 @@ static const char *_data_FX_MODE_OSCILLATE PROGMEM = "Oscillate"; uint16_t mode_lightning(void) { uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash - uint16_t ledlen = 1 + random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) + uint16_t ledlen = 1 + random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond SEGLEN-1) uint8_t bri = 255/random8(1, 3); if (SEGENV.aux1 == 0) //init, leader flash @@ -1958,7 +1958,7 @@ static const char *_data_FX_MODE_PALETTE PROGMEM = "Palette@!,;1,2,3;!"; // // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). // -// This simulation scales it self a bit depending on NUM_LEDS; it should look +// This simulation scales it self a bit depending on SEGLEN; it should look // "OK" on anywhere from 20 to 100 LEDs without too much tweaking. // // I recommend running this simulation at anywhere from 30-100 frames per second, @@ -4565,10 +4565,6 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - // const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - - // if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - // CRGB *leds = reinterpret_cast(SEGENV.data); uint16_t x, y; @@ -4613,13 +4609,9 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); //for (uint16_t i = 0; i < w*h; i++) leds[i] = CRGB::Black; SEGENV.aux0 = 0; // start with red hue } @@ -4630,7 +4622,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so byte numLines = SEGMENT.intensity/16 + 1; SEGENV.aux0++; // hue - SEGMENT.fadeToBlackBy(leds, 40); + SEGMENT.fadeToBlackBy(strip.leds, 40); for (size_t i = 0; i < numLines; i++) { byte x1 = beatsin8(2 + SEGMENT.speed/16, 0, (cols - 1)); @@ -4647,18 +4639,18 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so byte dx = lerp8by8(x1, y1, i * 255 / steps); byte dy = lerp8by8(x2, y2, i * 255 / steps); int index = XY(dx, dy); - leds[index] += color; // change to += for brightness look - if (grad) leds[index] %= (i * 255 / steps); //Draw gradient line + strip.leds[index] += color; // change to += for brightness look + if (grad) strip.leds[index] %= (i * 255 / steps); //Draw gradient line } if (dot) { //add white point at the ends of line - leds[XY(x1, x2)] += CRGB::White; - leds[XY(y1, y2)] += CRGB::White; + strip.leds[XY(x1, x2)] += CRGB::White; + strip.leds[XY(y1, y2)] += CRGB::White; } } - SEGMENT.blur2d(leds, 4); + SEGMENT.blur2d(strip.leds, 4); - SEGMENT.setPixels(leds); // Use this ONLY if we're going to display via leds[x] method. + SEGMENT.setPixels(strip.leds); // Use this ONLY if we're going to display via leds[x] method. return FRAMETIME; } // mode_2DColoredBursts() static const char *_data_FX_MODE_2DCOLOREDBURSTS PROGMEM = "2D Colored Bursts@Speed,# of lines;;!"; @@ -4672,22 +4664,18 @@ uint16_t mode_2Ddna(void) { // dna originally by by ldirko at https://pa const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 64); + SEGMENT.fadeToBlackBy(strip.leds, 64); for(int i = 0; i < cols; i++) { - leds[XY(i, beatsin8(SEGMENT.speed/8, 0, rows-1, 0, i*4))] = ColorFromPalette(SEGPALETTE, i*5+millis()/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND); - leds[XY(i, beatsin8(SEGMENT.speed/8, 0, rows-1, 0, i*4+128))] = ColorFromPalette(SEGPALETTE,i*5+128+millis()/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND); // 180 degrees (128) out of phase + strip.leds[XY(i, beatsin8(SEGMENT.speed/8, 0, rows-1, 0, i*4))] = ColorFromPalette(SEGPALETTE, i*5+millis()/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND); + strip.leds[XY(i, beatsin8(SEGMENT.speed/8, 0, rows-1, 0, i*4+128))] = ColorFromPalette(SEGPALETTE,i*5+128+millis()/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND); // 180 degrees (128) out of phase } - SEGMENT.blur2d(leds, SEGMENT.intensity/8); + SEGMENT.blur2d(strip.leds, SEGMENT.intensity/8); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2Ddna() static const char *_data_FX_MODE_2DDNA PROGMEM = "2D DNA@Scroll speed,Blur;1,2,3;!"; @@ -4701,13 +4689,9 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); SEGENV.aux0 = 0; // hue } @@ -4715,7 +4699,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma uint8_t freq = SEGMENT.intensity/8; uint32_t ms = millis() / 20; - SEGMENT.nscale8(leds, 120); + SEGMENT.nscale8(strip.leds, 120); for (uint16_t i = 0; i < rows; i++) { uint16_t x = beatsin8(speeds, 0, cols - 1, 0, i * freq) + beatsin8(speeds - 7, 0, cols - 1, 0, i * freq + 128); @@ -4727,15 +4711,15 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma for (size_t k = 1; k <= steps; k++) { byte dx = lerp8by8(x, x1, k * 255 / steps); uint16_t index = XY(dx, i); - leds[index] += ColorFromPalette(SEGPALETTE, SEGENV.aux0, 255, LINEARBLEND); - leds[index] %= (k * 255 / steps); //for draw gradient line + strip.leds[index] += ColorFromPalette(SEGPALETTE, SEGENV.aux0, 255, LINEARBLEND); + strip.leds[index] %= (k * 255 / steps); //for draw gradient line } - leds[XY(x, i)] += CRGB::DarkSlateGray; - leds[XY(x1, i)] += CRGB::White; + strip.leds[XY(x, i)] += CRGB::DarkSlateGray; + strip.leds[XY(x1, i)] += CRGB::White; } } - SEGMENT.setPixels(leds); // Use this ONLY if we're going to display via leds[x] method. + SEGMENT.setPixels(strip.leds); // Use this ONLY if we're going to display via leds[x] method. return FRAMETIME; } // mode_2DDNASpiral() static const char *_data_FX_MODE_2DDNASPIRAL PROGMEM = "2D DNA Spiral@Scroll speed,Blur;;!"; @@ -4749,16 +4733,12 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled //if (cols<8 || rows<8) return mode_static(); // makes no sense to run on smaller than 8x8 - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 128); + SEGMENT.fadeToBlackBy(strip.leds, 128); const uint16_t maxDim = MAX(cols, rows)/2; unsigned long t = millis() / (32 - (SEGMENT.speed>>3)); @@ -4766,11 +4746,11 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli float angle = radians(t * (maxDim - i)); uint16_t myX = (cols>>1) + (uint16_t)(sin_t(angle) * i) + (cols%2); uint16_t myY = (rows>>1) + (uint16_t)(cos_t(angle) * i) + (rows%2); - leds[XY(myX,myY)] = ColorFromPalette(SEGPALETTE, (i * 20) + (t / 20), 255, LINEARBLEND); + strip.leds[XY(myX,myY)] = ColorFromPalette(SEGPALETTE, (i * 20) + (t / 20), 255, LINEARBLEND); } - SEGMENT.blur2d(leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DDrift() static const char *_data_FX_MODE_2DDRIFT PROGMEM = "2D Drift@Rotation speed,Blur amount;;!"; @@ -4784,12 +4764,8 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); uint16_t xscale = SEGMENT.intensity*4; uint32_t yscale = SEGMENT.speed*8; @@ -4803,11 +4779,11 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline for (uint16_t j=0; j < cols; j++) { for (uint16_t i=0; i < rows; i++) { indexx = inoise8(j*yscale*rows/255, i*xscale+millis()/4); // We're moving along our Perlin map. - leds[XY(j,i)] = ColorFromPalette(SEGPALETTE, min(i*(indexx)>>4, 255), i*255/cols, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED. + strip.leds[XY(j,i)] = ColorFromPalette(SEGPALETTE, min(i*(indexx)>>4, 255), i*255/cols, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED. } // for i } // for j - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2Dfirenoise() static const char *_data_FX_MODE_2DFIRENOISE PROGMEM = "2D Firenoise@X scale,Y scale;;"; @@ -4821,20 +4797,16 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 16); + SEGMENT.fadeToBlackBy(strip.leds, 16); for (size_t i = 8; i > 0; i--) { - leds[XY(beatsin8(SEGMENT.speed/8 + i, 0, cols - 1), beatsin8(SEGMENT.intensity/8 - i, 0, rows - 1))] += ColorFromPalette(SEGPALETTE, beatsin8(12, 0, 255), 255, LINEARBLEND); + strip.leds[XY(beatsin8(SEGMENT.speed/8 + i, 0, cols - 1), beatsin8(SEGMENT.intensity/8 - i, 0, rows - 1))] += ColorFromPalette(SEGPALETTE, beatsin8(12, 0, 255), 255, LINEARBLEND); } - SEGMENT.blur2d(leds, 16); + SEGMENT.blur2d(strip.leds, 16); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DFrizzles() static const char *_data_FX_MODE_2DFRIZZLES PROGMEM = "2D Frizzles@X frequency,Y frequency;;!"; @@ -4853,12 +4825,12 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled + const uint16_t dataSize = sizeof(CRGB) * strip.matrixWidth * strip.matrixHeight; // using width*height prevents reallocation if mirroring is enabled + // use matrixWidth and Height as leds is also on whole matrix - if (!SEGENV.allocateData(dataSize*2 + sizeof(unsigned long))) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - CRGB *prevLeds = reinterpret_cast(SEGENV.data + dataSize); - unsigned long *resetMillis = reinterpret_cast(SEGENV.data + 2*dataSize); // triggers reset + if (!SEGENV.allocateData(dataSize + sizeof(unsigned long))) return mode_static(); //allocation failed + CRGB *prevLeds = reinterpret_cast(SEGENV.data); + unsigned long *resetMillis = reinterpret_cast(SEGENV.data + dataSize); // triggers reset CRGB backgroundColor = SEGCOLOR(1); @@ -4871,9 +4843,9 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) { uint8_t state = random8()%2; if (state == 0) - leds[XY(x,y)] = backgroundColor; + strip.leds[XY(x,y)] = backgroundColor; else - leds[XY(x,y)] = (CRGB)SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0); + strip.leds[XY(x,y)] = (CRGB)SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0); } SEGMENT.fill_solid(prevLeds, CRGB::Black); @@ -4883,7 +4855,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: } //copy previous leds (save previous generation) - for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) prevLeds[XY(x,y)] = leds[XY(x,y)]; + for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) prevLeds[XY(x,y)] = strip.leds[XY(x,y)]; //calculate new leds for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) { @@ -4915,29 +4887,29 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: } // i,j // Rules of Life - if ((leds[XY(x,y)] != backgroundColor) && (neighbors < 2)) leds[XY(x,y)] = backgroundColor; // Loneliness - else if ((leds[XY(x,y)] != backgroundColor) && (neighbors > 3)) leds[XY(x,y)] = backgroundColor; // Overpopulation - else if ((leds[XY(x,y)] == backgroundColor) && (neighbors == 3)) { // Reproduction + if ((strip.leds[XY(x,y)] != backgroundColor) && (neighbors < 2)) strip.leds[XY(x,y)] = backgroundColor; // Loneliness + else if ((strip.leds[XY(x,y)] != backgroundColor) && (neighbors > 3)) strip.leds[XY(x,y)] = backgroundColor; // Overpopulation + else if ((strip.leds[XY(x,y)] == backgroundColor) && (neighbors == 3)) { // Reproduction //find dominantcolor and assign to cell colorCount dominantColorCount = {backgroundColor, 0}; for (int i=0; i<9 && colorsCount[i].count != 0; i++) if (colorsCount[i].count > dominantColorCount.count) dominantColorCount = colorsCount[i]; - if (dominantColorCount.count > 0) leds[XY(x,y)] = dominantColorCount.color; //assign the dominant color + if (dominantColorCount.count > 0) strip.leds[XY(x,y)] = dominantColorCount.color; //assign the dominant color } // else do nothing! } //x,y // calculate CRC16 of leds[] - uint16_t crc = crc16((const unsigned char*)leds, dataSize-1); + uint16_t crc = crc16((const unsigned char*)strip.leds, dataSize-1); // check if we had same CRC and reset if needed // same CRC would mean image did not change or was repeating itself if (!(crc == SEGENV.aux0 || crc == SEGENV.aux1)) *resetMillis = strip.now; //if no repetition avoid reset - // remeber last two + // remember last two SEGENV.aux1 = SEGENV.aux0; SEGENV.aux0 = crc; - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : FRAMETIME_FIXED * (128-(SEGMENT.speed>>1)); // update only when appropriate time passes (in 42 FPS slots) } // mode_2Dgameoflife() static const char *_data_FX_MODE_2DGAMEOFLIFE PROGMEM = "2D Game Of Life@!,;!,!;!"; @@ -5117,12 +5089,8 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); uint8_t fade = map(SEGMENT.custom1, 0, 255, 50, 250); // equals trail size uint8_t speed = (256-SEGMENT.speed) >> map(MIN(rows, 150), 0, 150, 0, 3); // slower speeds for small displays @@ -5141,22 +5109,22 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. SEGENV.step = strip.now; for (int16_t row=rows-1; row>=0; row--) { for (int16_t col=0; col(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 64); + SEGMENT.fadeToBlackBy(strip.leds, 64); float t = millis() / (33 - SEGMENT.speed/8); for (uint16_t i = 0; i < cols; i++) { uint16_t thisVal = inoise8(i * 30, t, t); @@ -5287,7 +5251,7 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito uint16_t cx = (i + thisMax_); uint16_t cy = (j + thisMax); - leds[XY(i, j)] += ((x - y > -2) && (x - y < 2)) || + strip.leds[XY(i, j)] += ((x - y > -2) && (x - y < 2)) || ((cols - 1 - x - y) > -2 && (cols - 1 - x - y < 2)) || (cols - cx == 0) || (cols - 1 - cx == 0) || @@ -5295,9 +5259,9 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito (rows - 1 - cy == 0)) ? ColorFromPalette(SEGPALETTE, beat8(5), thisVal, LINEARBLEND) : CRGB::Black; } } - SEGMENT.blur2d(leds, 4); + SEGMENT.blur2d(strip.leds, 4); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DPlasmaball() static const char *_data_FX_MODE_2DPLASMABALL PROGMEM = "2D Plasma Ball@Speed;!,!,!;!"; @@ -5314,16 +5278,12 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); CRGBPalette16 auroraPalette = {0x000000, 0x003300, 0x006600, 0x009900, 0x00cc00, 0x00ff00, 0x33ff00, 0x66ff00, 0x99ff00, 0xccff00, 0xffff00, 0xffcc00, 0xff9900, 0xff6600, 0xff3300, 0xff0000}; if (SEGENV.call == 0) { SEGENV.step = 0; - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); } float adjustHeight = (float)map(rows, 8, 32, 28, 12); @@ -5349,14 +5309,14 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https for (uint16_t x = 0; x < cols; x++) { for (uint16_t y = 0; y < rows; y++) { SEGENV.step++; - leds[XY(x, y)] = ColorFromPalette(auroraPalette, + strip.leds[XY(x, y)] = ColorFromPalette(auroraPalette, qsub8( inoise8((SEGENV.step%2) + x * _scale, y * 16 + SEGENV.step % 16, SEGENV.step / _speed), fabs((float)rows / 2 - (float)y) * adjustHeight)); } } - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DPolarLights() static const char *_data_FX_MODE_2DPOLARLIGHTS PROGMEM = "2D Polar Lights@Speed,Scale;;"; @@ -5370,24 +5330,20 @@ uint16_t mode_2DPulser(void) { // By: ldirko https://edi //const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 8 - (SEGMENT.intensity>>5)); + SEGMENT.fadeToBlackBy(strip.leds, 8 - (SEGMENT.intensity>>5)); uint16_t a = strip.now / (18 - SEGMENT.speed / 16); uint16_t x = (a / 14); uint16_t y = map((sin8(a * 5) + sin8(a * 4) + sin8(a * 2)), 0, 765, rows-1, 0); uint16_t index = XY(x, y); // XY() will wrap x or y - leds[index] = ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND); + strip.leds[index] = ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND); - SEGMENT.blur2d(leds, 1 + (SEGMENT.intensity>>4)); + SEGMENT.blur2d(strip.leds, 1 + (SEGMENT.intensity>>4)); - SEGMENT.setPixels(leds); // Use this ONLY if we're going to display via leds[x] method. + SEGMENT.setPixels(strip.leds); // Use this ONLY if we're going to display via leds[x] method. return FRAMETIME; } // mode_2DPulser() static const char *_data_FX_MODE_2DPULSER PROGMEM = "2D Pulser@Speed,Blur;;!"; @@ -5401,24 +5357,20 @@ uint16_t mode_2DSindots(void) { // By: ldirko http const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(leds, 15); + SEGMENT.fadeToBlackBy(strip.leds, 15); byte t1 = millis() / (257 - SEGMENT.speed); // 20; byte t2 = sin8(t1) / 4 * 2; for (uint16_t i = 0; i < 13; i++) { byte x = sin8(t1 + i * SEGMENT.intensity/8)*(cols-1)/255; // max index now 255x15/255=15! byte y = sin8(t2 + i * SEGMENT.intensity/8)*(rows-1)/255; // max index now 255x15/255=15! - leds[XY(x, y)] = ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND); + strip.leds[XY(x, y)] = ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND); } - SEGMENT.blur2d(leds, 16); + SEGMENT.blur2d(strip.leds, 16); - SEGMENT.setPixels(leds); // Use this ONLY if we're going to display via leds[x] method. + SEGMENT.setPixels(strip.leds); // Use this ONLY if we're going to display via leds[x] method. return FRAMETIME; } // mode_2DSindots() static const char *_data_FX_MODE_2DSINDOTS PROGMEM = "2D Sindots@Speed,Dot distance;;!"; @@ -5434,18 +5386,14 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); const uint8_t kBorderWidth = 2; - SEGMENT.fadeToBlackBy(leds, 24); + SEGMENT.fadeToBlackBy(strip.leds, 24); uint8_t blurAmount = SEGMENT.custom3>>4; - SEGMENT.blur2d(leds, blurAmount); + SEGMENT.blur2d(strip.leds, blurAmount); // Use two out-of-sync sine waves uint8_t i = beatsin8(19, kBorderWidth, cols-kBorderWidth); @@ -5457,11 +5405,11 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g uint16_t ms = millis(); - leds[XY(i, m)] += ColorFromPalette(SEGPALETTE, ms/29, 255, LINEARBLEND); - leds[XY(j, n)] += ColorFromPalette(SEGPALETTE, ms/41, 255, LINEARBLEND); - leds[XY(k, p)] += ColorFromPalette(SEGPALETTE, ms/73, 255, LINEARBLEND); + strip.leds[XY(i, m)] += ColorFromPalette(SEGPALETTE, ms/29, 255, LINEARBLEND); + strip.leds[XY(j, n)] += ColorFromPalette(SEGPALETTE, ms/41, 255, LINEARBLEND); + strip.leds[XY(k, p)] += ColorFromPalette(SEGPALETTE, ms/73, 255, LINEARBLEND); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2Dsquaredswirl() static const char *_data_FX_MODE_2DSQUAREDSWIRL PROGMEM = "2D Squared Swirl@,,,,Blur;,,;!"; @@ -5475,13 +5423,11 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize + (sizeof(byte)*(cols+2)*(rows+2)))) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - byte *bump = reinterpret_cast(SEGENV.data + dataSize); + if (!SEGENV.allocateData(sizeof(byte)*(cols+2)*(rows+2))) return mode_static(); //allocation failed + byte *bump = reinterpret_cast(SEGENV.data); - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); unsigned long t = millis() / 4; int index = 0; @@ -5507,12 +5453,12 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi int temp = difx * difx + dify * dify; int col = 255 - temp / 8; //8 its a size of effect if (col < 0) col = 0; - leds[XY(x, y)] = HeatColor(col / (3.0f-(float)(SEGMENT.intensity)/128.f)); + strip.leds[XY(x, y)] = HeatColor(col / (3.0f-(float)(SEGMENT.intensity)/128.f)); } yindex += (cols + 2); } - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DSunradiation() static const char *_data_FX_MODE_2DSUNRADIATION PROGMEM = "2D Sun Radiation@Variance,Brightness;;"; @@ -5526,12 +5472,8 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); uint8_t hue; int offsetX = beatsin16(3, -360, 360); @@ -5541,13 +5483,13 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so for (uint16_t y = 0; y < rows; y++) { uint16_t index = XY(x, y); hue = x * beatsin16(10, 1, 10) + offsetY; - leds[index] = ColorFromPalette(SEGPALETTE, hue, sin8(x * SEGMENT.speed + offsetX) * sin8(x * SEGMENT.speed + offsetX) / 255, LINEARBLEND); + strip.leds[index] = ColorFromPalette(SEGPALETTE, hue, sin8(x * SEGMENT.speed + offsetX) * sin8(x * SEGMENT.speed + offsetX) / 255, LINEARBLEND); hue = y * 3 + offsetX; - leds[index] += ColorFromPalette(SEGPALETTE, hue, sin8(y * SEGMENT.intensity + offsetY) * sin8(y * SEGMENT.intensity + offsetY) / 255, LINEARBLEND); + strip.leds[index] += ColorFromPalette(SEGPALETTE, hue, sin8(y * SEGMENT.intensity + offsetY) * sin8(y * SEGMENT.intensity + offsetY) / 255, LINEARBLEND); } } - SEGMENT.setPixels(leds); // Use this ONLY if we're going to display via leds[x] method. + SEGMENT.setPixels(strip.leds); // Use this ONLY if we're going to display via leds[x] method. return FRAMETIME; } // mode_2DTartan() static const char *_data_FX_MODE_2DTARTAN PROGMEM = "2D Tartan@X scale,Y scale;;!"; @@ -5561,12 +5503,8 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); uint32_t tb = strip.now >> 12; // every ~4s if (tb > SEGENV.step) { @@ -5578,23 +5516,23 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht SEGENV.step = tb + random8(4); } - SEGMENT.fadeToBlackBy(leds, map(SEGMENT.speed, 0, 255, 248, 16)); - SEGMENT.move(SEGENV.aux0, 1, leds); + SEGMENT.fadeToBlackBy(strip.leds, map(SEGMENT.speed, 0, 255, 248, 16)); + SEGMENT.move(SEGENV.aux0, 1, strip.leds); for (size_t i = 0; i < 8; i++) { byte x = beatsin8(12 + i, 2, cols - 3); byte y = beatsin8(15 + i, 2, rows - 3); CRGB color = ColorFromPalette(SEGPALETTE, beatsin8(12 + i, 0, 255), 255); - leds[XY(x, y)] += color; + strip.leds[XY(x, y)] += color; if (cols > 24 || rows > 24) { - leds[XY(x + 1, y)] += color; - leds[XY(x - 1, y)] += color; - leds[XY(x, y + 1)] += color; - leds[XY(x, y - 1)] += color; + strip.leds[XY(x + 1, y)] += color; + strip.leds[XY(x - 1, y)] += color; + strip.leds[XY(x, y + 1)] += color; + strip.leds[XY(x, y - 1)] += color; } } - SEGMENT.blur2d(leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DSPACESHIPS PROGMEM = "2D Spaceships@!,Blur;!,!,!;!"; @@ -5610,7 +5548,6 @@ uint16_t mode_2Dcrazybees(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled byte n = MIN(MAX_BEES, (rows * cols) / 256 + 1); @@ -5630,12 +5567,11 @@ uint16_t mode_2Dcrazybees(void) { }; } bee_t; - if (!SEGENV.allocateData(dataSize + sizeof(bee_t)*MAX_BEES)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - bee_t *bee = reinterpret_cast(SEGENV.data + dataSize); + if (!SEGENV.allocateData(sizeof(bee_t)*MAX_BEES)) return mode_static(); //allocation failed + bee_t *bee = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); for (size_t i = 0; i < n; i++) { bee[i].posX = random8(0, cols); bee[i].posY = random8(0, rows); @@ -5646,15 +5582,15 @@ uint16_t mode_2Dcrazybees(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + (FRAMETIME * 8 / ((SEGMENT.speed>>5)+1)); - SEGMENT.fadeToBlackBy(leds, 32); + SEGMENT.fadeToBlackBy(strip.leds, 32); for (size_t i = 0; i < n; i++) { - leds[XY(bee[i].aimX + 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); - leds[XY(bee[i].aimX, bee[i].aimY + 1)] += CHSV(bee[i].hue, 255, 255); - leds[XY(bee[i].aimX - 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); - leds[XY(bee[i].aimX, bee[i].aimY - 1)] += CHSV(bee[i].hue, 255, 255); + strip.leds[XY(bee[i].aimX + 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); + strip.leds[XY(bee[i].aimX, bee[i].aimY + 1)] += CHSV(bee[i].hue, 255, 255); + strip.leds[XY(bee[i].aimX - 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); + strip.leds[XY(bee[i].aimX, bee[i].aimY - 1)] += CHSV(bee[i].hue, 255, 255); if (bee[i].posX != bee[i].aimX || bee[i].posY != bee[i].aimY) { - leds[XY(bee[i].posX, bee[i].posY)] = CHSV(bee[i].hue, 60, 255); + strip.leds[XY(bee[i].posX, bee[i].posY)] = CHSV(bee[i].hue, 60, 255); int8_t error2 = bee[i].error * 2; if (error2 > -bee[i].deltaY) { bee[i].error -= bee[i].deltaY; @@ -5668,9 +5604,9 @@ uint16_t mode_2Dcrazybees(void) { bee[i].aimed(cols, rows); } } - SEGMENT.blur2d(leds, SEGMENT.intensity>>4); + SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>4); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); } return FRAMETIME; } @@ -5687,7 +5623,6 @@ uint16_t mode_2Dghostrider(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled typedef struct Lighter { int16_t gPosX; @@ -5702,16 +5637,15 @@ uint16_t mode_2Dghostrider(void) { int8_t Vspeed; } lighter_t; - if (!SEGENV.allocateData(dataSize + sizeof(lighter_t))) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - lighter_t *lighter = reinterpret_cast(SEGENV.data + dataSize); + if (!SEGENV.allocateData(sizeof(lighter_t))) return mode_static(); //allocation failed + lighter_t *lighter = reinterpret_cast(SEGENV.data); const size_t maxLighters = min(cols + rows, LIGHTERS_AM); if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); random16_set_seed(strip.now); lighter->angleSpeed = random8(0,20) - 10; lighter->Vspeed = 5; @@ -5727,10 +5661,10 @@ uint16_t mode_2Dghostrider(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + 1024 / (cols+rows); - SEGMENT.fadeToBlackBy(leds, (SEGMENT.speed>>2)+64); + SEGMENT.fadeToBlackBy(strip.leds, (SEGMENT.speed>>2)+64); CRGB color = CRGB::White; - SEGMENT.wu_pixel(leds, lighter->gPosX * 256 / 10, lighter->gPosY * 256 / 10, color); + SEGMENT.wu_pixel(strip.leds, lighter->gPosX * 256 / 10, lighter->gPosY * 256 / 10, color); lighter->gPosX += lighter->Vspeed * sin_t(radians(lighter->gAngle)); lighter->gPosY += lighter->Vspeed * cos_t(radians(lighter->gAngle)); @@ -5758,12 +5692,12 @@ uint16_t mode_2Dghostrider(void) { lighter->lightersPosX[i] += -7 * sin_t(radians(lighter->Angle[i])); lighter->lightersPosY[i] += -7 * cos_t(radians(lighter->Angle[i])); } - SEGMENT.wu_pixel(leds, lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); + SEGMENT.wu_pixel(strip.leds, lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); } - SEGMENT.blur2d(leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); } - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DGHOSTRIDER PROGMEM = "2D Ghost Rider@Fade rate,Blur;!,!,!;!"; @@ -5779,7 +5713,6 @@ uint16_t mode_2Dfloatingblobs(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled typedef struct Blob { float x[MAX_BLOBS], y[MAX_BLOBS]; @@ -5791,14 +5724,13 @@ uint16_t mode_2Dfloatingblobs(void) { uint8_t Amount = (SEGMENT.intensity>>5) + 1; // NOTE: be sure to update MAX_BLOBS if you change this - if (!SEGENV.allocateData(dataSize + sizeof(blob_t))) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - blob_t *blob = reinterpret_cast(SEGENV.data + dataSize); + if (!SEGENV.allocateData(sizeof(blob_t))) return mode_static(); //allocation failed + blob_t *blob = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); for (size_t i = 0; i < MAX_BLOBS; i++) { blob->r[i] = cols>15 ? random8(1, cols/8.f) : 1; blob->sX[i] = (float) random8(3, cols) / (float)(256 - SEGMENT.speed); // speed x @@ -5812,7 +5744,7 @@ uint16_t mode_2Dfloatingblobs(void) { } } - SEGMENT.fadeToBlackBy(leds, 20); + SEGMENT.fadeToBlackBy(strip.leds, 20); // Bounce balls around for (size_t i = 0; i < Amount; i++) { @@ -5833,8 +5765,8 @@ uint16_t mode_2Dfloatingblobs(void) { } CRGB c = ColorFromPalette(SEGPALETTE, blob->color[i]); //if (!SEGMENT.palette) c = SEGCOLOR(0); - if (blob->r[i] > 1.f) SEGMENT.fill_circle(leds, blob->y[i], blob->x[i], blob->r[i], c); - else leds[XY(blob->y[i], blob->x[i])] += c; + if (blob->r[i] > 1.f) SEGMENT.fill_circle(strip.leds, blob->y[i], blob->x[i], blob->r[i], c); + else strip.leds[XY(blob->y[i], blob->x[i])] += c; // move x if (blob->x[i] + blob->r[i] >= cols - 1) blob->x[i] += (blob->sX[i] * ((cols - 1 - blob->x[i]) / blob->r[i] + 0.005f)); else if (blob->x[i] - blob->r[i] <= 0) blob->x[i] += (blob->sX[i] * (blob->x[i] / blob->r[i] + 0.005f)); @@ -5862,11 +5794,11 @@ uint16_t mode_2Dfloatingblobs(void) { blob->y[i] = rows - 1.01f; } } - SEGMENT.blur2d(leds, cols+rows); + SEGMENT.blur2d(strip.leds, cols+rows); if (SEGENV.step < millis()) SEGENV.step = millis() + 2000; // change colors every 2 seconds - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } #undef MAX_BLOBS @@ -5932,28 +5864,24 @@ uint16_t mode_2Ddriftrose(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled const float CX = cols/2.f - .5f; const float CY = rows/2.f - .5f; const float L = min(cols, rows) / 2.f; - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); } - SEGMENT.fadeToBlackBy(leds, 32+(SEGMENT.speed>>3)); + SEGMENT.fadeToBlackBy(strip.leds, 32+(SEGMENT.speed>>3)); for (size_t i = 1; i < 37; i++) { uint32_t x = (CX + (sin_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f; uint32_t y = (CY + (cos_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f; - SEGMENT.wu_pixel(leds, x, y, CHSV(i * 10, 255, 255)); + SEGMENT.wu_pixel(strip.leds, x, y, CHSV(i * 10, 255, 255)); } - SEGMENT.blur2d(leds, (SEGMENT.intensity>>4)+1); + SEGMENT.blur2d(strip.leds, (SEGMENT.intensity>>4)+1); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;;"; @@ -6078,16 +6006,12 @@ uint16_t mode_2DSwirl(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); - - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); const uint8_t borderWidth = 2; - SEGMENT.blur2d(leds, SEGMENT.custom1); + SEGMENT.blur2d(strip.leds, SEGMENT.custom1); uint8_t i = beatsin8( 27*SEGMENT.speed/255, borderWidth, cols - borderWidth); uint8_t j = beatsin8( 41*SEGMENT.speed/255, borderWidth, rows - borderWidth); @@ -6105,14 +6029,14 @@ uint16_t mode_2DSwirl(void) { // printUmData(); - leds[XY( i, j)] += ColorFromPalette(SEGPALETTE, (ms / 11 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 11, 200, 255); - leds[XY( j, i)] += ColorFromPalette(SEGPALETTE, (ms / 13 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 13, 200, 255); - leds[XY(ni, nj)] += ColorFromPalette(SEGPALETTE, (ms / 17 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 17, 200, 255); - leds[XY(nj, ni)] += ColorFromPalette(SEGPALETTE, (ms / 29 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 29, 200, 255); - leds[XY( i, nj)] += ColorFromPalette(SEGPALETTE, (ms / 37 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 37, 200, 255); - leds[XY(ni, j)] += ColorFromPalette(SEGPALETTE, (ms / 41 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 41, 200, 255); + strip.leds[XY( i, j)] += ColorFromPalette(SEGPALETTE, (ms / 11 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 11, 200, 255); + strip.leds[XY( j, i)] += ColorFromPalette(SEGPALETTE, (ms / 13 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 13, 200, 255); + strip.leds[XY(ni, nj)] += ColorFromPalette(SEGPALETTE, (ms / 17 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 17, 200, 255); + strip.leds[XY(nj, ni)] += ColorFromPalette(SEGPALETTE, (ms / 29 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 29, 200, 255); + strip.leds[XY( i, nj)] += ColorFromPalette(SEGPALETTE, (ms / 37 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 37, 200, 255); + strip.leds[XY(ni, j)] += ColorFromPalette(SEGPALETTE, (ms / 41 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND); //CHSV( ms / 41, 200, 255); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DSwirl() static const char *_data_FX_MODE_2DSWIRL PROGMEM = "2D Swirl ♪@!,Sensitivity=64,Blur;,Bg Swirl;!;ssim=0"; // Beatsin @@ -6127,13 +6051,9 @@ uint16_t mode_2DWaverly(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled - - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); } um_data_t *um_data; @@ -6143,7 +6063,7 @@ uint16_t mode_2DWaverly(void) { } float volumeSmth = *(float*) um_data->u_data[0]; - SEGMENT.fadeToBlackBy(leds, SEGMENT.speed); + SEGMENT.fadeToBlackBy(strip.leds, SEGMENT.speed); long t = millis() / 2; for (uint16_t i = 0; i < cols; i++) { @@ -6156,13 +6076,13 @@ uint16_t mode_2DWaverly(void) { uint16_t thisMax = map(thisVal, 0, 512, 0, rows); for (uint16_t j = 0; j < thisMax; j++) { - leds[XY(i, j)] += ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND); - leds[XY((cols - 1) - i, (rows - 1) - j)] += ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND); + strip.leds[XY(i, j)] += ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND); + strip.leds[XY((cols - 1) - i, (rows - 1) - j)] += ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND); } } - SEGMENT.blur2d(leds, 16); + SEGMENT.blur2d(strip.leds, 16); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DWaverly() static const char *_data_FX_MODE_2DWAVERLY PROGMEM = "2D Waverly ♪@Amplification,Sensitivity=64;;!;ssim=0"; // Beatsin @@ -6767,12 +6687,7 @@ static const char *_data_FX_MODE_BLURZ PROGMEM = "Blurz ♫@Fade rate,Blur amoun // ** DJLight // ///////////////////////// uint16_t mode_DJLight(void) { // Written by ??? Adapted by Will Tatam. - const int NUM_LEDS = SEGLEN; // aka SEGLEN - const int mid = NUM_LEDS / 2; - - const uint16_t dataSize = SEGLEN*sizeof(CRGB); - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); + const int mid = SEGLEN / 2; um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { @@ -6786,13 +6701,13 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil if (SEGENV.aux0 != secondHand) { // Triggered millis timing. SEGENV.aux0 = secondHand; - leds[mid] = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // 16-> 15 as 16 is out of bounds - leds[mid].fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10)); // TODO - Update + strip.leds[XY(mid%SEGMENT.virtualWidth(), mid/SEGMENT.virtualWidth())] = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // 16-> 15 as 16 is out of bounds + strip.leds[XY(mid%SEGMENT.virtualWidth(), mid/SEGMENT.virtualWidth())].fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10)); // TODO - Update - for (int i = NUM_LEDS - 1; i > mid; i--) leds[i] = leds[i - 1]; //move to the left - for (int i = 0; i < mid; i++) leds[i] = leds[i + 1]; // move to the right + for (int i = SEGLEN - 1; i > mid; i--) strip.leds[XY(i%SEGMENT.virtualWidth(), i/SEGMENT.virtualWidth())] = strip.leds[XY((i-1)%SEGMENT.virtualWidth(), (i-1)/SEGMENT.virtualWidth())]; //move to the left + for (int i = 0; i < mid; i++) strip.leds[XY(i%SEGMENT.virtualWidth(), i/SEGMENT.virtualWidth())] = strip.leds[XY((i+1)%SEGMENT.virtualWidth(), (i+1)/SEGMENT.virtualWidth())]; // move to the right - for (uint16_t i=0; i(SEGENV.data); int NUMB_BANDS = map(SEGMENT.custom1, 0, 255, 1, 16); int barWidth = (cols / NUMB_BANDS); @@ -7233,7 +7145,7 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil int v = map(fftResult[band], 0, 255, 10, 255); for (int w = 0; w < barWidth; w++) { int xpos = (barWidth * b) + w; - leds[XY(xpos, 0)] = CHSV(hue, 255, v); + strip.leds[XY(xpos, 0)] = CHSV(hue, 255, v); } } @@ -7242,12 +7154,12 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil for (int j = (cols - 1); j >= 0; j--) { int src = XY(j, (i - 1)); int dst = XY(j, i); - leds[dst] = leds[src]; + strip.leds[dst] = strip.leds[src]; } } } - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DFunkyPlank static const char *_data_FX_MODE_2DFUNKYPLANK PROGMEM = "2D Funky Plank ♫@Scroll speed,,# of bands;;;ssim=0"; // Beatsin diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 64bcbc5c..002f5fcd 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -141,9 +141,9 @@ uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y) { #ifndef WLED_DISABLE_2D uint16_t width = virtualWidth(); // segment width in logical pixels uint16_t height = virtualHeight(); // segment height in logical pixels - return (x%width) + (y%height) * width; + return (start + x%width) + (startY + y%height) * strip.matrixWidth; #else - return 0; + return start + x; #endif } @@ -176,7 +176,7 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end if (strip.useLedsArray) - strip.leds[start + xX + (startY + yY) * strip.matrixWidth] = col; + strip.leds[XY(xX, yY)] = col; strip.setPixelColorXY(start + xX, startY + yY, col); if (getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel @@ -251,8 +251,8 @@ uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) { y *= groupLength(); // expand to physical pixels if (x >= width() || y >= height()) return 0; if (strip.useLedsArray) { - CRGB led = strip.leds[start + x + (startY + y) * strip.matrixWidth]; - return led.r * 65536 + led.g * 256 + led.b; + CRGB led = strip.leds[XY(x, y)]; + return RGBW32(led.r, led.g, led.b, 0); } return strip.getPixelColorXY(start + x, startY + y); #else diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 6a50ae47..32e9f88f 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -465,7 +465,7 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) indexSet += offset; // offset/phase if (indexSet >= stop) indexSet -= len; // wrap if (strip.useLedsArray) - strip.leds[indexSet] = col; + strip.leds[XY(indexSet%virtualWidth(), indexSet/virtualWidth())] = col; strip.setPixelColor(indexSet, col); } } @@ -530,8 +530,8 @@ uint32_t Segment::getPixelColor(uint16_t i) i += offset; if (i >= stop) i -= length(); if (strip.useLedsArray) { - CRGB led = strip.leds[i]; - return led.r * 65536 + led.g * 256 + led.b; + CRGB led = strip.leds[XY(i%virtualWidth(), i/virtualWidth())]; + return RGBW32(led.r, led.g, led.b, 0); } else return strip.getPixelColor(i); @@ -833,15 +833,20 @@ void WS2812FX::service() { bool doShow = false; //initialize leds array. Move to better place then service??? TBD: realloc if nr of leds change - if (useLedsArray) { + // if (useLedsArray) { // if (leds != nullptr && sizeof(leds) / sizeof(uint32_t) != _length) { // free(leds); // leds = nullptr; // } if (leds == nullptr) { - leds = (CRGB*) malloc(sizeof(CRGB) * _length); + #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) + if (psramFound()) + leds = (CRGB*) ps_malloc(sizeof(CRGB) * _length); + else + #endif + leds = (CRGB*) malloc(sizeof(CRGB) * _length); } - } + // } _isServicing = true; _segment_index = 0;