some more fixes for Aurora effects

Signed-off-by: Emil Muratov <gpm@hotplug.ru>
This commit is contained in:
Emil Muratov 2020-12-02 22:39:03 +03:00
parent ba58902843
commit 2d38f96722
7 changed files with 72 additions and 47 deletions

View file

@ -99,7 +99,7 @@ void loop()
} }
if (fps_timer + 1000 < millis()){ if (fps_timer + 1000 < millis()){
Serial.printf_P(PSTR("Effect fps: %d\n"), fps); Serial.printf_P(PSTR("Effect fps: %ld\n"), fps);
fps_timer = millis(); fps_timer = millis();
fps = 0; fps = 0;
} }

View file

@ -42,6 +42,9 @@ const int MATRIX_CENTER_Y = MATRIX_HEIGHT / 2;
const uint16_t NUM_LEDS = (MATRIX_WIDTH * MATRIX_HEIGHT) + 1; // one led spare to capture out of bounds const uint16_t NUM_LEDS = (MATRIX_WIDTH * MATRIX_HEIGHT) + 1; // one led spare to capture out of bounds
// forward declaration
uint16_t XY16( uint16_t x, uint16_t y);
/* Convert x,y co-ordinate to flat array index. /* Convert x,y co-ordinate to flat array index.
* x and y positions start from 0, so must not be >= 'real' panel width or height * x and y positions start from 0, so must not be >= 'real' panel width or height
* (i.e. 64 pixels or 32 pixels.). Max value: MATRIX_WIDTH-1 etc. * (i.e. 64 pixels or 32 pixels.). Max value: MATRIX_WIDTH-1 etc.
@ -49,15 +52,11 @@ const uint16_t NUM_LEDS = (MATRIX_WIDTH * MATRIX_HEIGHT) + 1; // one led spare t
*/ */
uint16_t XY( uint8_t x, uint8_t y) uint16_t XY( uint8_t x, uint8_t y)
{ {
if( x >= MATRIX_WIDTH) return 0; return XY16(x, y);
if( y >= MATRIX_HEIGHT) return 0;
return (y * MATRIX_WIDTH) + x + 1; // everything offset by one to capute out of bounds stuff - never displayed by ShowFrame()
} }
/** /**
* This one is for 256+ matrixes * The one for 256+ matrixes
* otherwise this: * otherwise this:
* for (uint8_t i = 0; i < MATRIX_WIDTH; i++) {} * for (uint8_t i = 0; i < MATRIX_WIDTH; i++) {}
* turns into an infinite loop * turns into an infinite loop
@ -106,7 +105,8 @@ uint32_t noise_z;
uint32_t noise_scale_x; uint32_t noise_scale_x;
uint32_t noise_scale_y; uint32_t noise_scale_y;
uint8_t noise[MATRIX_WIDTH][MATRIX_HEIGHT]; //uint8_t noise[MATRIX_WIDTH][MATRIX_HEIGHT];
uint8_t **noise = nullptr; // we will allocate mem later
uint8_t noisesmoothing; uint8_t noisesmoothing;
class Effects { class Effects {
@ -116,12 +116,25 @@ public:
//CRGB leds2[NUM_LEDS]; // Faptastic: getting rid of this and any dependant effects or algos. to save memory 24*64*32 bytes of ram (50k). //CRGB leds2[NUM_LEDS]; // Faptastic: getting rid of this and any dependant effects or algos. to save memory 24*64*32 bytes of ram (50k).
Effects(){ Effects(){
// we do dynamic allocation for leds buffer, otherwise esp32 toolchain can't link static arrays of this size for 256+ matrixes // we do dynamic allocation for leds buffer, otherwise esp32 toolchain can't link static arrays of such a big size for 256+ matrixes
leds = (CRGB *)malloc(NUM_LEDS * sizeof(CRGB)); leds = (CRGB *)malloc(NUM_LEDS * sizeof(CRGB));
// allocate mem for noise effect
// (there should be some guards for malloc errors eventually)
noise = (uint8_t **)malloc(MATRIX_WIDTH * sizeof(uint8_t *));
for (int i = 0; i < MATRIX_WIDTH; ++i) {
noise[i] = (uint8_t *)malloc(MATRIX_HEIGHT * sizeof(uint8_t));
}
ClearFrame(); ClearFrame();
matrix.clearScreen();
} }
~Effects(){ ~Effects(){
free(leds); free(leds);
for (int i = 0; i < MATRIX_WIDTH; ++i) {
free(noise[i]);
}
free(noise);
} }
/* The only 'framebuffer' we have is what is contained in the leds and leds2 variables. /* The only 'framebuffer' we have is what is contained in the leds and leds2 variables.
@ -158,15 +171,14 @@ public:
// leds = (CRGB*) backgroundLayer.backBuffer(); // leds = (CRGB*) backgroundLayer.backBuffer();
// LEDS.countFPS(); // LEDS.countFPS();
for (int y=0; y<MATRIX_HEIGHT; ++y){
for (int y=0;y<MATRIX_HEIGHT; y++) for (int x=0; x<MATRIX_WIDTH; ++x){
for (int x=0;x<MATRIX_WIDTH; x++) //Serial.printf("Flushing x, y coord %d, %d\n", x, y);
{ uint16_t _pixel = XY16(x,y);
//Serial.printf("\r\nFlushing x, y coord %d, %d", x, y); matrix.drawPixelRGB888( x, y, leds[_pixel].r, leds[_pixel].g, leds[_pixel].b);
//display.drawPixelRGB888( x, 31-y, tmp_led.r, tmp_led.g, tmp_led.b);
matrix.drawPixelRGB888( x, y, leds[XY16(x,y)].r, leds[XY16(x,y)].g, leds[XY16(x,y)].b);
} // end loop to copy fast led to the dma matrix } // end loop to copy fast led to the dma matrix
} }
}
// scale the brightness of the screenbuffer down // scale the brightness of the screenbuffer down
void DimAll(byte value) void DimAll(byte value)
@ -180,7 +192,6 @@ public:
void ClearFrame() void ClearFrame()
{ {
memset(leds, 0x00, NUM_LEDS * sizeof(CRGB)); // flush memset(leds, 0x00, NUM_LEDS * sizeof(CRGB)); // flush
matrix.clearScreen();
} }
@ -419,8 +430,8 @@ public:
// copy one diagonal triangle into the other one within a 16x16 // copy one diagonal triangle into the other one within a 16x16
void Caleidoscope3() { void Caleidoscope3() {
for (int x = 0; x <= MATRIX_CENTRE_X; x++) { for (int x = 0; x <= MATRIX_CENTRE_X && x < MATRIX_HEIGHT; x++) {
for (int y = 0; y <= x; y++) { for (int y = 0; y <= x && y<MATRIX_HEIGHT; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)]; leds[XY16(x, y)] = leds[XY16(y, x)];
} }
} }
@ -438,7 +449,7 @@ public:
// copy one diagonal triangle into the other one within a 8x8 // copy one diagonal triangle into the other one within a 8x8
void Caleidoscope5() { void Caleidoscope5() {
for (int x = 0; x < MATRIX_WIDTH / 4; x++) { for (int x = 0; x < MATRIX_WIDTH / 4; x++) {
for (int y = 0; y <= x; y++) { for (int y = 0; y <= x && y<=MATRIX_HEIGHT; y++) {
leds[XY16(x, y)] = leds[XY16(y, x)]; leds[XY16(x, y)] = leds[XY16(y, x)];
} }
} }

View file

@ -31,7 +31,9 @@ public:
unsigned int drawFrame() { unsigned int drawFrame() {
// dim all pixels on the display slightly // dim all pixels on the display slightly
// to 250/255 (98%) of their current brightness // to 250/255 (98%) of their current brightness
effects.DimAll(250); effects.ShowFrame(); blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, 250);
// effects.DimAll(250); effects.ShowFrame();
// the Effects class has some sample oscillators // the Effects class has some sample oscillators
// that move from 0 to 255 at different speeds // that move from 0 to 255 at different speeds
@ -51,7 +53,8 @@ public:
// draw a pixel at x,y using a color from the current palette // draw a pixel at x,y using a color from the current palette
effects.Pixel(x, y, hue); effects.Pixel(x, y, hue);
return 15; effects.ShowFrame();
return 30;
} }
}; };

View file

@ -34,6 +34,12 @@
#ifndef PatternPendulumWave_H #ifndef PatternPendulumWave_H
#define PatternPendulumWave_H #define PatternPendulumWave_H
#define WAVE_BPM 25
#define AMP_BPM 2
#define SKEW_BPM 4
#define WAVE_TIMEMINSKEW MATRIX_WIDTH/8
#define WAVE_TIMEMAXSKEW MATRIX_WIDTH/2
class PatternPendulumWave : public Drawable { class PatternPendulumWave : public Drawable {
public: public:
PatternPendulumWave() { PatternPendulumWave() {
@ -41,15 +47,19 @@ class PatternPendulumWave : public Drawable {
} }
unsigned int drawFrame() { unsigned int drawFrame() {
effects.DimAll(170); effects.ShowFrame(); effects.ClearFrame();
for (int x = 0; x < MATRIX_WIDTH; x++) for (int x = 0; x < MATRIX_WIDTH; ++x)
{ {
uint8_t y = beatsin8(x + MATRIX_WIDTH, 0, MATRIX_HEIGHT); uint16_t amp = beatsin16(AMP_BPM, MATRIX_HEIGHT/8, MATRIX_HEIGHT-1);
uint16_t offset = (MATRIX_HEIGHT - beatsin16(AMP_BPM, 0, MATRIX_HEIGHT))/2;
uint8_t y = beatsin16(WAVE_BPM, 0, amp, x*beatsin16(SKEW_BPM, WAVE_TIMEMINSKEW, WAVE_TIMEMAXSKEW)) + offset;
effects.drawBackgroundFastLEDPixelCRGB(x, y, effects.ColorFromCurrentPalette(x * 7)); effects.drawBackgroundFastLEDPixelCRGB(x, y, effects.ColorFromCurrentPalette(x * 7));
} }
effects.ShowFrame();
return 10; return 20;
} }
}; };

View file

@ -51,7 +51,7 @@ class PatternSpiro : public Drawable {
}; };
unsigned int drawFrame() { unsigned int drawFrame() {
effects.DimAll(1); blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, 192);
boolean change = false; boolean change = false;

View file

@ -44,27 +44,28 @@ class PatternSwirl : public Drawable {
// Note that we never actually clear the matrix, we just constantly // Note that we never actually clear the matrix, we just constantly
// blur it repeatedly. Since the blurring is 'lossy', there's // blur it repeatedly. Since the blurring is 'lossy', there's
// an automatic trend toward black -- by design. // an automatic trend toward black -- by design.
uint8_t blurAmount = beatsin8(2, 10, 255); uint8_t blurAmount = beatsin8(2, 10, 255)
#if FASTLED_VERSION >= 3001000 #if FASTLED_VERSION >= 3001000
blur2d(effects.leds, MATRIX_WIDTH, MATRIX_HEIGHT, blurAmount); blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, blurAmount);
#else #else
effects.DimAll(blurAmount); effects.DimAll(blurAmount);
#endif #endif
// Use two out-of-sync sine waves // Use two out-of-sync sine waves
uint8_t i = beatsin8(13, borderWidth, MATRIX_HEIGHT - borderWidth); uint8_t i = beatsin8(256/MATRIX_HEIGHT, borderWidth, MATRIX_WIDTH - borderWidth);
uint8_t j = beatsin8(27, borderWidth, MATRIX_WIDTH - borderWidth); uint8_t j = beatsin8(2048/MATRIX_WIDTH, borderWidth, MATRIX_HEIGHT - borderWidth);
// Also calculate some reflections // Also calculate some reflections
uint8_t ni = (MATRIX_WIDTH - 1) - i; uint8_t ni = (MATRIX_WIDTH - 1) - i;
uint8_t nj = (MATRIX_WIDTH - 1) - j; uint8_t nj = (MATRIX_HEIGHT - 1) - j;
// The color of each point shifts over time, each at a different speed. // The color of each point shifts over time, each at a different speed.
uint16_t ms = millis(); uint16_t ms = millis();
effects.leds[XY(i, j)] += effects.ColorFromCurrentPalette(ms / 11); effects.leds[XY(i, j)] += effects.ColorFromCurrentPalette(ms / 11);
effects.leds[XY(j, i)] += effects.ColorFromCurrentPalette(ms / 13); //effects.leds[XY(j, i)] += effects.ColorFromCurrentPalette(ms / 13); // this doesn't work for non-square matrixes
effects.leds[XY(ni, nj)] += effects.ColorFromCurrentPalette(ms / 17); effects.leds[XY(ni, nj)] += effects.ColorFromCurrentPalette(ms / 17);
effects.leds[XY(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29); //effects.leds[XY(nj, ni)] += effects.ColorFromCurrentPalette(ms / 29); // this doesn't work for non-square matrixes
effects.leds[XY(i, nj)] += effects.ColorFromCurrentPalette(ms / 37); effects.leds[XY(i, nj)] += effects.ColorFromCurrentPalette(ms / 37);
effects.leds[XY(ni, j)] += effects.ColorFromCurrentPalette(ms / 41); effects.leds[XY(ni, j)] += effects.ColorFromCurrentPalette(ms / 41);

View file

@ -56,7 +56,7 @@
#include "PatternInfinity.h" #include "PatternInfinity.h"
#include "PatternPlasma.h" #include "PatternPlasma.h"
#include "PatternSnake.h" #include "PatternSnake.h"
//#include "PatternInvaders.h" // Doesn't seem to work, omitting. #include "PatternInvaders.h"
//#include "PatternCube.h" // Doesn't seem to work, omitting. //#include "PatternCube.h" // Doesn't seem to work, omitting.
//#include "PatternFire.h" // Doesn't seem to work, omitting. //#include "PatternFire.h" // Doesn't seem to work, omitting.
#include "PatternLife.h" #include "PatternLife.h"
@ -81,7 +81,7 @@ class Patterns : public Playlist {
PatternSwirl swirl; PatternSwirl swirl;
PatternPendulumWave pendulumWave; PatternPendulumWave pendulumWave;
PatternFlowField flowField; PatternFlowField flowField;
// PatternIncrementalDrift incrementalDrift; PatternIncrementalDrift incrementalDrift;
// PatternIncrementalDrift2 incrementalDrift2; // PatternIncrementalDrift2 incrementalDrift2;
PatternMunch munch; PatternMunch munch;
PatternElectricMandala electricMandala; PatternElectricMandala electricMandala;
@ -93,7 +93,7 @@ class Patterns : public Playlist {
PatternFlock flock; PatternFlock flock;
PatternInfinity infinity; PatternInfinity infinity;
PatternPlasma plasma; PatternPlasma plasma;
// PatternInvadersSmall invadersSmall; PatternInvadersSmall invadersSmall;
// PatternInvadersMedium invadersMedium; // PatternInvadersMedium invadersMedium;
// PatternInvadersLarge invadersLarge; // PatternInvadersLarge invadersLarge;
PatternSnake snake; PatternSnake snake;
@ -114,7 +114,7 @@ class Patterns : public Playlist {
//const static int PATTERN_COUNT = 37; //const static int PATTERN_COUNT = 37;
const static int PATTERN_COUNT = 16; const static int PATTERN_COUNT = 17;
Drawable* shuffledItems[PATTERN_COUNT]; Drawable* shuffledItems[PATTERN_COUNT];
@ -133,13 +133,13 @@ class Patterns : public Playlist {
&flowField, &flowField,
&pendulumWave, //11 ok &pendulumWave, //11 ok
// &incrementalDrift, //12 ok &incrementalDrift, //12 ok
// &incrementalDrift2, // 13 fail // &incrementalDrift2, // 13 fail
&munch, // 14 ok &munch, // 14 ok
&electricMandala, // 15 ok &electricMandala, // 15 ok
// &spin, // 16 ok but repeditivev // &spin, // 16 ok but repeditivev
&simplexNoise, // 17 - cool! &simplexNoise, // 17 - cool!
&wave, // 18 ok // &wave, // 18 ok (can't work with 256+ matrix due to uint8_t vars)
// &rainbowFlag, //20 // fail // &rainbowFlag, //20 // fail
&attract, // 21 ok &attract, // 21 ok
&swirl, // 22 &swirl, // 22
@ -147,7 +147,7 @@ class Patterns : public Playlist {
&flock, // works &flock, // works
&infinity, // works &infinity, // works
&plasma, // works &plasma, // works
// &invadersSmall, // works ish &invadersSmall, // works ish
// &invadersMedium, // fail // &invadersMedium, // fail
// &invadersLarge, // fail // &invadersLarge, // fail
&snake, // ok &snake, // ok