Skip to content

Commit

Permalink
Make ripple segment compatible and add more size sanity check for 2D …
Browse files Browse the repository at this point in the history
…routines.
  • Loading branch information
atuline committed Mar 26, 2021
1 parent b7172ee commit 6227380
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4154,6 +4154,8 @@ typedef struct Julia { // We can't use the 'static' keyword for per

uint16_t WS2812FX::mode_2DJulia(void) { // An animated Julia set by Andrew Tuline

if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB*) ledData;

if (!SEGENV.allocateData(sizeof(julia))) return mode_static(); // We use this method for allocating memory for static variables.
Expand Down Expand Up @@ -4663,7 +4665,9 @@ uint16_t WS2812FX::mode_ripplepeak(void) { // * Ripple peak. By A
// static uint8_t colour; // Ripple colour is randomized.
// static uint16_t centre; // Center of the current ripple.
// static int8_t steps = -1; // -1 is the initializing step.
static uint8_t ripFade = 255; // Starting brightness.

// static uint8_t ripFade = 255; // Starting brightness, which we'll say is SEGENV.aux0.
if (SEGENV.call == 0) SEGENV.aux0 = 255;


binNum = SEGMENT.fft2; // Select a bin.
Expand Down Expand Up @@ -4698,7 +4702,7 @@ uint16_t WS2812FX::mode_ripplepeak(void) { // * Ripple peak. By A
break;

case 0:
setPixelColor(ripples[i].pos, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), ripFade));
setPixelColor(ripples[i].pos, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), SEGENV.aux0));
ripples[i].state++;
break;

Expand All @@ -4708,8 +4712,8 @@ uint16_t WS2812FX::mode_ripplepeak(void) { // * Ripple peak. By A

default: // Middle of the ripples.

setPixelColor((ripples[i].pos + ripples[i].state + SEGLEN) % SEGLEN, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), ripFade/ripples[i].state*2));
setPixelColor((ripples[i].pos - ripples[i].state + SEGLEN) % SEGLEN, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), ripFade/ripples[i].state*2));
setPixelColor((ripples[i].pos + ripples[i].state + SEGLEN) % SEGLEN, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), SEGENV.aux0/ripples[i].state*2));
setPixelColor((ripples[i].pos - ripples[i].state + SEGLEN) % SEGLEN, color_blend(SEGCOLOR(1), color_from_palette(ripples[i].color, false, PALETTE_SOLID_WRAP, 0), SEGENV.aux0/ripples[i].state*2));
ripples[i].state++; // Next step.
break;
} // switch step
Expand Down Expand Up @@ -5103,6 +5107,8 @@ uint16_t WS2812FX::mode_DJLight(void) { // Written by ??? Adap

uint16_t WS2812FX::mode_2DGEQ(void) { // By Will Tatam.

if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

fade_out(224); // Just in case something doesn't get faded.

CRGB *leds = (CRGB*) ledData;
Expand Down Expand Up @@ -5142,6 +5148,8 @@ uint16_t WS2812FX::mode_2DGEQ(void) { // By Will Tatam.

uint16_t WS2812FX::mode_2DFunkyPlank(void) { // Written by ??? Adapted by Will Tatam.

if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB*) ledData;

int NUMB_BANDS = map(SEGMENT.fft3, 0, 255, 1, 16);
Expand Down Expand Up @@ -5193,6 +5201,8 @@ uint16_t WS2812FX::mode_2DFunkyPlank(void) { // Written by ??? Adap

uint16_t WS2812FX::mode_2DCenterBars(void) { // Written by Scott Marley Adapted by Spiro-C..

if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB*) ledData;
fadeToBlackBy(leds, SEGLEN, SEGMENT.speed);

Expand Down Expand Up @@ -5393,7 +5403,7 @@ uint16_t i;

uint16_t WS2812FX::mode_2Dplasma(void) { // By Andreas Pleschutznig. A work in progress.

if (matrixWidth * matrixHeight > SEGLEN) {fade_out(224); return FRAMETIME;} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

static uint8_t ihue=0;
uint8_t index;
Expand Down Expand Up @@ -5488,7 +5498,7 @@ uint16_t WS2812FX::mode_2Dplasma(void) { // By Andreas Pleschut

uint16_t WS2812FX::mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline. Yet another short routine.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB *)ledData;

Expand Down Expand Up @@ -5530,7 +5540,7 @@ uint16_t WS2812FX::mode_2Dsquaredswirl(void) { // By: Mark Kriegsman.
// Modifed by: Andrew Tuline
// fft3 affects the blur amount.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB *)ledData;
const uint8_t kBorderWidth = 2;
Expand Down Expand Up @@ -5568,7 +5578,7 @@ uint16_t WS2812FX::mode_2Dsquaredswirl(void) { // By: Mark Kriegsman.

uint16_t WS2812FX::mode_2Dfire2012(void) { // Fire2012 by Mark Kriegsman. Converted to WLED by Andrew Tuline.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB *)ledData;
static byte *heat = (byte *)dataStore;
Expand Down Expand Up @@ -5626,7 +5636,7 @@ uint16_t WS2812FX::mode_2Dfire2012(void) { // Fire2012 by Mark Kr

uint16_t WS2812FX::mode_2Ddna(void) { // dna originally by by ldirko at https://pastebin.com/pCkkkzcs. Updated by Preyy. WLED version by Andrew Tuline.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB *)ledData;

Expand Down Expand Up @@ -5661,7 +5671,7 @@ uint16_t WS2812FX::mode_2Ddna(void) { // dna originally by by ldirko at

uint16_t WS2812FX::mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. Adapted by Andrew Tuline.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB* )ledData;

Expand Down Expand Up @@ -5735,7 +5745,7 @@ uint16_t WS2812FX::mode_2Dmatrix(void) { // Matrix2D. By Jeremy

uint16_t WS2812FX::mode_2Dmeatballs(void) { // Metaballs by Stefan Petrick. Cannot have one of the dimensions be 2 or less. Adapted by Andrew Tuline.

if (matrixWidth * matrixHeight > SEGLEN) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.
if (matrixWidth * matrixHeight > SEGLEN || matrixWidth < 4 || matrixHeight < 4) {return blink(CRGB::Red, CRGB::Black, false, false);} // No, we're not going to overrun the segment.

CRGB *leds = (CRGB* )ledData;

Expand Down

0 comments on commit 6227380

Please sign in to comment.