esp-videoswitcher/NeoPatterns.h

212 lines
6.2 KiB
C++

#include <Adafruit_NeoPixel.h>
// Pattern types supported:
enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, RADAR, FILL, RANDOM };
// Patern directions supported:
enum direction { FORWARD, REVERSE };
class NeoPatterns : public Adafruit_NeoPixel
{
public:
NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)());
void Update();
void Reverse();
void None(uint8_t interval = 40);
void Stop(uint8_t interval = 40);
void RainbowCycle(uint8_t interval, direction dir = FORWARD);
void RainbowCycleUpdate();
void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir = FORWARD);
void TheaterChaseUpdate();
void ColorWipe(uint32_t color, uint8_t interval, direction dir = FORWARD);
void ColorWipeUpdate();
void Scanner(uint32_t color1 = 16711680, uint8_t interval = 40, bool colorful = false, bool spiral = false);
void ScannerUpdate();
void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD);
void FadeUpdate();
void RandomFade(uint8_t interval = 100);
void RandomFadeUpdate();
void RandomFadeSingle(uint8_t interval = 100, uint8_t speed = 5);
void RandomFadeSingleUpdate();
void RandomBuffer();
void Random();
void Smooth(uint8_t wheelSpeed = 16, uint8_t smoothing = 80, uint8_t strength = 50, uint8_t interval = 40);
void SmoothUpdate();
void Plasma(float phase = 0, float phaseIncrement = 0.08, float colorStretch = 0.11, uint8_t interval = 60); // 0.08 and 0.11 // 0.03 und 0.3
void PlasmaUpdate();
void Radar(float radarspeed = 0.5,float radarthickness = 1, uint8_t interval = 50);
void RadarUpdate();
void Equalizer(uint8_t eqvalues[]);
void setEqBar(uint8_t barid,uint8_t pvalue);
void SetColor1(uint32_t color);
void SetColor2(uint32_t color);
//Utilities
void ColorSet(uint32_t color);
struct box
{
int left;
int middle;
int right;
};
struct box boxs[25];
uint8_t boxcircle[20][6]={
{0,1,2,2,2,2},
{3,4,5,5,5,5},
{6,7,8,8,8,8},
{9,10,11,11,11,11},
{12,13,14,14,14,14},
{15,16,17,17,17,17},
{18,19,20,27,28,29},
{21,22,23,27,28,29},
{24,25,26,27,28,29},
{32,33,34,30,31,31},
{37,38,39,35,36,36},
{43,44,45,40,41,42},
{46,47,48,40,41,42},
{49,50,51,40,41,42},
{52,53,54,54,54,54},
{55,56,57,57,57,57},
{58,59,60,60,60,60},
{61,62,63,63,63,63},
{64,65,66,66,66,66},
{67,68,69,69,69,69}
};
/*uint8_t boxcircle[32][4]={
{0,0,0,0}, //0
{1,2,2,2},
{3,4,4,4},
{5,6,7,8}, //3
{9,10,11,11},
{12,13,13,13}, //5
{14,14,14,14},
{255,255,255,255},
{15,16,17,17},
{255,255,255,255},
{18,19,20,29}, //10
{22,23,27,28},
{21,25,26,30},
{24,31,32,33}, //13
{34,34,34,34},
{255,255,255,255}, //15
{255,255,255,255}, //16
{39,39,39,39},
{36,37,38,45},
{35,43,44,48}, //19
{41,42,46,47},
{40,49,50,51},
{255,255,255,255}, //22
{52,53,54,54},
{255,255,255,255},
{55,55,55,55},
{56,57,57,57},
{58,59,60,60}, //27
{61,62,63,64},
{65,66,66,66},
{67,68,68,68},
{69,69,69,69} //31
};*/
uint8_t ledEq[18][8]={
{23,20,17,14,11,8,8,8},
{22,19,16,13,10,7,7,7},
{21,18,15,12,9,6,6,6},
{26,29,255,255,255,5,5,5},
{25,28,255,255,255,4,4,4},
{24,27,255,255,255,3,3,3},
{34,33,32,31,30,2,2,2},
{255,255,255,255,255,1,1,1},
{255,255,255,255,255,0,0,0},
{255,255,255,255,255,69,69,69},
{255,255,255,255,255,68,68,68},
{39,38,37,36,35,67,67,67},
{45,42,255,255,255,66,66,66},
{44,41,255,255,255,65,65,65},
{43,40,255,255,255,64,64,64},
{48,51,54,57,60,63,63,63},
{47,50,53,56,59,62,62,62},
{46,49,52,55,58,61,61,61}
};
void setupboxs();
void colorBox(uint8_t boxid, uint32_t c);
void colorCircleSegment(uint8_t segmentid, uint32_t c);
void ColorSetParameters(String parameters);
uint8_t Red(uint32_t color);
uint8_t Green(uint32_t color);
uint8_t Blue(uint32_t color);
uint32_t Wheel(byte WheelPos);
uint8_t numToSpiralPos(int num);
uint8_t xyToPos(int x, int y);
uint8_t numToPos(int num);
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
uint32_t parseColor(String value);
private:
// Member Variables:
pattern ActivePattern; // which pattern is running
pattern SavedPattern;
direction Direction; // direction to run the pattern
direction SavedDirection;
unsigned long Interval; // milliseconds between updates
unsigned long SavedInterval;
unsigned long lastUpdate; // last update of position
uint32_t Color1, Color2; // What colors are in use
uint32_t SavedColor1;
uint16_t TotalSteps; // total number of steps in the pattern
uint16_t SavedTotalSteps;
uint16_t Index; // current step within the pattern
uint16_t SavedIndex;
uint8_t Every; // Turn every "Every" pixel in Color1/Color2
byte wPos;
bool colorful;
bool spiral;
uint8_t wPosSlow;
uint8_t WheelSpeed;
uint8_t Smoothing;
uint8_t Strength;
uint8_t movingPoint_x;
uint8_t movingPoint_y;
uint8_t *pixelR;
uint8_t *pixelG;
uint8_t *pixelB;
uint8_t *pixelR_buffer;
uint8_t *pixelG_buffer;
uint8_t *pixelB_buffer;
float PlasmaPhase;
float SavedPlasmaPhase;
float PlasmaPhaseIncrement;
float SavedPlasmaPhaseIncrement;
float PlasmaColorStretch;
float SavedPlasmaColorStretch;
float Radarposition;
float Radarspeed;
float Radarthickness;
float Radarfadelength;
float Radardotposition;
uint8_t Radardotbrightness;
uint8_t Radardotfadespeed;
uint32_t DimColor(uint32_t color);
void Increment();
void (*OnComplete)(); // Callback on completion of pattern
// Convenient 2D point structure
struct Point {
float x;
float y;
};
};