From a70717f2f763d08faf945e622ef49b06bdbc9c87 Mon Sep 17 00:00:00 2001 From: ewowi Date: Fri, 29 Jul 2022 23:30:23 +0200 Subject: [PATCH 01/10] ssim2=ssim1 and ssim1=ssim0 (because off=0 is removed) --- wled00/FX.cpp | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 5d24600ba..457186001 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6060,7 +6060,7 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli return FRAMETIME; } // mode_ripplepeak() -static const char *_data_FX_MODE_RIPPLEPEAK PROGMEM = "Ripple Peak ♪@Fade rate,Max # of ripples,,Select bin,Volume (minimum)=0;!,!;!;mp12=0,ssim=1"; // Pixel, Beatsin +static const char *_data_FX_MODE_RIPPLEPEAK PROGMEM = "Ripple Peak ♪@Fade rate,Max # of ripples,,Select bin,Volume (minimum)=0;!,!;!;mp12=0,ssim=0"; // Pixel, Beatsin #ifndef WLED_DISABLE_2D @@ -6110,7 +6110,7 @@ uint16_t mode_2DSwirl(void) { SEGMENT.setPixels(leds); return FRAMETIME; } // mode_2DSwirl() -static const char *_data_FX_MODE_2DSWIRL PROGMEM = "2D Swirl ♪@!,Sensitivity=64,Blur;,Bg Swirl;!;ssim=1"; // Beatsin +static const char *_data_FX_MODE_2DSWIRL PROGMEM = "2D Swirl ♪@!,Sensitivity=64,Blur;,Bg Swirl;!;ssim=0"; // Beatsin ///////////////////////// @@ -6160,7 +6160,7 @@ uint16_t mode_2DWaverly(void) { SEGMENT.setPixels(leds); return FRAMETIME; } // mode_2DWaverly() -static const char *_data_FX_MODE_2DWAVERLY PROGMEM = "2D Waverly ♪@Amplification,Sensitivity=64;;!;ssim=1"; // Beatsin +static const char *_data_FX_MODE_2DWAVERLY PROGMEM = "2D Waverly ♪@Amplification,Sensitivity=64;;!;ssim=0"; // Beatsin #endif // WLED_DISABLE_2D @@ -6219,7 +6219,7 @@ uint16_t mode_gravcenter(void) { // Gravcenter. By Andrew Tuline. return FRAMETIME; } // mode_gravcenter() -static const char *_data_FX_MODE_GRAVCENTER PROGMEM = "Gravcenter ♪@Rate of fall,Sensitivity=128;,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_GRAVCENTER PROGMEM = "Gravcenter ♪@Rate of fall,Sensitivity=128;,!;!;mp12=2,ssim=0"; // Circle, Beatsin /////////////////////// @@ -6269,7 +6269,7 @@ uint16_t mode_gravcentric(void) { // Gravcentric. By Andrew return FRAMETIME; } // mode_gravcentric() -static const char *_data_FX_MODE_GRAVCENTRIC PROGMEM = "Gravcentric ♪@Rate of fall,Sensitivity=128;!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_GRAVCENTRIC PROGMEM = "Gravcentric ♪@Rate of fall,Sensitivity=128;!;!;mp12=2,ssim=0"; // Circle, Beatsin /////////////////////// @@ -6314,7 +6314,7 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline. return FRAMETIME; } // mode_gravimeter() -static const char *_data_FX_MODE_GRAVIMETER PROGMEM = "Gravimeter ♪@Rate of fall,Sensitivity=128;,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_GRAVIMETER PROGMEM = "Gravimeter ♪@Rate of fall,Sensitivity=128;,!;!;mp12=2,ssim=0"; // Circle, Beatsin ////////////////////// @@ -6337,7 +6337,7 @@ uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline. return FRAMETIME; } // mode_juggles() -static const char *_data_FX_MODE_JUGGLES PROGMEM = "Juggles ♪@!,# of balls;,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_JUGGLES PROGMEM = "Juggles ♪@!,# of balls;,!;!;mp12=0,ssim=0"; // Pixels, Beatsin ////////////////////// @@ -6364,7 +6364,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. return FRAMETIME; } // mode_matripix() -static const char *_data_FX_MODE_MATRIPIX PROGMEM = "Matripix ♪@!,Brightness=64;!,!;!;mp12=2,ssim=2,rev=1,mi=1,rY=1,mY=1"; // Circle, WeWillRockYou, reverseX +static const char *_data_FX_MODE_MATRIPIX PROGMEM = "Matripix ♪@!,Brightness=64;!,!;!;mp12=2,ssim=0,rev=1,mi=1,rY=1,mY=1"; // Circle, WeWillRockYou, reverseX ////////////////////// @@ -6399,7 +6399,7 @@ uint16_t mode_midnoise(void) { // Midnoise. By Andrew Tuline. return FRAMETIME; } // mode_midnoise() -static const char *_data_FX_MODE_MIDNOISE PROGMEM = "Midnoise ♪@Fade rate,Maximum length=128;,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_MIDNOISE PROGMEM = "Midnoise ♪@Fade rate,Maximum length=128;,!;!;mp12=2,ssim=0"; // Circle, Beatsin ////////////////////// @@ -6430,7 +6430,7 @@ uint16_t mode_noisefire(void) { // Noisefire. By Andrew Tuline. return FRAMETIME; } // mode_noisefire() -static const char *_data_FX_MODE_NOISEFIRE PROGMEM = "Noisefire ♪@!,!;;;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_NOISEFIRE PROGMEM = "Noisefire ♪@!,!;;;mp12=2,ssim=0"; // Circle, Beatsin /////////////////////// @@ -6463,7 +6463,7 @@ uint16_t mode_noisemeter(void) { // Noisemeter. By Andrew Tuline. return FRAMETIME; } // mode_noisemeter() -static const char *_data_FX_MODE_NOISEMETER PROGMEM = "Noisemeter ♪@Fade rate,Width=128;!,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_NOISEMETER PROGMEM = "Noisemeter ♪@Fade rate,Width=128;!,!;!;mp12=2,ssim=0"; // Circle, Beatsin ////////////////////// @@ -6493,7 +6493,7 @@ uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline. return FRAMETIME; } // mode_pixelwave() -static const char *_data_FX_MODE_PIXELWAVE PROGMEM = "Pixelwave ♪@!,Sensitivity=64;!,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_PIXELWAVE PROGMEM = "Pixelwave ♪@!,Sensitivity=64;!,!;!;mp12=2,ssim=0"; // Circle, Beatsin ////////////////////// @@ -6534,7 +6534,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline. return FRAMETIME; } // mode_plasmoid() -static const char *_data_FX_MODE_PLASMOID PROGMEM = "Plasmoid ♪@Phase=128,# of pixels=128;,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_PLASMOID PROGMEM = "Plasmoid ♪@Phase=128,# of pixels=128;,!;!;mp12=0,ssim=0"; // Pixels, Beatsin /////////////////////// @@ -6578,7 +6578,7 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline. return FRAMETIME; } // mode_puddlepeak() -static const char *_data_FX_MODE_PUDDLEPEAK PROGMEM = "Puddlepeak ♪@Fade rate,Puddle size,,Select bin,Volume (minimum)=0;!,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_PUDDLEPEAK PROGMEM = "Puddlepeak ♪@Fade rate,Puddle size,,Select bin,Volume (minimum)=0;!,!;!;mp12=0,ssim=0"; // Pixels, Beatsin ////////////////////// @@ -6609,7 +6609,7 @@ uint16_t mode_puddles(void) { // Puddles. By Andrew Tuline. return FRAMETIME; } // mode_puddles() -static const char *_data_FX_MODE_PUDDLES PROGMEM = "Puddles ♪@Fade rate,Puddle size;!,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_PUDDLES PROGMEM = "Puddles ♪@Fade rate,Puddle size;!,!;!;mp12=0,ssim=0"; // Pixels, Beatsin /////////////////////////////////////////////////////////////////////////////// @@ -6642,7 +6642,7 @@ uint16_t mode_pixels(void) { // Pixels. By Andrew Tuline. return FRAMETIME; } // mode_pixels() -static const char *_data_FX_MODE_PIXELS PROGMEM = "Pixels ♪@Fade rate,# of pixels;,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_PIXELS PROGMEM = "Pixels ♪@Fade rate,# of pixels;,!;!;mp12=0,ssim=0"; // Pixels, Beatsin /////////////////////////////// @@ -6755,7 +6755,7 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline. return FRAMETIME; } // mode_blurz() -static const char *_data_FX_MODE_BLURZ PROGMEM = "Blurz ♫@Fade rate,Blur amount;!,Color mix;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_BLURZ PROGMEM = "Blurz ♫@Fade rate,Blur amount;!,Color mix;!;mp12=0,ssim=0"; // Pixels, Beatsin ///////////////////////// @@ -6792,7 +6792,7 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil return FRAMETIME; } // mode_DJLight() -static const char *_data_FX_MODE_DJLIGHT PROGMEM = "DJ Light ♫@Speed;;;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_DJLIGHT PROGMEM = "DJ Light ♫@Speed;;;mp12=2,ssim=0"; // Circle, Beatsin //////////////////// @@ -6822,7 +6822,7 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN. return FRAMETIME; } // mode_freqmap() -static const char *_data_FX_MODE_FREQMAP PROGMEM = "Freqmap ♫@Fade rate,Starting color;,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_FREQMAP PROGMEM = "Freqmap ♫@Fade rate,Starting color;,!;!;mp12=2,ssim=0"; // Circle, Beatsin /////////////////////// @@ -6872,7 +6872,7 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch return FRAMETIME; } // mode_freqmatrix() -static const char *_data_FX_MODE_FREQMATRIX PROGMEM = "Freqmatrix ♫@Time delay,Sound effect,Low bin,High bin,Sensivity;;;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_FREQMATRIX PROGMEM = "Freqmatrix ♫@Time delay,Sound effect,Low bin,High bin,Sensivity;;;mp12=0,ssim=0"; // Pixels, Beatsin ////////////////////// @@ -6902,7 +6902,7 @@ uint16_t mode_freqpixels(void) { // Freqpixel. By Andrew Tuline. return FRAMETIME; } // mode_freqpixels() -static const char *_data_FX_MODE_FREQPIXELS PROGMEM = "Freqpixels ♫@Fade rate,Starting colour and # of pixels;;;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_FREQPIXELS PROGMEM = "Freqpixels ♫@Fade rate,Starting colour and # of pixels;;;mp12=0,ssim=0"; // Pixels, Beatsin ////////////////////// @@ -6969,7 +6969,7 @@ uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschun return FRAMETIME; } // mode_freqwave() -static const char *_data_FX_MODE_FREQWAVE PROGMEM = "Freqwave ♫@Time delay,Sound effect,Low bin,High bin,Pre-amp;;;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_FREQWAVE PROGMEM = "Freqwave ♫@Time delay,Sound effect,Low bin,High bin,Pre-amp;;;mp12=2,ssim=0"; // Circle, Beatsin /////////////////////// @@ -7019,7 +7019,7 @@ uint16_t mode_gravfreq(void) { // Gravfreq. By Andrew Tuline. return FRAMETIME; } // mode_gravfreq() -static const char *_data_FX_MODE_GRAVFREQ PROGMEM = "Gravfreq ♫@Rate of fall,Sensivity=128;,!;!;mp12=2,ssim=1"; // Circle, Beatsin +static const char *_data_FX_MODE_GRAVFREQ PROGMEM = "Gravfreq ♫@Rate of fall,Sensivity=128;,!;!;mp12=2,ssim=0"; // Circle, Beatsin ////////////////////// @@ -7045,7 +7045,7 @@ uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuli return FRAMETIME; } // mode_noisemove() -static const char *_data_FX_MODE_NOISEMOVE PROGMEM = "Noisemove ♫@Speed of perlin movement,Fade rate;,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_NOISEMOVE PROGMEM = "Noisemove ♫@Speed of perlin movement,Fade rate;,!;!;mp12=0,ssim=0"; // Pixels, Beatsin ////////////////////// @@ -7082,7 +7082,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac return FRAMETIME; } // mode_rocktaves() -static const char *_data_FX_MODE_ROCKTAVES PROGMEM = "Rocktaves ♫@;,!;!;mp12=0,ssim=1"; // Pixels, Beatsin +static const char *_data_FX_MODE_ROCKTAVES PROGMEM = "Rocktaves ♫@;,!;!;mp12=0,ssim=0"; // Pixels, Beatsin /////////////////////// @@ -7128,7 +7128,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin return FRAMETIME; } // mode_waterfall() -static const char *_data_FX_MODE_WATERFALL PROGMEM = "Waterfall ♫@!,Adjust color,,Select bin, Volume (minimum)=0;!,!;!;mp12=2,ssim=1"; // Circles, Beatsin +static const char *_data_FX_MODE_WATERFALL PROGMEM = "Waterfall ♫@!,Adjust color,,Select bin, Volume (minimum)=0;!,!;!;mp12=2,ssim=0"; // Circles, Beatsin #ifndef WLED_DISABLE_2D @@ -7185,7 +7185,7 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma. return FRAMETIME; } // mode_2DGEQ() -static const char *_data_FX_MODE_2DGEQ PROGMEM = "2D GEQ ♫@Fade speed,Ripple decay,# of bands=255,Color bars=64;!,,Peak Color;!=11;ssim=1"; // Beatsin +static const char *_data_FX_MODE_2DGEQ PROGMEM = "2D GEQ ♫@Fade speed,Ripple decay,# of bands=255,Color bars=64;!,,Peak Color;!=11;ssim=0"; // Beatsin ///////////////////////// @@ -7245,7 +7245,7 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil SEGMENT.setPixels(leds); return FRAMETIME; } // mode_2DFunkyPlank -static const char *_data_FX_MODE_2DFUNKYPLANK PROGMEM = "2D Funky Plank ♫@Scroll speed,,# of bands;;;ssim=1"; // Beatsin +static const char *_data_FX_MODE_2DFUNKYPLANK PROGMEM = "2D Funky Plank ♫@Scroll speed,,# of bands;;;ssim=0"; // Beatsin #endif // WLED_DISABLE_2D @@ -7355,7 +7355,7 @@ uint16_t mode_2DAkemi(void) { return FRAMETIME; } // mode_2DAkemi -static const char *_data_FX_MODE_2DAKEMI PROGMEM = "2D Akemi@Color speed,Dance;Head palette,Arms & Legs,Eyes & Mouth;Face palette;ssim=1"; //beatsin +static const char *_data_FX_MODE_2DAKEMI PROGMEM = "2D Akemi@Color speed,Dance;Head palette,Arms & Legs,Eyes & Mouth;Face palette;ssim=0"; //beatsin #endif // WLED_DISABLE_2D From 66da57f375138809b116d309743b47a065642b89 Mon Sep 17 00:00:00 2001 From: ewowi Date: Sun, 31 Jul 2022 12:38:10 +0200 Subject: [PATCH 02/10] POC to use leds array in strip.set/getPixelColor --- wled00/FX.h | 7 ++++++- wled00/FX_2Dfcn.cpp | 7 ++++++- wled00/FX_fcn.cpp | 22 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 7f66f074e..8ec7b44db 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -609,6 +609,10 @@ class WS2812FX { // 96 bytes public: + // FastLED array, so we can refer to leds[i] instead of getPixel() and setPixel() + uint32_t *leds = nullptr ; //See FX_fcn.cpp for init (wip). + //Type is uint32_t as with CRGB assigning CRGB to uint32_t in gPC not implemented (yet) in pixeltypes.h, + WS2812FX() : gammaCorrectBri(false), gammaCorrectCol(true), @@ -716,7 +720,8 @@ class WS2812FX { // 96 bytes hasRGBWBus(void), hasCCTBus(void), // return true if the strip is being sent pixel updates - isUpdating(void); + isUpdating(void), + useLedsArray = true; inline bool isServicing(void) { return _isServicing; } inline bool hasWhiteChannel(void) {return _hasWhiteChannel;} diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 635300801..681c661e0 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -116,6 +116,8 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col) uint16_t index = y * matrixWidth + x; if (index >= _length) return; if (index < customMappingSize) index = customMappingTable[index]; + if (useLedsArray) + leds[index] = col; busses.setPixelColor(index, col); #endif } @@ -126,7 +128,10 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) { uint16_t index = (y * matrixWidth + x); if (index >= _length) return 0; if (index < customMappingSize) index = customMappingTable[index]; - return busses.getPixelColor(index); + if (useLedsArray) + return leds[index]; + else + return busses.getPixelColor(index); #else return 0; #endif diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index a4cb9c486..34328f746 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -825,6 +825,17 @@ void WS2812FX::service() { if (nowUp - _lastShow < MIN_SHOW_DELAY) return; bool doShow = false; + //initialize leds array. Move to better place then service??? TBD: realloc if nr of leds change + if (useLedsArray) { + // if (leds != nullptr && sizeof(leds) / sizeof(uint32_t) != _length) { + // free(leds); + // leds = nullptr; + // } + if (leds == nullptr) { + leds = (uint32_t*) malloc(sizeof(uint32_t) * _length); + } + } + _isServicing = true; _segment_index = 0; for (segment &seg : _segments) { @@ -918,17 +929,23 @@ void WS2812FX::setPixelColor(int i, uint32_t col) if (indexMir >= seg.stop) indexMir -= len; // wrap if (indexMir < customMappingSize) indexMir = customMappingTable[indexMir]; + if (useLedsArray) + leds[indexMir] = col; busses.setPixelColor(indexMir, col); } indexSet += seg.offset; // offset/phase if (indexSet >= seg.stop) indexSet -= len; // wrap if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; + if (useLedsArray) + leds[indexSet] = col; busses.setPixelColor(indexSet, col); } } } else { if (i < customMappingSize) i = customMappingTable[i]; + if (useLedsArray) + leds[i] = col; busses.setPixelColor(i, col); } } @@ -940,7 +957,10 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) //if (isMatrix) return getPixelColorXY(i%matrixWidth, i/matrixWidth); // compatibility w/ non-effect fn //#endif if (i < customMappingSize) i = customMappingTable[i]; - return busses.getPixelColor(i); + if (useLedsArray) + return leds[i]; + else + return busses.getPixelColor(i); } From 69f9a484ca3b6defcf246fca547bec33fa141bd9 Mon Sep 17 00:00:00 2001 From: ewowi Date: Sun, 31 Jul 2022 14:48:00 +0200 Subject: [PATCH 03/10] strip.leds array fully fastLed and segment compatible - leds array from uint32_t to CRGB for fastled compatibility - reading and writing leds from strip to segment sPC/gPC so it has logical instead of physical indexes so it can be used in effects - change mode_2DBlackHole as showcase how it can both work with leds or with sPC/gPC --- wled00/FX.cpp | 25 +++++++++++++++---------- wled00/FX.h | 3 +-- wled00/FX_2Dfcn.cpp | 13 +++++++------ wled00/FX_fcn.cpp | 20 +++++++++----------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 457186001..b3eaca4ac 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4565,38 +4565,41 @@ 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 + // 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.allocateData(dataSize)) return mode_static(); //allocation failed + // CRGB *leds = reinterpret_cast(SEGENV.data); uint16_t x, y; // initialize on first call if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(strip.leds, CRGB::Black); } - SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails + SEGMENT.fadeToBlackBy(strip.leds, 16 + (SEGMENT.speed>>3)); // create fading trails float t = (float)(millis())/128; // timebase // outer stars for (size_t i = 0; i < 8; i++) { x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i); y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i); - leds[XY(x,y)] += CHSV(i*32, 255, 255); + strip.leds[XY(x,y)] += CHSV(i*32, 255, 255); + // SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255)); } // inner stars for (size_t i = 0; i < 4; i++) { x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i); y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i); - leds[XY(x,y)] += CHSV(i*32, 255, 255); + strip.leds[XY(x,y)] += CHSV(i*32, 255, 255); + // SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255)); } // central white dot - leds[XY(cols/2,rows/2)] = CHSV(0,0,255); + strip.leds[XY(cols/2,rows/2)] = CHSV(0,0,255); + // SEGMENT.setPixelColorXY(cols/2,rows/2, CHSV(0,0,255)); // blur everything a bit - SEGMENT.blur2d(leds, 16); + SEGMENT.blur2d(strip.leds, 16); - SEGMENT.setPixels(leds); + SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DBlackHole() static const char *_data_FX_MODE_2DBLACKHOLE PROGMEM = "2D Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;"; @@ -6006,7 +6009,9 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli um_data = simulateSound(SEGMENT.soundSim); } uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; + #ifdef ESP32 float FFT_MajorPeak = *(float*) um_data->u_data[4]; + #endif uint8_t *maxVol = (uint8_t*)um_data->u_data[6]; uint8_t *binNum = (uint8_t*)um_data->u_data[7]; diff --git a/wled00/FX.h b/wled00/FX.h index 8ec7b44db..35bf7a611 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -610,8 +610,7 @@ class WS2812FX { // 96 bytes public: // FastLED array, so we can refer to leds[i] instead of getPixel() and setPixel() - uint32_t *leds = nullptr ; //See FX_fcn.cpp for init (wip). - //Type is uint32_t as with CRGB assigning CRGB to uint32_t in gPC not implemented (yet) in pixeltypes.h, + CRGB *leds = nullptr ; //See FX_fcn.cpp for init (wip). WS2812FX() : gammaCorrectBri(false), diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 681c661e0..64bcbc5c1 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -116,8 +116,6 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col) uint16_t index = y * matrixWidth + x; if (index >= _length) return; if (index < customMappingSize) index = customMappingTable[index]; - if (useLedsArray) - leds[index] = col; busses.setPixelColor(index, col); #endif } @@ -128,9 +126,6 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) { uint16_t index = (y * matrixWidth + x); if (index >= _length) return 0; if (index < customMappingSize) index = customMappingTable[index]; - if (useLedsArray) - return leds[index]; - else return busses.getPixelColor(index); #else return 0; @@ -180,6 +175,8 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) uint16_t xX = (x+g), yY = (y+j); 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.setPixelColorXY(start + xX, startY + yY, col); if (getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel @@ -253,7 +250,11 @@ uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) { x *= groupLength(); // expand to physical pixels y *= groupLength(); // expand to physical pixels if (x >= width() || y >= height()) return 0; - return strip.getPixelColorXY(start + x, startY + y); + if (strip.useLedsArray) { + CRGB led = strip.leds[start + x + (startY + y) * strip.matrixWidth]; + return led.r * 65536 + led.g * 256 + led.b; + } + return strip.getPixelColorXY(start + x, startY + y); #else return 0; #endif diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 34328f746..6a50ae472 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -464,6 +464,8 @@ 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.setPixelColor(indexSet, col); } } @@ -527,7 +529,12 @@ uint32_t Segment::getPixelColor(uint16_t i) /* offset/phase */ i += offset; if (i >= stop) i -= length(); - return strip.getPixelColor(i); + if (strip.useLedsArray) { + CRGB led = strip.leds[i]; + return led.r * 65536 + led.g * 256 + led.b; + } + else + return strip.getPixelColor(i); } uint8_t Segment::differs(Segment& b) { @@ -832,7 +839,7 @@ void WS2812FX::service() { // leds = nullptr; // } if (leds == nullptr) { - leds = (uint32_t*) malloc(sizeof(uint32_t) * _length); + leds = (CRGB*) malloc(sizeof(CRGB) * _length); } } @@ -929,23 +936,17 @@ void WS2812FX::setPixelColor(int i, uint32_t col) if (indexMir >= seg.stop) indexMir -= len; // wrap if (indexMir < customMappingSize) indexMir = customMappingTable[indexMir]; - if (useLedsArray) - leds[indexMir] = col; busses.setPixelColor(indexMir, col); } indexSet += seg.offset; // offset/phase if (indexSet >= seg.stop) indexSet -= len; // wrap if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; - if (useLedsArray) - leds[indexSet] = col; busses.setPixelColor(indexSet, col); } } } else { if (i < customMappingSize) i = customMappingTable[i]; - if (useLedsArray) - leds[i] = col; busses.setPixelColor(i, col); } } @@ -957,9 +958,6 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) //if (isMatrix) return getPixelColorXY(i%matrixWidth, i/matrixWidth); // compatibility w/ non-effect fn //#endif if (i < customMappingSize) i = customMappingTable[i]; - if (useLedsArray) - return leds[i]; - else return busses.getPixelColor(i); } From 004c2920f5354f0658bb44264885a67c21e8e0fe Mon Sep 17 00:00:00 2001 From: ewowi Date: Mon, 1 Aug 2022 16:11:59 +0200 Subject: [PATCH 04/10] All effects use strip.leds, refactor XY - remove leds out of SEGMENT.data (remove if no other use of data) - use strip.leds - refactor XY to make segment relative to the whole matrix - use RGBW32 - in case of 1D also use XY in leds[]: XY(i%width, i/width)] - add ps_malloc --- wled00/FX.cpp | 406 +++++++++++++++++--------------------------- wled00/FX_2Dfcn.cpp | 10 +- wled00/FX_fcn.cpp | 17 +- 3 files changed, 175 insertions(+), 258 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index b3eaca4ac..ae5abe0e3 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 64bcbc5c1..002f5fcda 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 6a50ae472..32e9f88f4 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; From 2ca5e0c8b8c17d85f1361f04ba7233010f8f916c Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 12:19:04 +0200 Subject: [PATCH 05/10] Remove leds from FX.cpp - add addPixelColor overloads - remove setPixels function - sPC/gPC move leds check to beginning - refactor wu_pixel work without leds - remove leds out of effects and replace by sPC/gPC/aPC/nullptr - workaround %= - refactor game of life (but need to check patterns / history, see SR) - refactor fill_circle to work without leds --- wled00/FX.cpp | 299 ++++++++++++++++++++------------------------ wled00/FX.h | 7 +- wled00/FX_2Dfcn.cpp | 50 ++++---- wled00/FX_fcn.cpp | 17 +-- 4 files changed, 176 insertions(+), 197 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index ae5abe0e3..1a21c3912 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4570,32 +4570,28 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma // initialize on first call if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); } - SEGMENT.fadeToBlackBy(strip.leds, 16 + (SEGMENT.speed>>3)); // create fading trails + SEGMENT.fadeToBlackBy(nullptr, 16 + (SEGMENT.speed>>3)); // create fading trails float t = (float)(millis())/128; // timebase // outer stars for (size_t i = 0; i < 8; i++) { x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i); y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i); - strip.leds[XY(x,y)] += CHSV(i*32, 255, 255); - // SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255)); + SEGMENT.addPixelColorXY(x, y, CHSV(i*32, 255, 255)); } // inner stars for (size_t i = 0; i < 4; i++) { x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i); y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i); - strip.leds[XY(x,y)] += CHSV(i*32, 255, 255); - // SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255)); + SEGMENT.addPixelColorXY(x, y, CHSV(i*32, 255, 255)); } // central white dot - strip.leds[XY(cols/2,rows/2)] = CHSV(0,0,255); - // SEGMENT.setPixelColorXY(cols/2,rows/2, CHSV(0,0,255)); + SEGMENT.setPixelColorXY(cols/2,rows/2, CHSV(0,0,255)); // blur everything a bit - SEGMENT.blur2d(strip.leds, 16); + SEGMENT.blur2d(nullptr, 16); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DBlackHole() static const char *_data_FX_MODE_2DBLACKHOLE PROGMEM = "2D Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;"; @@ -4611,8 +4607,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); - //for (uint16_t i = 0; i < w*h; i++) leds[i] = CRGB::Black; + SEGMENT.fill_solid(nullptr, CRGB::Black); SEGENV.aux0 = 0; // start with red hue } @@ -4622,7 +4617,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so byte numLines = SEGMENT.intensity/16 + 1; SEGENV.aux0++; // hue - SEGMENT.fadeToBlackBy(strip.leds, 40); + SEGMENT.fadeToBlackBy(nullptr, 40); for (size_t i = 0; i < numLines; i++) { byte x1 = beatsin8(2 + SEGMENT.speed/16, 0, (cols - 1)); @@ -4638,19 +4633,19 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so for (size_t i = 1; i <= steps; i++) { byte dx = lerp8by8(x1, y1, i * 255 / steps); byte dy = lerp8by8(x2, y2, i * 255 / steps); - int index = XY(dx, dy); - strip.leds[index] += color; // change to += for brightness look - if (grad) strip.leds[index] %= (i * 255 / steps); //Draw gradient line + SEGMENT.addPixelColorXY(dx, dy, color); // change to += for brightness look + CRGB color = SEGMENT.getPixelColorXY(dx,dy); + color %= (i * 255 / steps); + if (grad) SEGMENT.setPixelColorXY(dx, dy, color); //Draw gradient line } if (dot) { //add white point at the ends of line - strip.leds[XY(x1, x2)] += CRGB::White; - strip.leds[XY(y1, y2)] += CRGB::White; + SEGMENT.addPixelColorXY(x1, x2, CRGB::White); + SEGMENT.addPixelColorXY(y1, y2, CRGB::White); } } - SEGMENT.blur2d(strip.leds, 4); + SEGMENT.blur2d(nullptr, 4); - 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;;!"; @@ -4665,17 +4660,16 @@ 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(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); - SEGMENT.fadeToBlackBy(strip.leds, 64); + SEGMENT.fadeToBlackBy(nullptr, 64); for(int i = 0; i < cols; i++) { - 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.setPixelColorXY(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)); + SEGMENT.setPixelColorXY(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(strip.leds, SEGMENT.intensity/8); + SEGMENT.blur2d(nullptr, SEGMENT.intensity/8); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2Ddna() static const char *_data_FX_MODE_2DDNA PROGMEM = "2D DNA@Scroll speed,Blur;1,2,3;!"; @@ -4691,7 +4685,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); SEGENV.aux0 = 0; // hue } @@ -4699,7 +4693,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma uint8_t freq = SEGMENT.intensity/8; uint32_t ms = millis() / 20; - SEGMENT.nscale8(strip.leds, 120); + SEGMENT.nscale8(nullptr, 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); @@ -4710,16 +4704,16 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma byte steps = abs8(x - x1) + 1; for (size_t k = 1; k <= steps; k++) { byte dx = lerp8by8(x, x1, k * 255 / steps); - uint16_t index = XY(dx, i); - strip.leds[index] += ColorFromPalette(SEGPALETTE, SEGENV.aux0, 255, LINEARBLEND); - strip.leds[index] %= (k * 255 / steps); //for draw gradient line + SEGMENT.addPixelColorXY(dx, i, ColorFromPalette(SEGPALETTE, SEGENV.aux0, 255, LINEARBLEND)); + CRGB color = SEGMENT.getPixelColorXY(dx,i); + color %= (k * 255 / steps); + SEGMENT.setPixelColorXY(dx, i, color); } - strip.leds[XY(x, i)] += CRGB::DarkSlateGray; - strip.leds[XY(x1, i)] += CRGB::White; + SEGMENT.addPixelColorXY(x, i, CRGB::DarkSlateGray); + SEGMENT.addPixelColorXY(x1, i, CRGB::White); } } - 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;;!"; @@ -4734,11 +4728,9 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - //if (cols<8 || rows<8) return mode_static(); // makes no sense to run on smaller than 8x8 + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); - - SEGMENT.fadeToBlackBy(strip.leds, 128); + SEGMENT.fadeToBlackBy(nullptr, 128); const uint16_t maxDim = MAX(cols, rows)/2; unsigned long t = millis() / (32 - (SEGMENT.speed>>3)); @@ -4746,11 +4738,10 @@ 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); - strip.leds[XY(myX,myY)] = ColorFromPalette(SEGPALETTE, (i * 20) + (t / 20), 255, LINEARBLEND); + SEGMENT.setPixelColorXY(myX,myY, ColorFromPalette(SEGPALETTE, (i * 20) + (t / 20), 255, LINEARBLEND)); } - SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DDrift() static const char *_data_FX_MODE_2DDRIFT PROGMEM = "2D Drift@Rotation speed,Blur amount;;!"; @@ -4765,7 +4756,7 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); uint16_t xscale = SEGMENT.intensity*4; uint32_t yscale = SEGMENT.speed*8; @@ -4779,11 +4770,10 @@ 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. - 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. + SEGMENT.setPixelColorXY(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(strip.leds); return FRAMETIME; } // mode_2Dfirenoise() static const char *_data_FX_MODE_2DFIRENOISE PROGMEM = "2D Firenoise@X scale,Y scale;;"; @@ -4798,15 +4788,14 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); - SEGMENT.fadeToBlackBy(strip.leds, 16); + SEGMENT.fadeToBlackBy(nullptr, 16); for (size_t i = 8; i > 0; i--) { - 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.setPixelColorXY(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(strip.leds, 16); + SEGMENT.blur2d(nullptr, 16); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DFrizzles() static const char *_data_FX_MODE_2DFRIZZLES PROGMEM = "2D Frizzles@X frequency,Y frequency;;!"; @@ -4843,9 +4832,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) - strip.leds[XY(x,y)] = backgroundColor; + SEGMENT.setPixelColorXY(x,y, backgroundColor); else - strip.leds[XY(x,y)] = (CRGB)SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0); + SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); } SEGMENT.fill_solid(prevLeds, CRGB::Black); @@ -4855,7 +4844,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)] = strip.leds[XY(x,y)]; + for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) prevLeds[XY(x,y)] = SEGMENT.getPixelColorXY(x,y); //calculate new leds for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) { @@ -4887,20 +4876,20 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: } // i,j // Rules of Life - 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 + if ((SEGMENT.getPixelColorXY(x,y) != RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0)) && (neighbors < 2)) SEGMENT.setPixelColorXY(x,y, backgroundColor); // Loneliness + else if ((SEGMENT.getPixelColorXY(x,y) != RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0)) && (neighbors > 3)) SEGMENT.setPixelColorXY(x,y, backgroundColor); // Overpopulation + else if ((SEGMENT.getPixelColorXY(x,y) == RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0)) && (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) strip.leds[XY(x,y)] = dominantColorCount.color; //assign the dominant color + if (dominantColorCount.count > 0) SEGMENT.setPixelColorXY(x,y, dominantColorCount.color); //assign the dominant color } // else do nothing! } //x,y // calculate CRC16 of leds[] - uint16_t crc = crc16((const unsigned char*)strip.leds, dataSize-1); + uint16_t crc = crc16((const unsigned char*)prevLeds, dataSize-1); //ewowi: prevLeds instead of leds work as well, tbd: compare more patterns, see SR! // check if we had same CRC and reset if needed // same CRC would mean image did not change or was repeating itself @@ -4909,7 +4898,6 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: SEGENV.aux1 = SEGENV.aux0; SEGENV.aux0 = crc; - 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@!,;!,!;!"; @@ -5090,7 +5078,7 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, 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 @@ -5109,22 +5097,25 @@ 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 -2) && (x - y < 2)) || + SEGMENT.addPixelColorXY(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) || ((rows - cy == 0) || - (rows - 1 - cy == 0)) ? ColorFromPalette(SEGPALETTE, beat8(5), thisVal, LINEARBLEND) : CRGB::Black; + (rows - 1 - cy == 0)) ? ColorFromPalette(SEGPALETTE, beat8(5), thisVal, LINEARBLEND) : CRGB::Black); } } - SEGMENT.blur2d(strip.leds, 4); + SEGMENT.blur2d(nullptr, 4); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DPlasmaball() static const char *_data_FX_MODE_2DPLASMABALL PROGMEM = "2D Plasma Ball@Speed;!,!,!;!"; @@ -5283,7 +5271,7 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https if (SEGENV.call == 0) { SEGENV.step = 0; - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); } float adjustHeight = (float)map(rows, 8, 32, 28, 12); @@ -5309,14 +5297,13 @@ 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++; - strip.leds[XY(x, y)] = ColorFromPalette(auroraPalette, + SEGMENT.setPixelColorXY(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)); + fabs((float)rows / 2 - (float)y) * adjustHeight))); } } - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DPolarLights() static const char *_data_FX_MODE_2DPOLARLIGHTS PROGMEM = "2D Polar Lights@Speed,Scale;;"; @@ -5331,19 +5318,17 @@ uint16_t mode_2DPulser(void) { // By: ldirko https://edi //const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); - SEGMENT.fadeToBlackBy(strip.leds, 8 - (SEGMENT.intensity>>5)); + SEGMENT.fadeToBlackBy(nullptr, 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 - strip.leds[index] = ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND); + SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND)); - SEGMENT.blur2d(strip.leds, 1 + (SEGMENT.intensity>>4)); + SEGMENT.blur2d(nullptr, 1 + (SEGMENT.intensity>>4)); - 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;;!"; @@ -5358,19 +5343,18 @@ uint16_t mode_2DSindots(void) { // By: ldirko http const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); - SEGMENT.fadeToBlackBy(strip.leds, 15); + SEGMENT.fadeToBlackBy(nullptr, 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! - strip.leds[XY(x, y)] = ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND); + SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND)); } - SEGMENT.blur2d(strip.leds, 16); + SEGMENT.blur2d(nullptr, 16); - 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;;!"; @@ -5387,13 +5371,13 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); const uint8_t kBorderWidth = 2; - SEGMENT.fadeToBlackBy(strip.leds, 24); + SEGMENT.fadeToBlackBy(nullptr, 24); uint8_t blurAmount = SEGMENT.custom3>>4; - SEGMENT.blur2d(strip.leds, blurAmount); + SEGMENT.blur2d(nullptr, blurAmount); // Use two out-of-sync sine waves uint8_t i = beatsin8(19, kBorderWidth, cols-kBorderWidth); @@ -5405,11 +5389,10 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g uint16_t ms = millis(); - 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.addPixelColorXY(i, m, ColorFromPalette(SEGPALETTE, ms/29, 255, LINEARBLEND)); + SEGMENT.addPixelColorXY(j, n, ColorFromPalette(SEGPALETTE, ms/41, 255, LINEARBLEND)); + SEGMENT.addPixelColorXY(k, p, ColorFromPalette(SEGPALETTE, ms/73, 255, LINEARBLEND)); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2Dsquaredswirl() static const char *_data_FX_MODE_2DSQUAREDSWIRL PROGMEM = "2D Squared Swirl@,,,,Blur;,,;!"; @@ -5427,7 +5410,7 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi 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(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); unsigned long t = millis() / 4; int index = 0; @@ -5453,12 +5436,11 @@ 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; - strip.leds[XY(x, y)] = HeatColor(col / (3.0f-(float)(SEGMENT.intensity)/128.f)); + SEGMENT.setPixelColorXY(x, y, HeatColor(col / (3.0f-(float)(SEGMENT.intensity)/128.f))); } yindex += (cols + 2); } - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DSunradiation() static const char *_data_FX_MODE_2DSUNRADIATION PROGMEM = "2D Sun Radiation@Variance,Brightness;;"; @@ -5473,7 +5455,7 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); uint8_t hue; int offsetX = beatsin16(3, -360, 360); @@ -5481,15 +5463,13 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so for (uint16_t x = 0; x < cols; x++) { for (uint16_t y = 0; y < rows; y++) { - uint16_t index = XY(x, y); hue = x * beatsin16(10, 1, 10) + offsetY; - strip.leds[index] = ColorFromPalette(SEGPALETTE, hue, sin8(x * SEGMENT.speed + offsetX) * sin8(x * SEGMENT.speed + offsetX) / 255, LINEARBLEND); + SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, hue, sin8(x * SEGMENT.speed + offsetX) * sin8(x * SEGMENT.speed + offsetX) / 255, LINEARBLEND)); hue = y * 3 + offsetX; - strip.leds[index] += ColorFromPalette(SEGPALETTE, hue, sin8(y * SEGMENT.intensity + offsetY) * sin8(y * SEGMENT.intensity + offsetY) / 255, LINEARBLEND); + SEGMENT.addPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, hue, sin8(y * SEGMENT.intensity + offsetY) * sin8(y * SEGMENT.intensity + offsetY) / 255, LINEARBLEND)); } } - 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;;!"; @@ -5504,7 +5484,7 @@ 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(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); uint32_t tb = strip.now >> 12; // every ~4s if (tb > SEGENV.step) { @@ -5516,23 +5496,22 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht SEGENV.step = tb + random8(4); } - SEGMENT.fadeToBlackBy(strip.leds, map(SEGMENT.speed, 0, 255, 248, 16)); - SEGMENT.move(SEGENV.aux0, 1, strip.leds); + SEGMENT.fadeToBlackBy(nullptr, map(SEGMENT.speed, 0, 255, 248, 16)); + SEGMENT.move(SEGENV.aux0, 1, nullptr); 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); - strip.leds[XY(x, y)] += color; + SEGMENT.addPixelColorXY(x, y, color); if (cols > 24 || rows > 24) { - 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.addPixelColorXY(x + 1, y, color); + SEGMENT.addPixelColorXY(x - 1, y, color); + SEGMENT.addPixelColorXY(x, y + 1, color); + SEGMENT.addPixelColorXY(x, y - 1, color); } } - SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DSPACESHIPS PROGMEM = "2D Spaceships@!,Blur;!,!,!;!"; @@ -5571,7 +5550,7 @@ uint16_t mode_2Dcrazybees(void) { bee_t *bee = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); for (size_t i = 0; i < n; i++) { bee[i].posX = random8(0, cols); bee[i].posY = random8(0, rows); @@ -5582,15 +5561,15 @@ uint16_t mode_2Dcrazybees(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + (FRAMETIME * 8 / ((SEGMENT.speed>>5)+1)); - SEGMENT.fadeToBlackBy(strip.leds, 32); + SEGMENT.fadeToBlackBy(nullptr, 32); for (size_t i = 0; i < n; i++) { - 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); + SEGMENT.addPixelColorXY(bee[i].aimX + 1, bee[i].aimY, CHSV(bee[i].hue, 255, 255)); + SEGMENT.addPixelColorXY(bee[i].aimX, bee[i].aimY + 1, CHSV(bee[i].hue, 255, 255)); + SEGMENT.addPixelColorXY(bee[i].aimX - 1, bee[i].aimY, CHSV(bee[i].hue, 255, 255)); + SEGMENT.addPixelColorXY(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) { - strip.leds[XY(bee[i].posX, bee[i].posY)] = CHSV(bee[i].hue, 60, 255); + SEGMENT.setPixelColorXY(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; @@ -5604,9 +5583,8 @@ uint16_t mode_2Dcrazybees(void) { bee[i].aimed(cols, rows); } } - SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>4); + SEGMENT.blur2d(nullptr, SEGMENT.intensity>>4); - SEGMENT.setPixels(strip.leds); } return FRAMETIME; } @@ -5645,7 +5623,7 @@ uint16_t mode_2Dghostrider(void) { if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); random16_set_seed(strip.now); lighter->angleSpeed = random8(0,20) - 10; lighter->Vspeed = 5; @@ -5661,10 +5639,10 @@ uint16_t mode_2Dghostrider(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + 1024 / (cols+rows); - SEGMENT.fadeToBlackBy(strip.leds, (SEGMENT.speed>>2)+64); + SEGMENT.fadeToBlackBy(nullptr, (SEGMENT.speed>>2)+64); CRGB color = CRGB::White; - SEGMENT.wu_pixel(strip.leds, lighter->gPosX * 256 / 10, lighter->gPosY * 256 / 10, color); + SEGMENT.wu_pixel(nullptr, 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)); @@ -5692,12 +5670,11 @@ 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(strip.leds, lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); + SEGMENT.wu_pixel(nullptr, lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); } - SEGMENT.blur2d(strip.leds, SEGMENT.intensity>>3); + SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); } - SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DGHOSTRIDER PROGMEM = "2D Ghost Rider@Fade rate,Blur;!,!,!;!"; @@ -5730,7 +5707,7 @@ uint16_t mode_2Dfloatingblobs(void) { if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, 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 @@ -5744,7 +5721,7 @@ uint16_t mode_2Dfloatingblobs(void) { } } - SEGMENT.fadeToBlackBy(strip.leds, 20); + SEGMENT.fadeToBlackBy(nullptr, 20); // Bounce balls around for (size_t i = 0; i < Amount; i++) { @@ -5765,8 +5742,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(strip.leds, blob->y[i], blob->x[i], blob->r[i], c); - else strip.leds[XY(blob->y[i], blob->x[i])] += c; + if (blob->r[i] > 1.f) SEGMENT.fill_circle(nullptr, blob->y[i], blob->x[i], blob->r[i], c); + else SEGMENT.addPixelColorXY(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)); @@ -5794,11 +5771,10 @@ uint16_t mode_2Dfloatingblobs(void) { blob->y[i] = rows - 1.01f; } } - SEGMENT.blur2d(strip.leds, cols+rows); + SEGMENT.blur2d(nullptr, cols+rows); if (SEGENV.step < millis()) SEGENV.step = millis() + 2000; // change colors every 2 seconds - SEGMENT.setPixels(strip.leds); return FRAMETIME; } #undef MAX_BLOBS @@ -5870,18 +5846,17 @@ uint16_t mode_2Ddriftrose(void) { const float L = min(cols, rows) / 2.f; if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); } - SEGMENT.fadeToBlackBy(strip.leds, 32+(SEGMENT.speed>>3)); + SEGMENT.fadeToBlackBy(nullptr, 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(strip.leds, x, y, CHSV(i * 10, 255, 255)); + SEGMENT.wu_pixel(nullptr, x, y, CHSV(i * 10, 255, 255)); } - SEGMENT.blur2d(strip.leds, (SEGMENT.intensity>>4)+1); + SEGMENT.blur2d(nullptr, (SEGMENT.intensity>>4)+1); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;;"; @@ -6007,11 +5982,11 @@ uint16_t mode_2DSwirl(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(strip.leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); const uint8_t borderWidth = 2; - SEGMENT.blur2d(strip.leds, SEGMENT.custom1); + SEGMENT.blur2d(nullptr, SEGMENT.custom1); uint8_t i = beatsin8( 27*SEGMENT.speed/255, borderWidth, cols - borderWidth); uint8_t j = beatsin8( 41*SEGMENT.speed/255, borderWidth, rows - borderWidth); @@ -6029,14 +6004,13 @@ uint16_t mode_2DSwirl(void) { // printUmData(); - 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.addPixelColorXY( i, j, ColorFromPalette(SEGPALETTE, (ms / 11 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 11, 200, 255); + SEGMENT.addPixelColorXY( j, i, ColorFromPalette(SEGPALETTE, (ms / 13 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 13, 200, 255); + SEGMENT.addPixelColorXY(ni, nj, ColorFromPalette(SEGPALETTE, (ms / 17 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 17, 200, 255); + SEGMENT.addPixelColorXY(nj, ni, ColorFromPalette(SEGPALETTE, (ms / 29 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 29, 200, 255); + SEGMENT.addPixelColorXY( i, nj, ColorFromPalette(SEGPALETTE, (ms / 37 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 37, 200, 255); + SEGMENT.addPixelColorXY(ni, j, ColorFromPalette(SEGPALETTE, (ms / 41 + volumeSmth*4), volumeRaw * SEGMENT.intensity / 64, LINEARBLEND)); //CHSV( ms / 41, 200, 255); - 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 @@ -6053,7 +6027,7 @@ uint16_t mode_2DWaverly(void) { const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(strip.leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); } um_data_t *um_data; @@ -6063,7 +6037,7 @@ uint16_t mode_2DWaverly(void) { } float volumeSmth = *(float*) um_data->u_data[0]; - SEGMENT.fadeToBlackBy(strip.leds, SEGMENT.speed); + SEGMENT.fadeToBlackBy(nullptr, SEGMENT.speed); long t = millis() / 2; for (uint16_t i = 0; i < cols; i++) { @@ -6076,13 +6050,12 @@ uint16_t mode_2DWaverly(void) { uint16_t thisMax = map(thisVal, 0, 512, 0, rows); for (uint16_t j = 0; j < thisMax; j++) { - 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.addPixelColorXY(i, j, ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND)); + SEGMENT.addPixelColorXY((cols - 1) - i, (rows - 1) - j, ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND)); } } - SEGMENT.blur2d(strip.leds, 16); + SEGMENT.blur2d(nullptr, 16); - SEGMENT.setPixels(strip.leds); return FRAMETIME; } // mode_2DWaverly() static const char *_data_FX_MODE_2DWAVERLY PROGMEM = "2D Waverly ♪@Amplification,Sensitivity=64;;!;ssim=0"; // Beatsin @@ -6701,13 +6674,12 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil if (SEGENV.aux0 != secondHand) { // Triggered millis timing. SEGENV.aux0 = secondHand; - 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 + SEGMENT.setPixelColor(mid, CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2)); // 16-> 15 as 16 is out of bounds + CRGB color = SEGMENT.getPixelColor(mid); + SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10))); // TODO - Update - 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 mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left + for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right } return FRAMETIME; @@ -7145,21 +7117,18 @@ 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; - strip.leds[XY(xpos, 0)] = CHSV(hue, 255, v); + SEGMENT.setPixelColorXY(xpos, 0, CHSV(hue, 255, v)); } } // Update the display: for (int i = (rows - 1); i > 0; i--) { for (int j = (cols - 1); j >= 0; j--) { - int src = XY(j, (i - 1)); - int dst = XY(j, i); - strip.leds[dst] = strip.leds[src]; + SEGMENT.setPixelColorXY(j, i-1, SEGMENT.getPixelColorXY(j, i)); } } } - 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.h b/wled00/FX.h index 35bf7a611..238914d7c 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -573,6 +573,8 @@ typedef struct Segment { // 2D support functions void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend); void addPixelColorXY(uint16_t x, uint16_t y, uint32_t color); + void addPixelColorXY(uint16_t x, uint16_t y, byte r, byte g, byte b, byte w = 0) { addPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline + void addPixelColorXY(uint16_t x, uint16_t y, CRGB c) { addPixelColorXY(x, y, c.red, c.green, c.blue); } // automatically inline void blur1d(CRGB* leds, fract8 blur_amount); void blur1d(uint16_t i, bool vertical, fract8 blur_amount, CRGB* leds=nullptr); // 1D box blur (with weight) void blur2d(CRGB* leds, fract8 blur_amount); @@ -585,7 +587,6 @@ typedef struct Segment { void fill_circle(CRGB* leds, uint16_t cx, uint16_t cy, uint8_t radius, CRGB c); void fadeToBlackBy(CRGB* leds, uint8_t fadeBy); void nscale8(CRGB* leds, uint8_t scale); - void setPixels(CRGB* leds); void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c, CRGB *leds = nullptr); void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color, CRGB *leds = nullptr); void wu_pixel(CRGB *leds, uint32_t x, uint32_t y, CRGB c); @@ -813,8 +814,8 @@ class WS2812FX { // 96 bytes setPixelColorXY(int x, int y, uint32_t c); // outsmart the compiler :) by correctly overloading - inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline - inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, c.red, c.green, c.blue); } + // inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline + // inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, c.red, c.green, c.blue); } uint32_t getPixelColorXY(uint16_t, uint16_t); diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 002f5fcda..aaa5ea2a5 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -152,6 +152,9 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) #ifndef WLED_DISABLE_2D if (!strip.isMatrix) return; // not a matrix set-up + if (strip.useLedsArray) + strip.leds[XY(x, y)] = col; + uint8_t _bri_t = strip._bri_t; //uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); if (_bri_t < 255) { @@ -175,8 +178,6 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) uint16_t xX = (x+g), yY = (y+j); if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end - if (strip.useLedsArray) - strip.leds[XY(xX, yY)] = col; strip.setPixelColorXY(start + xX, startY + yY, col); if (getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel @@ -244,17 +245,17 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa) // returns RGBW values of pixel uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) { #ifndef WLED_DISABLE_2D + if (strip.useLedsArray) { + CRGB led = strip.leds[XY(x, y)]; + return RGBW32(led.r, led.g, led.b, 0); + } if (getOption(SEG_OPTION_REVERSED) ) x = virtualWidth() - x - 1; if (getOption(SEG_OPTION_REVERSED_Y)) y = virtualHeight() - y - 1; if (getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed x *= groupLength(); // expand to physical pixels y *= groupLength(); // expand to physical pixels if (x >= width() || y >= height()) return 0; - if (strip.useLedsArray) { - CRGB led = strip.leds[XY(x, y)]; - return RGBW32(led.r, led.g, led.b, 0); - } - return strip.getPixelColorXY(start + x, startY + y); + return strip.getPixelColorXY(start + x, startY + y); #else return 0; #endif @@ -480,8 +481,10 @@ void Segment::fill_circle(CRGB* leds, uint16_t cx, uint16_t cy, uint8_t radius, for (int16_t x = -radius; x <= radius; x++) { if (x * x + y * y <= radius * radius && int16_t(cx)+x>=0 && int16_t(cy)+y>=0 && - int16_t(cx)+x> 8) + (i & 1), (y >> 8) + ((i >> 1) & 1)); - leds[xy].r = qadd8(leds[xy].r, c.r * wu[i] >> 8); - leds[xy].g = qadd8(leds[xy].g, c.g * wu[i] >> 8); - leds[xy].b = qadd8(leds[xy].b, c.b * wu[i] >> 8); + uint16_t xx = (x >> 8) + (i & 1); + uint16_t yy = (y >> 8) + ((i >> 1) & 1); + uint16_t xy = XY(xx, yy); + CRGB color; + if (leds) { + color.r = qadd8(leds[xy].r, c.r * wu[i] >> 8); + color.g = qadd8(leds[xy].g, c.g * wu[i] >> 8); + color.b = qadd8(leds[xy].b, c.b * wu[i] >> 8); + leds[xy] = color; + } + else { + CRGB oColor = getPixelColorXY(xx, yy); + color.r = qadd8(oColor.r, c.r * wu[i] >> 8); + color.g = qadd8(oColor.g, c.g * wu[i] >> 8); + color.b = qadd8(oColor.b, c.b * wu[i] >> 8); + setPixelColorXY(xx, yy, color); + } } #endif } diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 32e9f88f4..22f0c9cc1 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -430,6 +430,9 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) } #endif + if (strip.useLedsArray) + strip.leds[start + i] = col; //ewowi: is this right? + uint16_t len = length(); uint8_t _bri_t = strip._bri_t; //uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); @@ -464,8 +467,6 @@ 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[XY(indexSet%virtualWidth(), indexSet/virtualWidth())] = col; strip.setPixelColor(indexSet, col); } } @@ -523,18 +524,18 @@ uint32_t Segment::getPixelColor(uint16_t i) } #endif + if (strip.useLedsArray) { + CRGB led = strip.leds[start + i]; + return RGBW32(led.r, led.g, led.b, 0); + } + if (getOption(SEG_OPTION_REVERSED)) i = virtualLength() - i - 1; i *= groupLength(); i += start; /* offset/phase */ i += offset; if (i >= stop) i -= length(); - if (strip.useLedsArray) { - CRGB led = strip.leds[XY(i%virtualWidth(), i/virtualWidth())]; - return RGBW32(led.r, led.g, led.b, 0); - } - else - return strip.getPixelColor(i); + return strip.getPixelColor(i); } uint8_t Segment::differs(Segment& b) { From 5f8b8835e10af7e21f6963d9df409722be35334d Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 12:58:35 +0200 Subject: [PATCH 06/10] Leds removal leftovers - Remove leds from 1D SEGMENT.data effects - Noisefire: re-establish own palette - FreqMatrix to circle mapping --- wled00/FX.cpp | 80 +++++++++++++++------------------------------ wled00/FX_2Dfcn.cpp | 3 +- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 61ee2daf8..8b308416a 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3836,7 +3836,7 @@ uint16_t phased_base(uint8_t moder) { // We're making sine wave for (int i = 0; i < SEGLEN; i++) { if (moder == 1) modVal = (inoise8(i*10 + i*10) /16); // Let's randomize our mod length with some Perlin noise. - uint16_t val = (i+1) * allfreq; // This sets the frequency of the waves. The +1 makes sure that leds[0] is used. + uint16_t val = (i+1) * allfreq; // This sets the frequency of the waves. The +1 makes sure that led 0 is used. if (modVal == 0) modVal = 1; val += *phase * (i % modVal +1) /2; // This sets the varying phase change of the waves. By Andrew Tuline. uint8_t b = cubicwave8(val); // Now we make an 8 bit sinewave. @@ -4888,7 +4888,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: // else do nothing! } //x,y - // calculate CRC16 of leds[] + // calculate CRC16 of leds uint16_t crc = crc16((const unsigned char*)prevLeds, dataSize-1); //ewowi: prevLeds instead of leds work as well, tbd: compare more patterns, see SR! // check if we had same CRC and reset if needed @@ -6243,9 +6243,6 @@ static const char *_data_FX_MODE_JUGGLES PROGMEM = "Juggles ♪@!,# of balls;,!; ////////////////////// uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. // even with 1D effect we have to take logic for 2D segments for allocation as fill_solid() fills whole segment - const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled - if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed - CRGB *leds = reinterpret_cast(SEGENV.data); um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { @@ -6254,7 +6251,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. } int16_t volumeRaw = *(int16_t*)um_data->u_data[1]; - if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); uint8_t secondHand = micros()/(256-SEGMENT.speed)/500 % 16; if(SEGENV.aux0 != secondHand) { @@ -6264,7 +6261,6 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. for (uint16_t i=0; i(SEGENV.data); um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { @@ -6663,23 +6649,22 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline. if (!fftResult) return mode_static(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(leds, CRGB::Black); + SEGMENT.fill_solid(nullptr, CRGB::Black); SEGMENT.fill(BLACK); // clear canvas SEGENV.aux0 = 0; } - SEGMENT.fade_out(SEGMENT.speed); // do not fade leds[] but only canvas + SEGMENT.fade_out(SEGMENT.speed); SEGENV.step += FRAMETIME; if (SEGENV.step > SPEED_FORMULA_L) { uint16_t segLoc = random16(SEGLEN); - leds[segLoc] = color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(2*fftResult[SEGENV.aux0%16]*240/(SEGLEN-1), false, PALETTE_SOLID_WRAP, 0), 2*fftResult[SEGENV.aux0%16]); + SEGMENT.setPixelColor(segLoc, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(2*fftResult[SEGENV.aux0%16]*240/(SEGLEN-1), false, PALETTE_SOLID_WRAP, 0), 2*fftResult[SEGENV.aux0%16])); ++(SEGENV.aux0) %= 16; // make sure it doesn't cross 16 SEGENV.step = 1; - if (SEGMENT.is2D()) SEGMENT.blur2d(leds, SEGMENT.intensity); - else SEGMENT.blur1d(leds, SEGMENT.intensity); - for (int i=0; i mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right } - for (int i=0; i(SEGENV.data); um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { @@ -7003,7 +6976,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac float FFT_MajorPeak = *(float*) um_data->u_data[4]; float my_magnitude = *(float*) um_data->u_data[5] / 16.0f; - SEGMENT.fadeToBlackBy(leds, 64); // Just in case something doesn't get faded. + SEGMENT.fadeToBlackBy(nullptr, 64); // Just in case something doesn't get faded. float frTemp = FFT_MajorPeak; uint8_t octCount = 0; // Octave counter. @@ -7019,10 +6992,9 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac frTemp -=132; // This should give us a base musical note of C3 frTemp = fabs(frTemp * 2.1); // Fudge factors to compress octave range starting at 0 and going to 255; -// leds[beatsin8(8+octCount*4,0,SEGLEN-1,0,octCount*8)] += CHSV((uint8_t)frTemp,255,volTemp); // Back and forth with different frequencies and phase shift depending on current octave. +// SEGMENT.addPixelColor(beatsin8(8+octCount*4,0,SEGLEN-1,0,octCount*8), CHSV((uint8_t)frTemp,255,volTemp)); // Back and forth with different frequencies and phase shift depending on current octave. uint16_t i = map(beatsin8(8+octCount*4, 0, 255, 0, octCount*8), 0, 255, 0, SEGLEN-1); - leds[i] += color_blend(SEGCOLOR(1), SEGMENT.color_from_palette((uint8_t)frTemp, false, PALETTE_SOLID_WRAP, 0), volTemp); - for (int x = 0; x < SEGLEN; x++) SEGMENT.setPixelColor(x, leds[x]); + SEGMENT.addPixelColor(i, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette((uint8_t)frTemp, false, PALETTE_SOLID_WRAP, 0), volTemp)); return FRAMETIME; } // mode_rocktaves() diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index b1a5d2cfa..fff677e5d 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -157,8 +157,7 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) if (strip.useLedsArray) strip.leds[XY(x, y)] = col; - uint8_t _bri_t = strip._bri_t; - //uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); + uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); if (_bri_t < 255) { byte r = scale8(R(col), _bri_t); byte g = scale8(G(col), _bri_t); From 4202fb8cdc18c72ceb2e530f89ed56e9737ca43d Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 18:05:55 +0200 Subject: [PATCH 07/10] Small things - Remove leds[] in comments - freqmatrix default mapping to circle - t_bri compile error --- wled00/FX.cpp | 8 ++++---- wled00/FX_fcn.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 1a21c3912..3fbcb76ba 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3836,7 +3836,7 @@ uint16_t phased_base(uint8_t moder) { // We're making sine wave for (int i = 0; i < SEGLEN; i++) { if (moder == 1) modVal = (inoise8(i*10 + i*10) /16); // Let's randomize our mod length with some Perlin noise. - uint16_t val = (i+1) * allfreq; // This sets the frequency of the waves. The +1 makes sure that leds[0] is used. + uint16_t val = (i+1) * allfreq; // This sets the frequency of the waves. The +1 makes sure that led 0 is used. if (modVal == 0) modVal = 1; val += *phase * (i % modVal +1) /2; // This sets the varying phase change of the waves. By Andrew Tuline. uint8_t b = cubicwave8(val); // Now we make an 8 bit sinewave. @@ -4888,7 +4888,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: // else do nothing! } //x,y - // calculate CRC16 of leds[] + // calculate CRC16 of leds uint16_t crc = crc16((const unsigned char*)prevLeds, dataSize-1); //ewowi: prevLeds instead of leds work as well, tbd: compare more patterns, see SR! // check if we had same CRC and reset if needed @@ -6764,7 +6764,7 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch return FRAMETIME; } // mode_freqmatrix() -static const char *_data_FX_MODE_FREQMATRIX PROGMEM = "Freqmatrix ♫@Time delay,Sound effect,Low bin,High bin,Sensivity;;;mp12=0,ssim=0"; // Pixels, Beatsin +static const char *_data_FX_MODE_FREQMATRIX PROGMEM = "Freqmatrix ♫@Time delay,Sound effect,Low bin,High bin,Sensivity;;;mp12=1,ssim=0"; // Circel, Beatsin ////////////////////// @@ -6968,7 +6968,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac frTemp -=132; // This should give us a base musical note of C3 frTemp = fabs(frTemp * 2.1); // Fudge factors to compress octave range starting at 0 and going to 255; -// leds[beatsin8(8+octCount*4,0,SEGLEN-1,0,octCount*8)] += CHSV((uint8_t)frTemp,255,volTemp); // Back and forth with different frequencies and phase shift depending on current octave. +// SEGMENT.setPixelColor(beatsin8(8+octCount*4,0,SEGLEN-1,0,octCount*8), CHSV((uint8_t)frTemp,255,volTemp)); // Back and forth with different frequencies and phase shift depending on current octave. uint16_t i = map(beatsin8(8+octCount*4, 0, 255, 0, octCount*8), 0, 255, 0, SEGLEN-1); SEGMENT.setPixelColor(i, color_add(SEGMENT.getPixelColor(i),color_blend(SEGCOLOR(1), SEGMENT.color_from_palette((uint8_t)frTemp, false, PALETTE_SOLID_WRAP, 0), volTemp))); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 22f0c9cc1..bad4f3133 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -434,8 +434,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) strip.leds[start + i] = col; //ewowi: is this right? uint16_t len = length(); - uint8_t _bri_t = strip._bri_t; - //uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); + // uint8_t _bri_t = strip._bri_t; + uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); if (_bri_t < 255) { byte r = scale8(R(col), _bri_t); byte g = scale8(G(col), _bri_t); From 640f45f57d24c4333fc7cc634461de6781343ab6 Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 19:44:27 +0200 Subject: [PATCH 08/10] Remove leds array from utility functions + small things - Remove CRGB* leds from utility functions - GameOfLife: fill_solid for prevLeds to for loop - Remove if !fftResult - Funky Plank: toggle src and dst - Comment drawLine as not used - Duplicate FadeToBlack, call one FadeToBlackOld --- wled00/FX.cpp | 158 +++++++++++++++++------------------------- wled00/FX.h | 32 ++++----- wled00/FX_2Dfcn.cpp | 163 +++++++++++++++++++------------------------- 3 files changed, 149 insertions(+), 204 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 3fbcb76ba..826cb3506 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4570,10 +4570,10 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma // initialize on first call if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); } - SEGMENT.fadeToBlackBy(nullptr, 16 + (SEGMENT.speed>>3)); // create fading trails + SEGMENT.fadeToBlackBy(16 + (SEGMENT.speed>>3)); // create fading trails float t = (float)(millis())/128; // timebase // outer stars for (size_t i = 0; i < 8; i++) { @@ -4590,7 +4590,7 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma // central white dot SEGMENT.setPixelColorXY(cols/2,rows/2, CHSV(0,0,255)); // blur everything a bit - SEGMENT.blur2d(nullptr, 16); + SEGMENT.blur2d(16); return FRAMETIME; } // mode_2DBlackHole() @@ -4607,7 +4607,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); SEGENV.aux0 = 0; // start with red hue } @@ -4617,7 +4617,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so byte numLines = SEGMENT.intensity/16 + 1; SEGENV.aux0++; // hue - SEGMENT.fadeToBlackBy(nullptr, 40); + SEGMENT.fadeToBlackBy(40); for (size_t i = 0; i < numLines; i++) { byte x1 = beatsin8(2 + SEGMENT.speed/16, 0, (cols - 1)); @@ -4644,7 +4644,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so SEGMENT.addPixelColorXY(y1, y2, CRGB::White); } } - SEGMENT.blur2d(nullptr, 4); + SEGMENT.blur2d(4); return FRAMETIME; } // mode_2DColoredBursts() @@ -4660,15 +4660,15 @@ 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(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 64); + SEGMENT.fadeToBlackBy(64); for(int i = 0; i < cols; i++) { SEGMENT.setPixelColorXY(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)); SEGMENT.setPixelColorXY(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(nullptr, SEGMENT.intensity/8); + SEGMENT.blur2d(SEGMENT.intensity/8); return FRAMETIME; } // mode_2Ddna() @@ -4685,7 +4685,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); SEGENV.aux0 = 0; // hue } @@ -4693,7 +4693,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma uint8_t freq = SEGMENT.intensity/8; uint32_t ms = millis() / 20; - SEGMENT.nscale8(nullptr, 120); + SEGMENT.nscale8(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); @@ -4728,9 +4728,9 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 128); + SEGMENT.fadeToBlackBy(128); const uint16_t maxDim = MAX(cols, rows)/2; unsigned long t = millis() / (32 - (SEGMENT.speed>>3)); @@ -4740,7 +4740,7 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli uint16_t myY = (rows>>1) + (uint16_t)(cos_t(angle) * i) + (rows%2); SEGMENT.setPixelColorXY(myX,myY, ColorFromPalette(SEGPALETTE, (i * 20) + (t / 20), 255, LINEARBLEND)); } - SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); + SEGMENT.blur2d(SEGMENT.intensity>>3); return FRAMETIME; } // mode_2DDrift() @@ -4756,7 +4756,7 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); uint16_t xscale = SEGMENT.intensity*4; uint32_t yscale = SEGMENT.speed*8; @@ -4788,13 +4788,13 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 16); + SEGMENT.fadeToBlackBy(16); for (size_t i = 8; i > 0; i--) { SEGMENT.setPixelColorXY(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(nullptr, 16); + SEGMENT.blur2d(16); return FRAMETIME; } // mode_2DFrizzles() @@ -4837,7 +4837,8 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https: SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); } - SEGMENT.fill_solid(prevLeds, CRGB::Black); + for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) prevLeds[XY(x,y)] = CRGB::Black; + SEGENV.aux1 = 0; SEGENV.aux0 = 0xFFFF; @@ -5034,7 +5035,7 @@ uint16_t mode_2DJulia(void) { // An animated Julia set } y += dy; } -// blur2d( leds, 64); +// blur2d(64); return FRAMETIME; } // mode_2DJulia() @@ -5078,7 +5079,7 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(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 @@ -5225,9 +5226,9 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 64); + SEGMENT.fadeToBlackBy(64); float t = millis() / (33 - SEGMENT.speed/8); for (uint16_t i = 0; i < cols; i++) { uint16_t thisVal = inoise8(i * 30, t, t); @@ -5248,7 +5249,7 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito (rows - 1 - cy == 0)) ? ColorFromPalette(SEGPALETTE, beat8(5), thisVal, LINEARBLEND) : CRGB::Black); } } - SEGMENT.blur2d(nullptr, 4); + SEGMENT.blur2d(4); return FRAMETIME; } // mode_2DPlasmaball() @@ -5271,7 +5272,7 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https if (SEGENV.call == 0) { SEGENV.step = 0; - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); } float adjustHeight = (float)map(rows, 8, 32, 28, 12); @@ -5318,16 +5319,16 @@ uint16_t mode_2DPulser(void) { // By: ldirko https://edi //const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 8 - (SEGMENT.intensity>>5)); + SEGMENT.fadeToBlackBy(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); SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND)); - SEGMENT.blur2d(nullptr, 1 + (SEGMENT.intensity>>4)); + SEGMENT.blur2d(1 + (SEGMENT.intensity>>4)); return FRAMETIME; } // mode_2DPulser() @@ -5343,9 +5344,9 @@ uint16_t mode_2DSindots(void) { // By: ldirko http const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); - SEGMENT.fadeToBlackBy(nullptr, 15); + SEGMENT.fadeToBlackBy(15); byte t1 = millis() / (257 - SEGMENT.speed); // 20; byte t2 = sin8(t1) / 4 * 2; for (uint16_t i = 0; i < 13; i++) { @@ -5353,7 +5354,7 @@ uint16_t mode_2DSindots(void) { // By: ldirko http byte y = sin8(t2 + i * SEGMENT.intensity/8)*(rows-1)/255; // max index now 255x15/255=15! SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND)); } - SEGMENT.blur2d(nullptr, 16); + SEGMENT.blur2d(16); return FRAMETIME; } // mode_2DSindots() @@ -5371,13 +5372,13 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); const uint8_t kBorderWidth = 2; - SEGMENT.fadeToBlackBy(nullptr, 24); + SEGMENT.fadeToBlackBy(24); uint8_t blurAmount = SEGMENT.custom3>>4; - SEGMENT.blur2d(nullptr, blurAmount); + SEGMENT.blur2d(blurAmount); // Use two out-of-sync sine waves uint8_t i = beatsin8(19, kBorderWidth, cols-kBorderWidth); @@ -5410,7 +5411,7 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi 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(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); unsigned long t = millis() / 4; int index = 0; @@ -5455,7 +5456,7 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); uint8_t hue; int offsetX = beatsin16(3, -360, 360); @@ -5484,7 +5485,7 @@ 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(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); uint32_t tb = strip.now >> 12; // every ~4s if (tb > SEGENV.step) { @@ -5496,8 +5497,8 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht SEGENV.step = tb + random8(4); } - SEGMENT.fadeToBlackBy(nullptr, map(SEGMENT.speed, 0, 255, 248, 16)); - SEGMENT.move(SEGENV.aux0, 1, nullptr); + SEGMENT.fadeToBlackBy(map(SEGMENT.speed, 0, 255, 248, 16)); + SEGMENT.move(SEGENV.aux0, 1); for (size_t i = 0; i < 8; i++) { byte x = beatsin8(12 + i, 2, cols - 3); byte y = beatsin8(15 + i, 2, rows - 3); @@ -5510,7 +5511,7 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht SEGMENT.addPixelColorXY(x, y - 1, color); } } - SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); + SEGMENT.blur2d(SEGMENT.intensity>>3); return FRAMETIME; } @@ -5550,7 +5551,7 @@ uint16_t mode_2Dcrazybees(void) { bee_t *bee = reinterpret_cast(SEGENV.data); if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); for (size_t i = 0; i < n; i++) { bee[i].posX = random8(0, cols); bee[i].posY = random8(0, rows); @@ -5561,7 +5562,7 @@ uint16_t mode_2Dcrazybees(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + (FRAMETIME * 8 / ((SEGMENT.speed>>5)+1)); - SEGMENT.fadeToBlackBy(nullptr, 32); + SEGMENT.fadeToBlackBy(32); for (size_t i = 0; i < n; i++) { SEGMENT.addPixelColorXY(bee[i].aimX + 1, bee[i].aimY, CHSV(bee[i].hue, 255, 255)); @@ -5583,7 +5584,7 @@ uint16_t mode_2Dcrazybees(void) { bee[i].aimed(cols, rows); } } - SEGMENT.blur2d(nullptr, SEGMENT.intensity>>4); + SEGMENT.blur2d(SEGMENT.intensity>>4); } return FRAMETIME; @@ -5623,7 +5624,7 @@ uint16_t mode_2Dghostrider(void) { if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); random16_set_seed(strip.now); lighter->angleSpeed = random8(0,20) - 10; lighter->Vspeed = 5; @@ -5639,10 +5640,10 @@ uint16_t mode_2Dghostrider(void) { if (millis() > SEGENV.step) { SEGENV.step = millis() + 1024 / (cols+rows); - SEGMENT.fadeToBlackBy(nullptr, (SEGMENT.speed>>2)+64); + SEGMENT.fadeToBlackBy((SEGMENT.speed>>2)+64); CRGB color = CRGB::White; - SEGMENT.wu_pixel(nullptr, lighter->gPosX * 256 / 10, lighter->gPosY * 256 / 10, color); + SEGMENT.wu_pixel(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)); @@ -5670,9 +5671,9 @@ 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(nullptr, lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); + SEGMENT.wu_pixel(lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i]))); } - SEGMENT.blur2d(nullptr, SEGMENT.intensity>>3); + SEGMENT.blur2d(SEGMENT.intensity>>3); } return FRAMETIME; @@ -5707,7 +5708,7 @@ uint16_t mode_2Dfloatingblobs(void) { if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows) { SEGENV.aux0 = cols; SEGENV.aux1 = rows; - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(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 @@ -5721,7 +5722,7 @@ uint16_t mode_2Dfloatingblobs(void) { } } - SEGMENT.fadeToBlackBy(nullptr, 20); + SEGMENT.fadeToBlackBy(20); // Bounce balls around for (size_t i = 0; i < Amount; i++) { @@ -5742,7 +5743,7 @@ 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(nullptr, blob->y[i], blob->x[i], blob->r[i], c); + if (blob->r[i] > 1.f) SEGMENT.fill_circle(blob->y[i], blob->x[i], blob->r[i], c); else SEGMENT.addPixelColorXY(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)); @@ -5771,7 +5772,7 @@ uint16_t mode_2Dfloatingblobs(void) { blob->y[i] = rows - 1.01f; } } - SEGMENT.blur2d(nullptr, cols+rows); + SEGMENT.blur2d(cols+rows); if (SEGENV.step < millis()) SEGENV.step = millis() + 2000; // change colors every 2 seconds @@ -5846,16 +5847,16 @@ uint16_t mode_2Ddriftrose(void) { const float L = min(cols, rows) / 2.f; if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); } - SEGMENT.fadeToBlackBy(nullptr, 32+(SEGMENT.speed>>3)); + SEGMENT.fadeToBlackBy(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(nullptr, x, y, CHSV(i * 10, 255, 255)); + SEGMENT.wu_pixel(x, y, CHSV(i * 10, 255, 255)); } - SEGMENT.blur2d(nullptr, (SEGMENT.intensity>>4)+1); + SEGMENT.blur2d((SEGMENT.intensity>>4)+1); return FRAMETIME; } @@ -5888,7 +5889,6 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur; binNum = (uint8_t*) um_data->u_data[7]; // requires UI element (SEGMENT.customX?), changes source element fftBin = (float*) um_data->u_data[8]; } else { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } */ @@ -5908,7 +5908,6 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; @@ -5982,11 +5981,11 @@ uint16_t mode_2DSwirl(void) { const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); const uint8_t borderWidth = 2; - SEGMENT.blur2d(nullptr, SEGMENT.custom1); + SEGMENT.blur2d(SEGMENT.custom1); uint8_t i = beatsin8( 27*SEGMENT.speed/255, borderWidth, cols - borderWidth); uint8_t j = beatsin8( 41*SEGMENT.speed/255, borderWidth, rows - borderWidth); @@ -5996,7 +5995,6 @@ uint16_t mode_2DSwirl(void) { um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; //ewowi: use instead of sampleAvg??? @@ -6027,17 +6025,16 @@ uint16_t mode_2DWaverly(void) { const uint16_t rows = SEGMENT.virtualHeight(); if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); } um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; - SEGMENT.fadeToBlackBy(nullptr, SEGMENT.speed); + SEGMENT.fadeToBlackBy(SEGMENT.speed); long t = millis() / 2; for (uint16_t i = 0; i < cols; i++) { @@ -6054,7 +6051,7 @@ uint16_t mode_2DWaverly(void) { SEGMENT.addPixelColorXY((cols - 1) - i, (rows - 1) - j, ColorFromPalette(SEGPALETTE, map(j, 0, thisMax, 250, 0), 255, LINEARBLEND)); } } - SEGMENT.blur2d(nullptr, 16); + SEGMENT.blur2d(16); return FRAMETIME; } // mode_2DWaverly() @@ -6084,7 +6081,6 @@ uint16_t mode_gravcenter(void) { // Gravcenter. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6131,7 +6127,6 @@ uint16_t mode_gravcentric(void) { // Gravcentric. By Andrew um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6181,7 +6176,6 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6221,7 +6215,6 @@ static const char *_data_FX_MODE_GRAVIMETER PROGMEM = "Gravimeter ♪@Rate of fa uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6244,7 +6237,6 @@ static const char *_data_FX_MODE_JUGGLES PROGMEM = "Juggles ♪@!,# of balls;,!; uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } int16_t volumeRaw = *(int16_t*)um_data->u_data[1]; @@ -6273,7 +6265,6 @@ uint16_t mode_midnoise(void) { // Midnoise. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6312,7 +6303,6 @@ uint16_t mode_noisefire(void) { // Noisefire. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6338,7 +6328,6 @@ uint16_t mode_noisemeter(void) { // Noisemeter. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6372,7 +6361,6 @@ uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } int16_t volumeRaw = *(int16_t*)um_data->u_data[1]; @@ -6409,7 +6397,6 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float volumeSmth = *(float*) um_data->u_data[0]; @@ -6447,7 +6434,6 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; @@ -6491,7 +6477,6 @@ uint16_t mode_puddles(void) { // Puddles. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } int16_t volumeRaw = *(int16_t*)um_data->u_data[1]; @@ -6632,11 +6617,9 @@ static const char *_data_FX_MODE_BINMAP PROGMEM = " ♫ Binmap@,,Input level=128 uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; - if (!fftResult) return mode_static(); if (SEGENV.call == 0) { SEGMENT.fill(BLACK); @@ -6664,11 +6647,9 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; - if (!fftResult) return mode_static(); uint8_t secondHand = micros()/(256-SEGMENT.speed)/500+1 % 64; if (SEGENV.aux0 != secondHand) { // Triggered millis timing. @@ -6696,7 +6677,6 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*) um_data->u_data[4]; @@ -6723,7 +6703,6 @@ static const char *_data_FX_MODE_FREQMAP PROGMEM = "Freqmap ♫@Fade rate,Starti uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Pleschung. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*)um_data->u_data[4]; @@ -6777,7 +6756,6 @@ static const char *_data_FX_MODE_FREQMATRIX PROGMEM = "Freqmatrix ♫@Time delay uint16_t mode_freqpixels(void) { // Freqpixel. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*) um_data->u_data[4]; @@ -6815,7 +6793,6 @@ static const char *_data_FX_MODE_FREQPIXELS PROGMEM = "Freqpixels ♫@Fade rate, uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschung. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*) um_data->u_data[4]; @@ -6875,7 +6852,6 @@ uint16_t mode_gravfreq(void) { // Gravfreq. By Andrew Tuline. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*) um_data->u_data[4]; @@ -6920,11 +6896,9 @@ static const char *_data_FX_MODE_GRAVFREQ PROGMEM = "Gravfreq ♫@Rate of fall,S uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuline um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; - if (!fftResult) return mode_static(); SEGMENT.fade_out(224); // Just in case something doesn't get faded. @@ -6946,7 +6920,6 @@ static const char *_data_FX_MODE_NOISEMOVE PROGMEM = "Noisemove ♫@Speed of per uint16_t mode_rocktaves(void) { // Rocktaves. Same note from each octave is same colour. By: Andrew Tuline um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } float FFT_MajorPeak = *(float*) um_data->u_data[4]; @@ -6986,7 +6959,6 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; @@ -7039,11 +7011,9 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma. um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - // add support for no audio data um_data = simulateSound(SEGMENT.soundSim); } uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; - if (!fftResult) return mode_static(); if (SEGENV.call == 0) for (int i=0; iu_data[2]; - if (!fftResult) return mode_static(); uint8_t secondHand = micros()/(256-SEGMENT.speed)/500+1 % 64; if (SEGENV.aux0 != secondHand) { // Triggered millis timing. @@ -7124,7 +7092,7 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil // Update the display: for (int i = (rows - 1); i > 0; i--) { for (int j = (cols - 1); j >= 0; j--) { - SEGMENT.setPixelColorXY(j, i-1, SEGMENT.getPixelColorXY(j, i)); + SEGMENT.setPixelColorXY(j, i, SEGMENT.getPixelColorXY(j, i-1)); } } } diff --git a/wled00/FX.h b/wled00/FX.h index 238914d7c..162ef6ec7 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -575,22 +575,22 @@ typedef struct Segment { void addPixelColorXY(uint16_t x, uint16_t y, uint32_t color); void addPixelColorXY(uint16_t x, uint16_t y, byte r, byte g, byte b, byte w = 0) { addPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline void addPixelColorXY(uint16_t x, uint16_t y, CRGB c) { addPixelColorXY(x, y, c.red, c.green, c.blue); } // automatically inline - void blur1d(CRGB* leds, fract8 blur_amount); - void blur1d(uint16_t i, bool vertical, fract8 blur_amount, CRGB* leds=nullptr); // 1D box blur (with weight) - void blur2d(CRGB* leds, fract8 blur_amount); - void blurRow(uint16_t row, fract8 blur_amount, CRGB* leds=nullptr); - void blurCol(uint16_t col, fract8 blur_amount, CRGB* leds=nullptr); - void moveX(CRGB *leds, int8_t delta); - void moveY(CRGB *leds, int8_t delta); - void move(uint8_t dir, uint8_t delta, CRGB *leds=nullptr); - void fill_solid(CRGB* leds, CRGB c); - void fill_circle(CRGB* leds, uint16_t cx, uint16_t cy, uint8_t radius, CRGB c); - void fadeToBlackBy(CRGB* leds, uint8_t fadeBy); - void nscale8(CRGB* leds, uint8_t scale); - void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c, CRGB *leds = nullptr); - void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color, CRGB *leds = nullptr); - void wu_pixel(CRGB *leds, uint32_t x, uint32_t y, CRGB c); - inline void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) { drawLine(x0, y0, x1, y1, CRGB(byte(c>>16), byte(c>>8), byte(c))); } + void blur1d(fract8 blur_amount); + void blur1d(uint16_t i, bool vertical, fract8 blur_amount); // 1D box blur (with weight) + void blur2d(fract8 blur_amount); + void blurRow(uint16_t row, fract8 blur_amount); + void blurCol(uint16_t col, fract8 blur_amount); + void moveX(int8_t delta); + void moveY(int8_t delta); + void move(uint8_t dir, uint8_t delta); + void fill_solid(CRGB c); + void fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB c); + void fadeToBlackByOld(uint8_t fadeBy); + void nscale8(uint8_t scale); + // void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c, CRGB *leds = nullptr); + void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color); + void wu_pixel(uint32_t x, uint32_t y, CRGB c); + // inline void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) { drawLine(x0, y0, x1, y1, CRGB(byte(c>>16), byte(c>>8), byte(c))); } inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t c) { drawCharacter(chr, x, y, w, h, CRGB(byte(c>>16), byte(c>>8), byte(c))); } } segment; //static int i = sizeof(Segment); diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index aaa5ea2a5..393aa5071 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -276,7 +276,7 @@ void Segment::addPixelColorXY(uint16_t x, uint16_t y, uint32_t color) { } // blurRow: perform a blur on a row of a rectangular matrix -void Segment::blurRow(uint16_t row, fract8 blur_amount, CRGB* leds) { +void Segment::blurRow(uint16_t row, fract8 blur_amount) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -287,25 +287,23 @@ void Segment::blurRow(uint16_t row, fract8 blur_amount, CRGB* leds) { uint8_t seep = blur_amount >> 1; CRGB carryover = CRGB::Black; for (uint16_t x = 0; x < cols; x++) { - CRGB cur = leds ? leds[XY(x,row)] : CRGB(getPixelColorXY(x, row)); + CRGB cur = CRGB(getPixelColorXY(x, row)); CRGB part = cur; part.nscale8(seep); cur.nscale8(keep); cur += carryover; if (x) { - CRGB prev = (leds ? leds[XY(x-1,row)] : CRGB(getPixelColorXY(x-1, row))) + part; - if (leds) leds[XY(x-1,row)] = prev; - else setPixelColorXY(x-1, row, prev); + CRGB prev = CRGB(getPixelColorXY(x-1, row)) + part; + setPixelColorXY(x-1, row, prev); } - if (leds) leds[XY(x,row)] = cur; - else setPixelColorXY(x, row, cur); + setPixelColorXY(x, row, cur); carryover = part; } #endif } // blurCol: perform a blur on a column of a rectangular matrix -void Segment::blurCol(uint16_t col, fract8 blur_amount, CRGB* leds) { +void Segment::blurCol(uint16_t col, fract8 blur_amount) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -316,18 +314,16 @@ void Segment::blurCol(uint16_t col, fract8 blur_amount, CRGB* leds) { uint8_t seep = blur_amount >> 1; CRGB carryover = CRGB::Black; for (uint16_t i = 0; i < rows; i++) { - CRGB cur = leds ? leds[XY(col,i)] : CRGB(getPixelColorXY(col, i)); + CRGB cur = CRGB(getPixelColorXY(col, i)); CRGB part = cur; part.nscale8(seep); cur.nscale8(keep); cur += carryover; if (i) { - CRGB prev = (leds ? leds[XY(col,i-1)] : CRGB(getPixelColorXY(col, i-1))) + part; - if (leds) leds[XY(col,i-1)] = prev; - else setPixelColorXY(col, i-1, prev); + CRGB prev = CRGB(getPixelColorXY(col, i-1)) + part; + setPixelColorXY(col, i-1, prev); } - if (leds) leds[XY(col,i)] = cur; - else setPixelColorXY(col, i, cur); + setPixelColorXY(col, i, cur); carryover = part; } #endif @@ -347,15 +343,15 @@ void Segment::blurCol(uint16_t col, fract8 blur_amount, CRGB* leds) { // eventually all the way to black; this is by design so that // it can be used to (slowly) clear the LEDs to black. -void Segment::blur1d(CRGB* leds, fract8 blur_amount) { +void Segment::blur1d(fract8 blur_amount) { #ifndef WLED_DISABLE_2D const uint16_t rows = virtualHeight(); - for (uint16_t y = 0; y < rows; y++) blurRow(y, blur_amount, leds); + for (uint16_t y = 0; y < rows; y++) blurRow(y, blur_amount); #endif } // 1D Box blur (with added weight - blur_amount: [0=no blur, 255=max blur]) -void Segment::blur1d(uint16_t i, bool vertical, fract8 blur_amount, CRGB* leds) { +void Segment::blur1d(uint16_t i, bool vertical, fract8 blur_amount) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -373,9 +369,9 @@ void Segment::blur1d(uint16_t i, bool vertical, fract8 blur_amount, CRGB* leds) uint16_t yp = vertical ? y-1 : y; uint16_t xn = vertical ? x : x+1; uint16_t yn = vertical ? y+1 : y; - CRGB curr = leds ? leds[XY(x,y)] : CRGB(getPixelColorXY(x,y)); - CRGB prev = (xp<0 || yp<0) ? CRGB::Black : (leds ? leds[XY(xp,yp)] : CRGB(getPixelColorXY(xp,yp))); - CRGB next = ((vertical && yn>=dim1) || (!vertical && xn>=dim1)) ? CRGB::Black : (leds ? leds[XY(xn,yn)] : CRGB(getPixelColorXY(xn,yn))); + CRGB curr = CRGB(getPixelColorXY(x,y)); + CRGB prev = (xp<0 || yp<0) ? CRGB::Black : CRGB(getPixelColorXY(xp,yp)); + CRGB next = ((vertical && yn>=dim1) || (!vertical && xn>=dim1)) ? CRGB::Black : CRGB(getPixelColorXY(xn,yn)); uint16_t r, g, b; r = (curr.r*keep + (prev.r + next.r)*seep) / 3; g = (curr.g*keep + (prev.g + next.g)*seep) / 3; @@ -385,22 +381,21 @@ void Segment::blur1d(uint16_t i, bool vertical, fract8 blur_amount, CRGB* leds) for (uint16_t j = 0; j < dim1; j++) { uint16_t x = vertical ? i : j; uint16_t y = vertical ? j : i; - if (leds) leds[XY(x,y)] = tmp[j]; - else setPixelColorXY(x, y, tmp[j]); + setPixelColorXY(x, y, tmp[j]); } #endif } -void Segment::blur2d(CRGB* leds, fract8 blur_amount) { +void Segment::blur2d(fract8 blur_amount) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); - for (uint16_t i = 0; i < rows; i++) blurRow(i, blur_amount, leds); // blur all rows - for (uint16_t k = 0; k < cols; k++) blurCol(k, blur_amount, leds); // blur all columns + for (uint16_t i = 0; i < rows; i++) blurRow(i, blur_amount); // blur all rows + for (uint16_t k = 0; k < cols; k++) blurCol(k, blur_amount); // blur all columns #endif } -void Segment::moveX(CRGB *leds, int8_t delta) { +void Segment::moveX(int8_t delta) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -408,20 +403,18 @@ void Segment::moveX(CRGB *leds, int8_t delta) { if (delta > 0) { for (uint8_t y = 0; y < rows; y++) for (uint8_t x = 0; x < cols-1; x++) { if (x + delta >= cols) break; - if (leds) leds[XY(x, y)] = leds[XY((x + delta)%cols, y)]; - else setPixelColorXY(x, y, getPixelColorXY((x + delta)%cols, y)); + setPixelColorXY(x, y, getPixelColorXY((x + delta)%cols, y)); } } else { for (uint8_t y = 0; y < rows; y++) for (int16_t x = cols-1; x >= 0; x--) { if (x + delta < 0) break; - if (leds) leds[XY(x, y)] = leds[XY(x + delta, y)]; - else setPixelColorXY(x, y, getPixelColorXY(x + delta, y)); + setPixelColorXY(x, y, getPixelColorXY(x + delta, y)); } } #endif } -void Segment::moveY(CRGB *leds, int8_t delta) { +void Segment::moveY(int8_t delta) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -429,14 +422,12 @@ void Segment::moveY(CRGB *leds, int8_t delta) { if (delta > 0) { for (uint8_t x = 0; x < cols; x++) for (uint8_t y = 0; y < rows-1; y++) { if (y + delta >= rows) break; - if (leds) leds[XY(x, y)] = leds[XY(x, (y + delta))]; - else setPixelColorXY(x, y, getPixelColorXY(x, (y + delta))); + setPixelColorXY(x, y, getPixelColorXY(x, (y + delta))); } } else { for (uint8_t x = 0; x < cols; x++) for (int16_t y = rows-1; y >= 0; y--) { if (y + delta < 0) break; - if (leds) leds[XY(x, y)] = leds[XY(x, y + delta)]; - else setPixelColorXY(x, y, getPixelColorXY(x, y + delta)); + setPixelColorXY(x, y, getPixelColorXY(x, y + delta)); } } #endif @@ -445,35 +436,34 @@ void Segment::moveY(CRGB *leds, int8_t delta) { // move() - move all pixels in desired direction delta number of pixels // @param dir direction: 0=left, 1=left-up, 2=up, 3=right-up, 4=right, 5=right-down, 6=down, 7=left-down // @param delta number of pixels to move -void Segment::move(uint8_t dir, uint8_t delta, CRGB *leds) { +void Segment::move(uint8_t dir, uint8_t delta) { #ifndef WLED_DISABLE_2D if (delta==0) return; switch (dir) { - case 0: moveX(leds, delta); break; - case 1: moveX(leds, delta); moveY(leds, delta); break; - case 2: moveY(leds, delta); break; - case 3: moveX(leds,-delta); moveY(leds, delta); break; - case 4: moveX(leds,-delta); break; - case 5: moveX(leds,-delta); moveY(leds,-delta); break; - case 6: moveY(leds,-delta); break; - case 7: moveX(leds, delta); moveY(leds,-delta); break; + case 0: moveX(delta); break; + case 1: moveX(delta); moveY(delta); break; + case 2: moveY(delta); break; + case 3: moveX(-delta); moveY(delta); break; + case 4: moveX(-delta); break; + case 5: moveX(-delta); moveY(-delta); break; + case 6: moveY(-delta); break; + case 7: moveX(delta); moveY(-delta); break; } #endif } -void Segment::fill_solid(CRGB* leds, CRGB color) { +void Segment::fill_solid(CRGB color) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) { - if (leds) leds[XY(x,y)] = color; - else setPixelColorXY(x, y, color); + setPixelColorXY(x, y, color); } #endif } // by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs -void Segment::fill_circle(CRGB* leds, uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) { +void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -482,50 +472,47 @@ void Segment::fill_circle(CRGB* leds, uint16_t cx, uint16_t cy, uint8_t radius, if (x * x + y * y <= radius * radius && int16_t(cx)+x>=0 && int16_t(cy)+y>=0 && int16_t(cx)+x= cols || x1 >= cols || y0 >= rows || y1 >= rows) return; - const int16_t dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2; - for (;;) { - if (leds == nullptr) setPixelColorXY(x0,y0,c); - else leds[XY(x0,y0)] = c; - if (x0==x1 && y0==y1) break; - e2 = err; - if (e2 >-dx) { err -= dy; x0 += sx; } - if (e2 < dy) { err += dx; y0 += sy; } - } -#endif -} +// void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c, CRGB *leds) { +// #ifndef WLED_DISABLE_2D +// const uint16_t cols = virtualWidth(); +// const uint16_t rows = virtualHeight(); +// if (x0 >= cols || x1 >= cols || y0 >= rows || y1 >= rows) return; +// const int16_t dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2; +// for (;;) { +// if (leds == nullptr) setPixelColorXY(x0,y0,c); +// else leds[XY(x0,y0)] = c; +// if (x0==x1 && y0==y1) break; +// e2 = err; +// if (e2 >-dx) { err -= dy; x0 += sx; } +// if (e2 < dy) { err += dx; y0 += sy; } +// } +// #endif +// } #ifndef WLED_DISABLE_2D // font curtesy of https://github.com/idispatch/raster-fonts @@ -6682,7 +6669,7 @@ static const unsigned char console_font_5x8[] PROGMEM = { // draws a raster font character on canvas // only supports 5x8 and 6x8 fonts ATM -void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color, CRGB *leds) { +void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color) { #ifndef WLED_DISABLE_2D const uint16_t cols = virtualWidth(); const uint16_t rows = virtualHeight(); @@ -6700,8 +6687,7 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, for (uint8_t j = 0; j= 0 || x0 < cols) && ((bits>>(j+(8-w))) & 0x01)) { // bit set & drawing on-screen - if (leds) leds[XY(x0,y0)] = color; - else setPixelColorXY(x0, y0, color); + setPixelColorXY(x0, y0, color); } } } @@ -6709,7 +6695,7 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, } #define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8)) -void Segment::wu_pixel(CRGB *leds, uint32_t x, uint32_t y, CRGB c) { //awesome wu_pixel procedure by reddit u/sutaburosu +void Segment::wu_pixel(uint32_t x, uint32_t y, CRGB c) { //awesome wu_pixel procedure by reddit u/sutaburosu #ifndef WLED_DISABLE_2D // extract the fractional parts and derive their inverses uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy; @@ -6720,21 +6706,12 @@ void Segment::wu_pixel(CRGB *leds, uint32_t x, uint32_t y, CRGB c) { //awes for (uint8_t i = 0; i < 4; i++) { uint16_t xx = (x >> 8) + (i & 1); uint16_t yy = (y >> 8) + ((i >> 1) & 1); - uint16_t xy = XY(xx, yy); CRGB color; - if (leds) { - color.r = qadd8(leds[xy].r, c.r * wu[i] >> 8); - color.g = qadd8(leds[xy].g, c.g * wu[i] >> 8); - color.b = qadd8(leds[xy].b, c.b * wu[i] >> 8); - leds[xy] = color; - } - else { - CRGB oColor = getPixelColorXY(xx, yy); - color.r = qadd8(oColor.r, c.r * wu[i] >> 8); - color.g = qadd8(oColor.g, c.g * wu[i] >> 8); - color.b = qadd8(oColor.b, c.b * wu[i] >> 8); - setPixelColorXY(xx, yy, color); - } + CRGB oColor = getPixelColorXY(xx, yy); + color.r = qadd8(oColor.r, c.r * wu[i] >> 8); + color.g = qadd8(oColor.g, c.g * wu[i] >> 8); + color.b = qadd8(oColor.b, c.b * wu[i] >> 8); + setPixelColorXY(xx, yy, color); } #endif } From 7b3fc206f740dadcf6e7bc78ba21b2d98084021f Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 21:52:10 +0200 Subject: [PATCH 09/10] Merge leftovers --- wled00/FX.cpp | 14 +++++++------- wled00/FX_2Dfcn.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 4fac870fb..de6331f77 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6243,7 +6243,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. } int16_t volumeRaw = *(int16_t*)um_data->u_data[1]; - if (SEGENV.call == 0) SEGMENT.fill_solid(nullptr, CRGB::Black); + if (SEGENV.call == 0) SEGMENT.fill_solid(CRGB::Black); uint8_t secondHand = micros()/(256-SEGMENT.speed)/500 % 16; if(SEGENV.aux0 != secondHand) { @@ -6364,7 +6364,7 @@ uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline. // even with 1D effect we have to take logic for 2D segments for allocation as fill_solid() fills whole segment if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); // clear buffer + SEGMENT.fill_solid(CRGB::Black); // clear buffer SEGMENT.fill(BLACK); // clear output } @@ -6409,7 +6409,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline. } float volumeSmth = *(float*) um_data->u_data[0]; - SEGMENT.fadeToBlackBy(nullptr, 64); + SEGMENT.fadeToBlackBy(64); plasmoip->thisphase += beatsin8(6,-4,4); // You can change direction and speed individually. plasmoip->thatphase += beatsin8(7,-4,4); // Two phase values to make a complex pattern. By Andrew Tuline. @@ -6632,7 +6632,7 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline. uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; if (SEGENV.call == 0) { - SEGMENT.fill_solid(nullptr, CRGB::Black); + SEGMENT.fill_solid(CRGB::Black); SEGMENT.fill(BLACK); // clear canvas SEGENV.aux0 = 0; } @@ -6646,8 +6646,8 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline. ++(SEGENV.aux0) %= 16; // make sure it doesn't cross 16 SEGENV.step = 1; - if (SEGMENT.is2D()) SEGMENT.blur2d(nullptr, SEGMENT.intensity); - else SEGMENT.blur1d(nullptr, SEGMENT.intensity); + if (SEGMENT.is2D()) SEGMENT.blur2d(SEGMENT.intensity); + else SEGMENT.blur1d(SEGMENT.intensity); } return FRAMETIME; @@ -6949,7 +6949,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac float FFT_MajorPeak = *(float*) um_data->u_data[4]; float my_magnitude = *(float*) um_data->u_data[5] / 16.0f; - SEGMENT.fadeToBlackBy(nullptr, 64); // Just in case something doesn't get faded. + SEGMENT.fadeToBlackBy(64); // Just in case something doesn't get faded. float frTemp = FFT_MajorPeak; uint8_t octCount = 0; // Octave counter. diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 327b8d5e9..221b0d8a3 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -462,6 +462,7 @@ void Segment::fill_solid(CRGB color) { for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) { setPixelColorXY(x, y, color); } +#endif } // by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs From a098aa0a8902f73315f6cb356afd71153e6df1f0 Mon Sep 17 00:00:00 2001 From: ewowi Date: Tue, 2 Aug 2022 22:06:13 +0200 Subject: [PATCH 10/10] leds array from CRGB to uint32_t --- wled00/FX.h | 2 +- wled00/FX_fcn.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 59faf9247..3f2ea7d02 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -612,7 +612,7 @@ class WS2812FX { // 96 bytes public: // FastLED array, so we can refer to leds[i] instead of getPixel() and setPixel() - CRGB *leds = nullptr ; //See FX_fcn.cpp for init (wip). + uint32_t *leds = nullptr ; //See FX_fcn.cpp for init (wip). WS2812FX() : gammaCorrectBri(false), diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index d9c2715a2..db89dbbb9 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -443,7 +443,7 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) #endif if (strip.useLedsArray) - strip.leds[start + i] = col; //ewowi: is this right? + strip.leds[start + i] = col; uint16_t len = length(); uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0); @@ -536,8 +536,7 @@ uint32_t Segment::getPixelColor(uint16_t i) #endif if (strip.useLedsArray) { - CRGB led = strip.leds[start + i]; - return RGBW32(led.r, led.g, led.b, 0); + return strip.leds[start + i]; } if (getOption(SEG_OPTION_REVERSED)) i = virtualLength() - i - 1; @@ -859,7 +858,7 @@ void WS2812FX::service() { leds = (CRGB*) ps_malloc(sizeof(CRGB) * _length); else #endif - leds = (CRGB*) malloc(sizeof(CRGB) * _length); + leds = (uint32_t*) malloc(sizeof(uint32_t) * _length); } // }