G.U.L.L.S. rebuilt to use PlatformIO
This commit is contained in:
46
include/AlternateMatrix.h
Normal file
46
include/AlternateMatrix.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef ALTERNATEMATRIX_H
|
||||
#define ALTERNATEMATRIX_H
|
||||
|
||||
#include "LEDHAL2D.h"
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
enum AlternateType {
|
||||
HORIZONTAL_ALTERNATE,
|
||||
VERTICAL_ALTERNATE
|
||||
};
|
||||
|
||||
class AlternateMatrix : public MatrixAnimation {
|
||||
public:
|
||||
AlternateMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, CRGB* _colors,
|
||||
uint8_t _numColors, AlternateType _type) : MatrixAnimation(_matrix, _refName, _updateTime),
|
||||
numColors(_numColors), colors(new CRGB[_numColors]), alternateInt(0), type(_type) {
|
||||
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
virtual ~AlternateMatrix() { delete colors; }
|
||||
|
||||
void initialize() {
|
||||
alternateInt = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
AlternateType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
alternateInt;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
AlternateType
|
||||
type;
|
||||
};
|
||||
|
||||
#endif
|
||||
34
include/AlternateStrip.h
Normal file
34
include/AlternateStrip.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef ALTERNATESTRIP_H
|
||||
#define ALTERNATESTRIP_H
|
||||
|
||||
#include "LEDHAL.h"
|
||||
#include "StripAnimation.h"
|
||||
|
||||
class AlternateStrip : public StripAnimation {
|
||||
public:
|
||||
AlternateStrip(LEDHAL* _strip, char* _refName, long _updateTime, CRGB* _colors,
|
||||
uint8_t _numColors) : StripAnimation(_strip, _refName, _updateTime),
|
||||
numColors(_numColors), colors(new CRGB[_numColors]), alternateInt(0) {
|
||||
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
virtual ~AlternateStrip() { delete colors; }
|
||||
|
||||
void initialize() {
|
||||
alternateInt = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
private:
|
||||
uint16_t
|
||||
alternateInt;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
};
|
||||
|
||||
#endif
|
||||
75
include/AnimationBase.h
Normal file
75
include/AnimationBase.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef ANIMATIONBASE_H
|
||||
#define ANIMATIONBASE_H
|
||||
|
||||
#include "elapsedMillis.h"
|
||||
|
||||
class AnimationBase {
|
||||
public:
|
||||
AnimationBase(char* _refName, long _updateTime)
|
||||
: refName(_refName), updateTime(_updateTime),
|
||||
enabled(false), initialized(false), timer(0) {}
|
||||
virtual ~AnimationBase() {
|
||||
delete refName;
|
||||
}
|
||||
|
||||
virtual void initialize() {}
|
||||
virtual void execute() {}
|
||||
virtual bool isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (enabled) {
|
||||
if (timer >= updateTime) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
if (!isFinished()) {
|
||||
execute();
|
||||
}
|
||||
|
||||
resetTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
void reinitialize() {
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
bool isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
char* getReferenceName() {
|
||||
return refName;
|
||||
}
|
||||
|
||||
protected:
|
||||
void resetTimer() {
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
char*
|
||||
refName;
|
||||
long
|
||||
updateTime;
|
||||
bool
|
||||
enabled,
|
||||
initialized;
|
||||
elapsedMillis
|
||||
timer;
|
||||
};
|
||||
|
||||
#endif
|
||||
73
include/CLEDControllerPhysicalMatrix.h
Normal file
73
include/CLEDControllerPhysicalMatrix.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef CLEDCONTROLLERPHYSICALMATRIX_H
|
||||
#define CLEDCONTROLLERPHYSICALMATRIX_H
|
||||
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
enum ArrangementType {
|
||||
HORIZONTALSCAN,
|
||||
HORIZONTALSERPENTINE,
|
||||
COLUMNSCAN,
|
||||
COLUMNSERPENTINE
|
||||
};
|
||||
|
||||
class CLEDControllerPhysicalMatrix : public LEDHAL2D {
|
||||
public:
|
||||
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ArrangementType _arrangement,
|
||||
int16_t width, int16_t height): LEDHAL2D(width, height, ledName, true), controller(_controller), arrangement(_arrangement) {}
|
||||
virtual ~CLEDControllerPhysicalMatrix() {}
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, CRGB color) {
|
||||
controller->leds()[XY(x, y)] = color;
|
||||
}
|
||||
|
||||
void setColor(int16_t pixel, CRGB color) {
|
||||
controller->leds()[pixel] = color;
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t pixel) {
|
||||
return controller->leds()[pixel];
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t x, int16_t y) {
|
||||
return getColor(XY(x, y));
|
||||
}
|
||||
|
||||
int16_t XY(int16_t x, int16_t y) {
|
||||
if(arrangement == ArrangementType::HORIZONTALSCAN) {
|
||||
return getWidth() * y + x;
|
||||
} else if(arrangement == ArrangementType::COLUMNSCAN) {
|
||||
return getHeight() * x + y;
|
||||
} else if(arrangement == ArrangementType::HORIZONTALSERPENTINE) {
|
||||
if(y & 0x1) {
|
||||
return y * getWidth() + (getWidth() - 1 - x);
|
||||
} else {
|
||||
return y * getWidth() + x;
|
||||
}
|
||||
} else if(arrangement == ArrangementType::COLUMNSERPENTINE) {
|
||||
if(x & 0x1) {
|
||||
return x * getHeight() + (getHeight() - 1 - y);
|
||||
} else {
|
||||
return x * getHeight() + y;
|
||||
}
|
||||
} else {
|
||||
return 0; //How did you get here?
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t getNumLEDs() {
|
||||
return getWidth() * getHeight();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateLEDs() {
|
||||
controller->showLeds();
|
||||
}
|
||||
|
||||
private:
|
||||
CLEDController*
|
||||
controller;
|
||||
ArrangementType
|
||||
arrangement;
|
||||
};
|
||||
|
||||
#endif
|
||||
24
include/CLEDControllerPhysicalStrip.h
Normal file
24
include/CLEDControllerPhysicalStrip.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef CLEDCONTROLLERPHYSICALSTRIP_H
|
||||
#define CLEDCONTROLLERPHYSICALSTRIP_H
|
||||
|
||||
#include "LEDHAL.h"
|
||||
|
||||
class CLEDControllerPhysicalStrip : public LEDHAL {
|
||||
public:
|
||||
CLEDControllerPhysicalStrip(CLEDController* _controller, char* _ledName) :
|
||||
LEDHAL(_ledName, true), controller(_controller) {}
|
||||
|
||||
uint16_t getNumLEDs() { return controller->size(); }
|
||||
CRGB getColor(int16_t pixel) { return controller->leds()[pixel]; }
|
||||
void setColor(int16_t pixel, CRGB color) { controller->leds()[pixel] = color; }
|
||||
|
||||
protected:
|
||||
void updateLEDs() { controller->showLeds(); }
|
||||
|
||||
|
||||
private:
|
||||
CLEDController*
|
||||
controller;
|
||||
};
|
||||
|
||||
#endif
|
||||
39
include/CollisionMatrix.h
Normal file
39
include/CollisionMatrix.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef COLLISIONMATRIX_H
|
||||
#define COLLISIONMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
enum CollisionType {
|
||||
HORIZONTAL_COLLISION,
|
||||
VERTICAL_COLLISION
|
||||
};
|
||||
|
||||
class CollisionMatrix : public MatrixAnimation {
|
||||
public:
|
||||
CollisionMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, CRGB _color1,
|
||||
CRGB _color2, CollisionType _type) : MatrixAnimation(_matrix, _refName, _updateTime),
|
||||
color1(_color1), color2(_color2), type(_type), collisionInt(0) {}
|
||||
virtual ~CollisionMatrix() {}
|
||||
|
||||
void initialize() {
|
||||
collisionInt = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
CollisionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
collisionInt;
|
||||
CRGB
|
||||
color1,
|
||||
color2;
|
||||
CollisionType
|
||||
type;
|
||||
};
|
||||
|
||||
#endif
|
||||
28
include/CollisionStrip.h
Normal file
28
include/CollisionStrip.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef COLLISIONSTRIP_H
|
||||
#define COLLISIONSTRIP_H
|
||||
|
||||
#include "StripAnimation.h"
|
||||
#include "LEDHAL.h"
|
||||
|
||||
class CollisionStrip : public StripAnimation {
|
||||
public:
|
||||
CollisionStrip(LEDHAL* _strip, char* _refName, long _updateTime, CRGB _color1,
|
||||
CRGB _color2) : StripAnimation(_strip, _refName, _updateTime), color1(_color1),
|
||||
color2(_color2), collisionInt(0) {}
|
||||
virtual ~CollisionStrip() {}
|
||||
|
||||
void initialize() {
|
||||
collisionInt = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
private:
|
||||
uint16_t
|
||||
collisionInt;
|
||||
CRGB
|
||||
color1,
|
||||
color2;
|
||||
};
|
||||
|
||||
#endif
|
||||
68
include/ColorRandomizerMatrix.h
Normal file
68
include/ColorRandomizerMatrix.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef COLORRANDOMIZERMATRIX_H
|
||||
#define COLORRANDOMIZERMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
#define DEFAULT_MATRIX_FADER 64
|
||||
|
||||
enum ColorRandomizerType {
|
||||
HORIZONTAL_COLORRANDOMIZER,
|
||||
VERTICAL_COLORRANDOMIZER
|
||||
};
|
||||
|
||||
class ColorRandomizerMatrix : public MatrixAnimation {
|
||||
public:
|
||||
ColorRandomizerMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, bool _fade,
|
||||
uint8_t _numColors, CRGB* _colors, ColorRandomizerType _type) :
|
||||
MatrixAnimation(_matrix, _refName, _updateTime), numColors(_numColors),
|
||||
colors(new CRGB[_numColors]), fade(_fade), colorRandomizerInt(0),
|
||||
scale(DEFAULT_MATRIX_FADER) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~ColorRandomizerMatrix() { delete colors; delete fadingValues; }
|
||||
|
||||
void initialize() {
|
||||
colorRandomizerInt = 0;
|
||||
isFading = false;
|
||||
|
||||
if(fadingValues != nullptr) {
|
||||
delete fadingValues;
|
||||
}
|
||||
|
||||
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
|
||||
fadingValues = new CRGB[matrix->getHeight()];
|
||||
} else {
|
||||
fadingValues = new CRGB[matrix->getWidth()];
|
||||
}
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
void setFade(bool _fade) { fade = _fade; initialize(); }
|
||||
bool getFade() { return fade; }
|
||||
void setFadeScale(uint8_t _scale) { scale = _scale; initialize(); }
|
||||
uint8_t getFadeScale() { return scale; }
|
||||
void setType(ColorRandomizerType _type) { type = _type; initialize(); }
|
||||
ColorRandomizerType getType() { return type; }
|
||||
|
||||
private:
|
||||
CRGB
|
||||
*colors,
|
||||
*fadingValues;
|
||||
uint16_t
|
||||
colorRandomizerInt;
|
||||
uint8_t
|
||||
scale,
|
||||
numColors;
|
||||
bool
|
||||
isFading,
|
||||
fade;
|
||||
ColorRandomizerType
|
||||
type;
|
||||
};
|
||||
|
||||
#endif
|
||||
50
include/ColorRandomizerStrip.h
Normal file
50
include/ColorRandomizerStrip.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef COLORRANDOMIZERSTRIP_H
|
||||
#define COLORRANDOMIZERSTRIP_H
|
||||
|
||||
#include "StripAnimation.h"
|
||||
#include "LEDHAL.h"
|
||||
|
||||
#define DEFAULT_STRIP_FADER 64
|
||||
|
||||
class ColorRandomizerStrip : public StripAnimation {
|
||||
public:
|
||||
ColorRandomizerStrip(LEDHAL* _strip, char* _refName, long _updateTime, bool _fade,
|
||||
uint8_t _numColors, CRGB* _colors) : StripAnimation(_strip, _refName, _updateTime),
|
||||
numColors(_numColors), colors(new CRGB[_numColors]),
|
||||
fadingValues(new CRGB[_numColors]), fade(_fade), colorRandomizerInt(0),
|
||||
scale(DEFAULT_STRIP_FADER) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~ColorRandomizerStrip() { delete colors; delete fadingValues; }
|
||||
|
||||
void initialize() {
|
||||
colorRandomizerInt = 0;
|
||||
isFading = false;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
void setFade(bool _fade) { fade = _fade; initialize(); }
|
||||
bool getFade() { return fade; }
|
||||
void setFadeScale(uint8_t _scale) { scale = _scale; initialize(); }
|
||||
uint8_t getFadeScale() { return scale; }
|
||||
|
||||
private:
|
||||
CRGB
|
||||
*colors,
|
||||
*fadingValues;
|
||||
uint16_t
|
||||
colorRandomizerInt;
|
||||
uint8_t
|
||||
scale,
|
||||
numColors;
|
||||
bool
|
||||
isFading,
|
||||
fade;
|
||||
};
|
||||
|
||||
#endif
|
||||
47
include/CycleLightMatrix.h
Normal file
47
include/CycleLightMatrix.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef CYCLELIGHTMATRIX_H
|
||||
#define CYCLELIGHTMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
enum CycleLightType {
|
||||
HORIZONTAL_CYCLELIGHT,
|
||||
VERTICAL_CYCLELIGHT
|
||||
};
|
||||
|
||||
class CycleLightMatrix : public MatrixAnimation {
|
||||
public:
|
||||
CycleLightMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, CRGB* _colors,
|
||||
uint8_t _numColors, CycleLightType _type) : MatrixAnimation(_matrix, _refName,
|
||||
_updateTime), numColors(_numColors), colors(new CRGB[_numColors]),
|
||||
cycleLightInt(0), cycleLightColor(0), type(_type) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
virtual ~CycleLightMatrix() { delete colors; }
|
||||
|
||||
void initialize() {
|
||||
cycleLightInt = 0;
|
||||
cycleLightColor = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
CycleLightType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
cycleLightInt,
|
||||
cycleLightColor;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
CycleLightType
|
||||
type;
|
||||
};
|
||||
|
||||
#endif
|
||||
38
include/CycleLightStrip.h
Normal file
38
include/CycleLightStrip.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef CYCLELIGHTSTRIP_H
|
||||
#define CYCLELIGHTSTRIP_H
|
||||
|
||||
#include "StripAnimation.h"
|
||||
#include "LEDHAL.h"
|
||||
|
||||
class CycleLightStrip : public StripAnimation {
|
||||
public:
|
||||
CycleLightStrip(LEDHAL* _strip, char* _refName, long _updateTime, uint8_t _numColors,
|
||||
CRGB* _colors) : StripAnimation(_strip, _refName, _updateTime),
|
||||
numColors(_numColors), colors(new CRGB[_numColors]), cycleLightInt(0),
|
||||
cycleLightColor(0) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~CycleLightStrip() { delete colors; }
|
||||
|
||||
void initialize() {
|
||||
cycleLightInt = 0;
|
||||
cycleLightColor = 0;
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
cycleLightInt,
|
||||
cycleLightColor;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
};
|
||||
|
||||
#endif
|
||||
60
include/CycloneHelper.h
Normal file
60
include/CycloneHelper.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef CYCLONEHELPER_H
|
||||
#define CYCLONEHELPER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Point2D.h"
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
class CycloneHelper {
|
||||
public:
|
||||
CycloneHelper(CRGB _color, uint16_t _originX, uint16_t _originY,
|
||||
uint8_t _radius, uint8_t _spinDirection) : color(_color), originX(_originX),
|
||||
originY(_originY), radius(_radius), spinDirection(_spinDirection),
|
||||
currentDrawAngle(0) {
|
||||
|
||||
numberOfTails = (uint8_t) round(PI * _radius * 2);
|
||||
|
||||
tailColors = new CRGB[numberOfTails];
|
||||
tailPoints = new Point2D[numberOfTails];
|
||||
|
||||
float redScaler = ((float) color.red) / numberOfTails;
|
||||
float greenScaler = ((float) color.green) / numberOfTails;
|
||||
float blueScaler = ((float) color.blue) / numberOfTails;
|
||||
|
||||
for(uint8_t i = 0; i < numberOfTails; i++) {
|
||||
tailColors[i] = CRGB(
|
||||
min(round(redScaler * (i + 1)), color.red),
|
||||
min(round(greenScaler * (i + 1)), color.green),
|
||||
min(round(blueScaler * (i + 1)), color.blue)
|
||||
);
|
||||
}
|
||||
|
||||
nextPoint = Point2D(
|
||||
_originX + (uint16_t) round(radius * cosf(currentDrawAngle)),
|
||||
_originY + (uint16_t) round(radius * sinf(currentDrawAngle))
|
||||
);
|
||||
}
|
||||
|
||||
void updateAndRedraw(LEDHAL2D* matrix);
|
||||
private:
|
||||
CRGB
|
||||
color;
|
||||
CRGB*
|
||||
tailColors;
|
||||
Point2D
|
||||
nextPoint;
|
||||
Point2D*
|
||||
tailPoints;
|
||||
int8_t
|
||||
spinDirection;
|
||||
uint8_t
|
||||
radius,
|
||||
numberOfTails;
|
||||
uint16_t
|
||||
originX,
|
||||
originY;
|
||||
int16_t
|
||||
currentDrawAngle;
|
||||
};
|
||||
|
||||
#endif
|
||||
63
include/CycloneMatrix.h
Normal file
63
include/CycloneMatrix.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef CYCLONEMATRIX_H
|
||||
#define CYCLONEMATRIX_H
|
||||
|
||||
#include "LEDHAL2D.h"
|
||||
#include "CycloneHelper.h"
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
class CycloneMatrix : public MatrixAnimation {
|
||||
public:
|
||||
CycloneMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, uint16_t originX,
|
||||
uint16_t originY, uint8_t _startRadius, uint8_t _endRadius, uint8_t numColors,
|
||||
CRGB* _colors) : MatrixAnimation(_matrix, _refName, _updateTime),
|
||||
startRadius(_startRadius), endRadius(_endRadius) {
|
||||
|
||||
colors = new CRGB[numColors];
|
||||
|
||||
for(uint8_t i = 0; i < numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
|
||||
helpers = new CycloneHelper*[_endRadius - _startRadius];
|
||||
|
||||
// The colors are currently being passed in such a way that I believe
|
||||
// there being taken into the CycloneHelper through value, rather than ByRef
|
||||
// i.e. wasting memory
|
||||
for(uint8_t i = 0; i < _endRadius - _startRadius; i++) {
|
||||
helpers[i] = new CycloneHelper(
|
||||
colors[random(0, numColors)],
|
||||
originX, originY,
|
||||
_startRadius + i,
|
||||
random(0, 100000) % 2 == 0 ? 1 : -1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~CycloneMatrix() { delete helpers; delete colors; }
|
||||
|
||||
// I don't know that there is a nice, memory friendly way to
|
||||
// reset this yet...
|
||||
void initialize() {
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute() {
|
||||
matrix->clearLEDs();
|
||||
|
||||
for(uint8_t i = 0; i < endRadius - startRadius; i++) {
|
||||
helpers[i]->updateAndRedraw(matrix);
|
||||
}
|
||||
|
||||
matrix->requestShow();
|
||||
}
|
||||
private:
|
||||
uint8_t
|
||||
startRadius,
|
||||
endRadius;
|
||||
CRGB*
|
||||
colors;
|
||||
CycloneHelper**
|
||||
helpers;
|
||||
};
|
||||
|
||||
#endif
|
||||
37
include/DecodingBitStream.h
Normal file
37
include/DecodingBitStream.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef DECODINGBITSTREAM_H
|
||||
#define DECODINGBITSTREAM_H
|
||||
|
||||
#include "SD.h"
|
||||
|
||||
class DecodingBitStream
|
||||
{
|
||||
public:
|
||||
DecodingBitStream(File* _stream, uint8_t _bytesAvailable, uint16_t _numberOfBitsInCode) :
|
||||
stream(_stream), bytesAvailable(_bytesAvailable), numberOfBitsInCode(_numberOfBitsInCode),
|
||||
bitBuffer(0), bitsAvailable(0) {}
|
||||
~DecodingBitStream() {}
|
||||
|
||||
void setNumberOfBitsInCode(uint16_t _numberOfBitsInCode) { numberOfBitsInCode = _numberOfBitsInCode; }
|
||||
void setBytesAvailable(uint8_t _bytesAvailable) { bytesAvailable = _bytesAvailable; }
|
||||
|
||||
uint16_t getCode();
|
||||
uint16_t getNumberOfBitsInCode() { return numberOfBitsInCode; }
|
||||
|
||||
bool dataRemainingInBlock() { return bytesAvailable > 0 || bitsAvailable > 0; }
|
||||
|
||||
static uint16_t getNumberOfBitsToRepresentValue(uint16_t value);
|
||||
|
||||
private:
|
||||
void
|
||||
verifyEnoughBits(void);
|
||||
uint16_t
|
||||
bitBuffer;
|
||||
uint8_t
|
||||
bytesAvailable,
|
||||
bitsAvailable,
|
||||
numberOfBitsInCode;
|
||||
File*
|
||||
stream;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
include/FireworksMatrix.h
Normal file
42
include/FireworksMatrix.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef FIREWORKSMATRIX_H
|
||||
#define FIREWORKSMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
typedef struct _firework_t {
|
||||
int16_t xPos;
|
||||
int16_t yPos;
|
||||
int16_t yMaxHeight;
|
||||
uint16_t currentRadius;
|
||||
uint16_t radius;
|
||||
CRGB color;
|
||||
bool isActive;
|
||||
} Firework_t;
|
||||
|
||||
class FireworksMatrix : public MatrixAnimation {
|
||||
public:
|
||||
FireworksMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, CRGB* _colors,
|
||||
uint8_t _numColors, uint8_t _maxRadius, uint8_t _maxFireworks) :
|
||||
MatrixAnimation(_matrix, _refName, _updateTime), colors(new CRGB[_numColors]),
|
||||
numColors(_numColors), maxRadius(_maxRadius), maxFireworks(_maxFireworks) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
virtual ~FireworksMatrix() { delete[] colors; delete[] fireworks; }
|
||||
|
||||
void initialize();
|
||||
void execute();
|
||||
|
||||
private:
|
||||
uint8_t
|
||||
maxFireworks,
|
||||
numColors,
|
||||
maxRadius;
|
||||
CRGB*
|
||||
colors;
|
||||
Firework_t*
|
||||
fireworks;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
include/FluidColorMatrix.h
Normal file
41
include/FluidColorMatrix.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef FLUIDCOLORMATRIX_H
|
||||
#define FLUIDCOLORMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
enum FluidColorType {
|
||||
PIXEL_BY_PIXEL_FLUIDCOLOR,
|
||||
HORIZONTAL_FLUIDCOLOR,
|
||||
VERTICAL_FLUIDCOLOR
|
||||
};
|
||||
|
||||
enum FluidColorResolution {
|
||||
FULL_FLUIDCOLOR,
|
||||
HALF_FLUIDCOLOR,
|
||||
QUATER_FLUIDCOLOR,
|
||||
EIGHTH_FLUIDCOLOR
|
||||
};
|
||||
|
||||
class FluidColorMatrix : public MatrixAnimation {
|
||||
public:
|
||||
FluidColorMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime,
|
||||
FluidColorType _type, FluidColorResolution _resolution) : MatrixAnimation(_matrix,
|
||||
_refName, _updateTime), type(_type), resolution(_resolution), colorShifter(0) {}
|
||||
virtual ~FluidColorMatrix() { delete[] colors; }
|
||||
|
||||
void initialize();
|
||||
void execute();
|
||||
private:
|
||||
uint16_t
|
||||
colorShifter;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
FluidColorType
|
||||
type;
|
||||
FluidColorResolution
|
||||
resolution;
|
||||
};
|
||||
|
||||
#endif
|
||||
89
include/GIFMatrix.h
Normal file
89
include/GIFMatrix.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifndef GIFMATRIX_H
|
||||
#define GIFMATRIX_H
|
||||
|
||||
#include "SD.h"
|
||||
#include "MatrixAnimation.h"
|
||||
|
||||
class GIFMatrix : public MatrixAnimation {
|
||||
public:
|
||||
GIFMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, File* _dataFile) :
|
||||
MatrixAnimation(_matrix, _refName, _updateTime), dataFile(_dataFile) {
|
||||
STANDARDHEADER[0] = 0x47;
|
||||
STANDARDHEADER[1] = 0x49;
|
||||
STANDARDHEADER[2] = 0x46;
|
||||
STANDARDHEADER[3] = 0x38;
|
||||
STANDARDHEADER[4] = 0x39;
|
||||
STANDARDHEADER[5] = 0x61;
|
||||
|
||||
if(!headerOK()) {
|
||||
// I can't throw exceptions, need to do something here...
|
||||
}
|
||||
|
||||
decodeLogicalDescriptor();
|
||||
|
||||
preImageDataBytes = 6 + 7 + (globalColorTableExists ? globalColorTableSize * 3 : 0);
|
||||
|
||||
lastCode = _dataFile->read();
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
// Reinitialization needs to be tested, this may not work correctly
|
||||
dataFile->seek(preImageDataBytes);
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void execute();
|
||||
bool headerOK();
|
||||
void decodeLogicalDescriptor();
|
||||
void decodeGlobalColorTable();
|
||||
void decodeGraphicControlExtension();
|
||||
void decodeApplicationExtension();
|
||||
void decodeImageDescriptor();
|
||||
void buildCodeTable();
|
||||
void drawForArray(CRGB* colorTable, uint16_t* indexes, uint16_t startingXPosition, uint16_t imageWidth);
|
||||
uint16_t readWord();
|
||||
|
||||
private:
|
||||
File*
|
||||
dataFile;
|
||||
uint16_t
|
||||
preImageDataBytes,
|
||||
currentXPosition,
|
||||
currentYPosition,
|
||||
gifCanvasWidth,
|
||||
gitCanvasHeight,
|
||||
currentImageLeft,
|
||||
currentImageTop,
|
||||
currentImageWidth,
|
||||
currentImageHeight,
|
||||
currentCCCode,
|
||||
currentEOICode;
|
||||
uint16_t**
|
||||
currentCodeTable;
|
||||
long
|
||||
delayTime;
|
||||
uint8_t
|
||||
lastCode,
|
||||
originalColorResolution,
|
||||
globalColorTableSize,
|
||||
globalColorTableBackgroundColorIndex,
|
||||
disposalMethodValue,
|
||||
userInputFlag,
|
||||
transparentColorFlag,
|
||||
transparentColorIndex,
|
||||
localColorTableSize,
|
||||
currentMinimumCodeSize;
|
||||
bool
|
||||
globalColorTableExists,
|
||||
globalColorTableSorted,
|
||||
localColorTableExists,
|
||||
interlaceFlag,
|
||||
localColorTableSorted;
|
||||
CRGB*
|
||||
globalColorTable,
|
||||
localColorTable;
|
||||
byte
|
||||
STANDARDHEADER[6];
|
||||
};
|
||||
|
||||
#endif
|
||||
312
include/GULLS_GFX.h
Normal file
312
include/GULLS_GFX.h
Normal file
@@ -0,0 +1,312 @@
|
||||
#ifndef _GULLS_GFX_H
|
||||
#define _GULLS_GFX_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "gfxfont.h"
|
||||
|
||||
#include "FastLED.h"
|
||||
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_SPIDevice.h>
|
||||
|
||||
/// A generic graphics superclass that can handle all sorts of drawing. At a
|
||||
/// minimum you can subclass and provide drawPixel(). At a maximum you can do a
|
||||
/// ton of overriding to optimize. Used for any/all Adafruit displays!
|
||||
class GULLS_GFX : public Print {
|
||||
|
||||
public:
|
||||
GULLS_GFX(int16_t w, int16_t h); // Constructor
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Draw to the screen/framebuffer/etc.
|
||||
Must be overridden in subclass.
|
||||
@param x X coordinate in pixels
|
||||
@param y Y coordinate in pixels
|
||||
@param color 16-bit pixel color.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
virtual void drawPixel(int16_t x, int16_t y, CRGB color) = 0;
|
||||
|
||||
// TRANSACTION API / CORE DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void startWrite(void);
|
||||
virtual void writePixel(int16_t x, int16_t y, CRGB color);
|
||||
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||
CRGB color);
|
||||
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, CRGB color);
|
||||
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, CRGB color);
|
||||
virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
CRGB color);
|
||||
virtual void endWrite(void);
|
||||
|
||||
// CONTROL API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void setRotation(uint8_t r);
|
||||
virtual void invertDisplay(bool i);
|
||||
|
||||
// BASIC DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
|
||||
// It's good to implement those, even if using transaction API
|
||||
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, CRGB color);
|
||||
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, CRGB color);
|
||||
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||
CRGB color);
|
||||
virtual void fillScreen(CRGB color);
|
||||
// Optional and probably not necessary to change
|
||||
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
CRGB color);
|
||||
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||
CRGB color);
|
||||
|
||||
// These exist only with GULLS_GFX (no subclass overrides)
|
||||
void drawCircle(int16_t x0, int16_t y0, int16_t r, CRGB color);
|
||||
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
CRGB color);
|
||||
void fillCircle(int16_t x0, int16_t y0, int16_t r, CRGB color);
|
||||
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
int16_t delta, CRGB color);
|
||||
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
|
||||
int16_t y2, CRGB color);
|
||||
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
|
||||
int16_t y2, CRGB color);
|
||||
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, CRGB color);
|
||||
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, CRGB color);
|
||||
void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
|
||||
int16_t h, CRGB color);
|
||||
void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
|
||||
int16_t h, CRGB color, CRGB bg);
|
||||
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h,
|
||||
CRGB color);
|
||||
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h,
|
||||
CRGB color, CRGB bg);
|
||||
void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
|
||||
int16_t h, CRGB color);
|
||||
void drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h);
|
||||
void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w,
|
||||
int16_t h);
|
||||
void drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
const uint8_t mask[], int16_t w, int16_t h);
|
||||
void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, uint8_t *mask,
|
||||
int16_t w, int16_t h);
|
||||
void drawRGBBitmap(int16_t x, int16_t y, const CRGB bitmap[], int16_t w,
|
||||
int16_t h);
|
||||
void drawRGBBitmap(int16_t x, int16_t y, CRGB *bitmap, int16_t w,
|
||||
int16_t h);
|
||||
void drawRGBBitmap(int16_t x, int16_t y, const CRGB bitmap[],
|
||||
const uint8_t mask[], int16_t w, int16_t h);
|
||||
void drawRGBBitmap(int16_t x, int16_t y, CRGB *bitmap, uint8_t *mask,
|
||||
int16_t w, int16_t h);
|
||||
void drawChar(int16_t x, int16_t y, unsigned char c, CRGB color,
|
||||
CRGB bg, uint8_t size);
|
||||
void drawChar(int16_t x, int16_t y, unsigned char c, CRGB color,
|
||||
CRGB bg, uint8_t size_x, uint8_t size_y);
|
||||
void getTextBounds(const char *string, int16_t x, int16_t y, int16_t *x1,
|
||||
int16_t *y1, uint16_t *w, uint16_t *h);
|
||||
void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
|
||||
void getTextBounds(const String &str, int16_t x, int16_t y, int16_t *x1,
|
||||
int16_t *y1, uint16_t *w, uint16_t *h);
|
||||
void setTextSize(uint8_t s);
|
||||
void setTextSize(uint8_t sx, uint8_t sy);
|
||||
void setFont(const GFXfont *f = NULL);
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set text cursor location
|
||||
@param x X coordinate in pixels
|
||||
@param y Y coordinate in pixels
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void setCursor(int16_t x, int16_t y) {
|
||||
cursor_x = x;
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set text font color with transparant background
|
||||
@param c 16-bit 5-6-5 Color to draw text with
|
||||
@note For 'transparent' background, background and foreground
|
||||
are set to same color rather than using a separate flag.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void setTextColor(CRGB c) { textcolor = textbgcolor = c; }
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set text font color with custom background color
|
||||
@param c 16-bit 5-6-5 Color to draw text with
|
||||
@param bg 16-bit 5-6-5 Color to draw background/fill with
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void setTextColor(CRGB c, CRGB bg) {
|
||||
textcolor = c;
|
||||
textbgcolor = bg;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set whether text that is too long for the screen width should
|
||||
automatically wrap around to the next line (else clip right).
|
||||
@param w true for wrapping, false for clipping
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void setTextWrap(bool w) { wrap = w; }
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Enable (or disable) Code Page 437-compatible charset.
|
||||
There was an error in glcdfont.c for the longest time -- one
|
||||
character (#176, the 'light shade' block) was missing -- this
|
||||
threw off the index of every character that followed it.
|
||||
But a TON of code has been written with the erroneous
|
||||
character indices. By default, the library uses the original
|
||||
'wrong' behavior and old sketches will still work. Pass
|
||||
'true' to this function to use correct CP437 character values
|
||||
in your code.
|
||||
@param x true = enable (new behavior), false = disable (old behavior)
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void cp437(bool x = true) { _cp437 = x; }
|
||||
|
||||
using Print::write;
|
||||
#if ARDUINO >= 100
|
||||
virtual size_t write(uint8_t);
|
||||
#else
|
||||
virtual void write(uint8_t);
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
/*!
|
||||
@brief Get width of the display, accounting for current rotation
|
||||
@returns Width in pixels
|
||||
*/
|
||||
/************************************************************************/
|
||||
int16_t width(void) const { return _width; };
|
||||
|
||||
/************************************************************************/
|
||||
/*!
|
||||
@brief Get height of the display, accounting for current rotation
|
||||
@returns Height in pixels
|
||||
*/
|
||||
/************************************************************************/
|
||||
int16_t height(void) const { return _height; }
|
||||
|
||||
/************************************************************************/
|
||||
/*!
|
||||
@brief Get rotation setting for display
|
||||
@returns 0 thru 3 corresponding to 4 cardinal rotations
|
||||
*/
|
||||
/************************************************************************/
|
||||
uint8_t getRotation(void) const { return rotation; }
|
||||
|
||||
// get current cursor position (get rotation safe maximum values,
|
||||
// using: width() for x, height() for y)
|
||||
/************************************************************************/
|
||||
/*!
|
||||
@brief Get text cursor X location
|
||||
@returns X coordinate in pixels
|
||||
*/
|
||||
/************************************************************************/
|
||||
int16_t getCursorX(void) const { return cursor_x; }
|
||||
|
||||
/************************************************************************/
|
||||
/*!
|
||||
@brief Get text cursor Y location
|
||||
@returns Y coordinate in pixels
|
||||
*/
|
||||
/************************************************************************/
|
||||
int16_t getCursorY(void) const { return cursor_y; };
|
||||
|
||||
protected:
|
||||
void charBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx,
|
||||
int16_t *miny, int16_t *maxx, int16_t *maxy);
|
||||
int16_t WIDTH; ///< This is the 'raw' display width - never changes
|
||||
int16_t HEIGHT; ///< This is the 'raw' display height - never changes
|
||||
int16_t _width; ///< Display width as modified by current rotation
|
||||
int16_t _height; ///< Display height as modified by current rotation
|
||||
int16_t cursor_x; ///< x location to start print()ing text
|
||||
int16_t cursor_y; ///< y location to start print()ing text
|
||||
CRGB textcolor; ///< 16-bit background color for print()
|
||||
CRGB textbgcolor; ///< 16-bit text color for print()
|
||||
uint8_t textsize_x; ///< Desired magnification in X-axis of text to print()
|
||||
uint8_t textsize_y; ///< Desired magnification in Y-axis of text to print()
|
||||
uint8_t rotation; ///< Display rotation (0 thru 3)
|
||||
bool wrap; ///< If set, 'wrap' text at right edge of display
|
||||
bool _cp437; ///< If set, use correct CP437 charset (default is off)
|
||||
GFXfont *gfxFont; ///< Pointer to special font
|
||||
};
|
||||
|
||||
/// A simple drawn button UI element
|
||||
class GULLS_GFX_Button {
|
||||
|
||||
public:
|
||||
GULLS_GFX_Button(void);
|
||||
// "Classic" initButton() uses center & size
|
||||
void initButton(GULLS_GFX *gfx, int16_t x, int16_t y, uint16_t w,
|
||||
uint16_t h, CRGB outline, CRGB fill,
|
||||
CRGB textcolor, char *label, uint8_t textsize);
|
||||
void initButton(GULLS_GFX *gfx, int16_t x, int16_t y, uint16_t w,
|
||||
uint16_t h, CRGB outline, CRGB fill,
|
||||
CRGB textcolor, char *label, uint8_t textsize_x,
|
||||
uint8_t textsize_y);
|
||||
// New/alt initButton() uses upper-left corner & size
|
||||
void initButtonUL(GULLS_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
|
||||
uint16_t h, CRGB outline, CRGB fill,
|
||||
CRGB textcolor, char *label, uint8_t textsize);
|
||||
void initButtonUL(GULLS_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
|
||||
uint16_t h, CRGB outline, CRGB fill,
|
||||
CRGB textcolor, char *label, uint8_t textsize_x,
|
||||
uint8_t textsize_y);
|
||||
void drawButton(bool inverted = false);
|
||||
bool contains(int16_t x, int16_t y);
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Sets button state, should be done by some touch function
|
||||
@param p True for pressed, false for not.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void press(bool p) {
|
||||
laststate = currstate;
|
||||
currstate = p;
|
||||
}
|
||||
|
||||
bool justPressed();
|
||||
bool justReleased();
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Query whether the button is currently pressed
|
||||
@returns True if pressed
|
||||
*/
|
||||
/**********************************************************************/
|
||||
bool isPressed(void) { return currstate; };
|
||||
|
||||
private:
|
||||
GULLS_GFX *_gfx;
|
||||
int16_t _x1, _y1; // Coordinates of top-left corner
|
||||
uint16_t _w, _h;
|
||||
uint8_t _textsize_x;
|
||||
uint8_t _textsize_y;
|
||||
CRGB _outlinecolor, _fillcolor, _textcolor;
|
||||
char _label[10];
|
||||
|
||||
bool currstate, laststate;
|
||||
};
|
||||
|
||||
|
||||
#endif // _GULLS_GFX_H
|
||||
50
include/LEDHAL.h
Normal file
50
include/LEDHAL.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef LEDHAL_H
|
||||
#define LEDHAL_H
|
||||
|
||||
#include "FastLED.h"
|
||||
|
||||
class LEDHAL {
|
||||
public:
|
||||
LEDHAL(char* _ledName, bool _isPhysical) :
|
||||
ledName(_ledName), isPhysical(_isPhysical), showRequested(false) {}
|
||||
virtual ~LEDHAL() { delete ledName; }
|
||||
|
||||
virtual char* getLEDName() { return ledName; }
|
||||
|
||||
virtual uint16_t getNumLEDs() = 0;
|
||||
|
||||
virtual bool getIsPhysical() { return isPhysical; }
|
||||
|
||||
virtual CRGB getColor(int16_t pixel) = 0;
|
||||
|
||||
virtual void setColor(int16_t pixel, CRGB color) = 0;
|
||||
|
||||
virtual void requestShow() { showRequested = true; }
|
||||
|
||||
//TODO UnifiedColor should have constants
|
||||
virtual void clearLEDs() {
|
||||
for(uint16_t i = 0; i < getNumLEDs(); i++) {
|
||||
setColor(i, CRGB(0, 0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
void show() {
|
||||
if(showRequested) {
|
||||
updateLEDs();
|
||||
|
||||
showRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void updateLEDs() {};
|
||||
|
||||
private:
|
||||
char*
|
||||
ledName;
|
||||
bool
|
||||
isPhysical,
|
||||
showRequested;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
include/LEDHAL2D.h
Normal file
42
include/LEDHAL2D.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef LEDHAL2D_H
|
||||
#define LEDHAL2D_H
|
||||
|
||||
#include "LEDHAL.h"
|
||||
|
||||
#include "GULLS_GFX.h"
|
||||
|
||||
class LEDHAL2D : public LEDHAL, public GULLS_GFX {
|
||||
public:
|
||||
LEDHAL2D(int16_t width, int16_t height, char* ledName, bool isPhysical) :
|
||||
LEDHAL(ledName, isPhysical), GULLS_GFX(width, height), _width(width), _height(height) {}
|
||||
|
||||
virtual uint16_t getNumLEDs() = 0;
|
||||
virtual CRGB getColor(int16_t pixel) = 0;
|
||||
virtual void drawPixel(int16_t x, int16_t y, CRGB color) = 0;
|
||||
virtual CRGB getColor(int16_t x, int16_t y) = 0;
|
||||
|
||||
virtual int16_t getWidth() {
|
||||
return _width;
|
||||
}
|
||||
|
||||
virtual int16_t getHeight() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
virtual void clearLEDs() {
|
||||
CRGB noColor(0, 0, 0);
|
||||
|
||||
for(int16_t x = 0; x < getWidth(); x++) {
|
||||
for(int16_t y = 0; y < getHeight(); y++) {
|
||||
drawPixel(x, y, noColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int16_t
|
||||
_width,
|
||||
_height; //TODO Really need to be getting these values from GFX
|
||||
};
|
||||
|
||||
#endif
|
||||
71
include/LogicalMatrix.h
Normal file
71
include/LogicalMatrix.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef LOGICALMATRIX_H
|
||||
#define LOGICALMATRIX_H
|
||||
|
||||
#include "LEDHAL2D.h"
|
||||
#include "FastLED.h"
|
||||
|
||||
class LogicalMatrix : public LEDHAL2D {
|
||||
public:
|
||||
LogicalMatrix(char* _ledName, LEDHAL2D* _parent, int16_t _startX, int16_t _startY,
|
||||
int16_t _stopX, int16_t _stopY) : LEDHAL2D(_stopX - _startX, _stopY - _startY,
|
||||
_ledName, false), startX(_startX), stopX(_stopX), startY(_startY), stopY(_stopY),
|
||||
parent(_parent) {}
|
||||
virtual ~LogicalMatrix() {}
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, CRGB color) {
|
||||
parent->drawPixel(startX + x, startY + y, color);
|
||||
}
|
||||
|
||||
void setColor(int16_t pixel, CRGB color) {
|
||||
//This is a computationally expensive cheap trick that I'm not
|
||||
//entirely convinced is necessary, it is essentially the reverse
|
||||
//of pixelPos = getHeight() * y + x
|
||||
//Integer division by getHeight returns y from the above
|
||||
//Modulous (remainder) by getHeight returns x from the above
|
||||
int16_t intDiv = pixel / getHeight(); //yPos
|
||||
int16_t intMod = pixel % getHeight(); //xPos
|
||||
|
||||
parent->setColor((startX + intMod) * (startY + intDiv), color);
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t pixel) {
|
||||
//This is a computationally expensive cheap trick that I'm not
|
||||
//entirely convinced is necessary, it is essentially the reverse
|
||||
//of pixelPos = getHeight() * y + x
|
||||
//Integer division by getHeight returns y from the above
|
||||
//Modulous (remainder) by getHeight returns x from the above
|
||||
int16_t intDiv = pixel / getHeight(); //yPos
|
||||
int16_t intMod = pixel % getHeight(); //xPos
|
||||
|
||||
return parent->getColor((startX + intMod) * (startY + intDiv));
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t x, int16_t y) {
|
||||
return parent->getColor(startX + x, startY + y);
|
||||
}
|
||||
|
||||
uint16_t getNumLEDs() {
|
||||
return getWidth() * getHeight();
|
||||
}
|
||||
|
||||
void requestShow() {
|
||||
parent->requestShow();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateLEDs() {
|
||||
//This does nothing, because show should never be called on
|
||||
//a logical strip
|
||||
}
|
||||
|
||||
private:
|
||||
LEDHAL2D*
|
||||
parent;
|
||||
int16_t
|
||||
startX,
|
||||
stopX,
|
||||
startY,
|
||||
stopY;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
include/LogicalStrip.h
Normal file
42
include/LogicalStrip.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef LOGICALSTRIP_H
|
||||
#define LOGICALSTRIP_H
|
||||
|
||||
#include "LEDHAL.h"
|
||||
#include "FastLED.h"
|
||||
|
||||
class LogicalStrip : public LEDHAL {
|
||||
public:
|
||||
LogicalStrip(char* _ledName, LEDHAL* _parent, int16_t _startPixel,
|
||||
uint16_t _stopPixel) : LEDHAL(_ledName, false), parent(_parent),
|
||||
startPixel(_startPixel), stopPixel(_stopPixel) {}
|
||||
virtual ~LogicalStrip() {}
|
||||
|
||||
uint16_t getNumLEDs() { return stopPixel - startPixel; }
|
||||
|
||||
CRGB getColor(int16_t pixel) {
|
||||
return parent->getColor(startPixel + pixel);
|
||||
}
|
||||
|
||||
void setColor(uint16_t pixel, CRGB color) {
|
||||
parent->setColor(startPixel + pixel, color);
|
||||
}
|
||||
|
||||
void requestShow() {
|
||||
parent->requestShow();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateLEDs() {
|
||||
//This does nothing, because show should never be called on
|
||||
//a logical strip
|
||||
}
|
||||
|
||||
private:
|
||||
LEDHAL*
|
||||
parent;
|
||||
int16_t
|
||||
startPixel,
|
||||
stopPixel;
|
||||
};
|
||||
|
||||
#endif
|
||||
19
include/MatrixAnimation.h
Normal file
19
include/MatrixAnimation.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef MATRIXANIMATION_H
|
||||
#define MATRIXANIMATION_H
|
||||
|
||||
#include "AnimationBase.h"
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
class MatrixAnimation : public AnimationBase {
|
||||
public:
|
||||
MatrixAnimation(LEDHAL2D* _matrix, char* _refName, long _updateTime) :
|
||||
AnimationBase(_refName, _updateTime), matrix(_matrix) {}
|
||||
virtual ~MatrixAnimation() {}
|
||||
|
||||
LEDHAL2D* getMatrix() { return matrix; }
|
||||
protected:
|
||||
LEDHAL2D*
|
||||
matrix;
|
||||
};
|
||||
|
||||
#endif
|
||||
53
include/PlasmaMatrix.h
Normal file
53
include/PlasmaMatrix.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef PLASMAMATRIX_H
|
||||
#define PLASMAMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
class PlasmaMatrix : public MatrixAnimation {
|
||||
public:
|
||||
PlasmaMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime) :
|
||||
MatrixAnimation(_matrix, _refName, _updateTime), paletteShift(0), palette(new CRGB[256]) {
|
||||
plasma = new uint8_t*[matrix->getWidth()];
|
||||
|
||||
for(uint16_t i = 0; i < matrix->getWidth(); i++) {
|
||||
plasma[i] = new uint8_t[matrix->getHeight()];
|
||||
}
|
||||
|
||||
for(uint16_t x = 0; x < matrix->getWidth(); x++) {
|
||||
for(uint16_t y = 0; y < matrix->getHeight(); y++) {
|
||||
plasma[x][y] = (uint8_t) ((128.0 + (128 * sinf(x / 8.0)) + 128 + (128.0 * sinf(y / 8.0))) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < 256; i++) {
|
||||
palette[i] = CRGB(CHSV(i, 255, 255));
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~PlasmaMatrix() {
|
||||
delete[] palette;
|
||||
|
||||
for(uint16_t i = 0; i < matrix->getWidth(); i++) {
|
||||
delete[] plasma[i];
|
||||
}
|
||||
|
||||
delete[] plasma;
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
paletteShift = 0;
|
||||
}
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
uint16_t
|
||||
paletteShift;
|
||||
CRGB*
|
||||
palette;
|
||||
uint8_t**
|
||||
plasma;
|
||||
};
|
||||
|
||||
#endif
|
||||
39
include/README
Normal file
39
include/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
36
include/RicochetHelper.h
Normal file
36
include/RicochetHelper.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef RICOCHETHELPER_H
|
||||
#define RICOCHETHELPER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "FastLED.h"
|
||||
|
||||
class RicochetHelper {
|
||||
public:
|
||||
RicochetHelper() {}
|
||||
RicochetHelper(int16_t _startPosX, int16_t _startPosY, int16_t _width, int16_t _height,
|
||||
CRGB _color) : currentX(_startPosX), currentY(_startPosY), width(_width),
|
||||
height(_height), xDir(random(0, 101) > 51 ? -1 : 1), yDir(random(0, 100) > 51 ? -1 : 1) {}
|
||||
|
||||
int16_t getCurrentXPos() { return currentX; }
|
||||
int16_t getCurrentYPos() { return currentY; }
|
||||
|
||||
CRGB getCurrentColor() { return color; }
|
||||
|
||||
void setCurrentColor(uint16_t _color) { color = _color; }
|
||||
|
||||
void updatePositions();
|
||||
|
||||
private:
|
||||
int16_t
|
||||
currentX,
|
||||
currentY,
|
||||
width,
|
||||
height;
|
||||
int8_t
|
||||
xDir,
|
||||
yDir;
|
||||
CRGB
|
||||
color;
|
||||
};
|
||||
|
||||
#endif
|
||||
32
include/RicochetMatrix.h
Normal file
32
include/RicochetMatrix.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef RICOCHETMATRIX_H
|
||||
#define RICOCHETMATRIX_H
|
||||
|
||||
#include "MatrixAnimation.h"
|
||||
#include "RicochetHelper.h"
|
||||
|
||||
class RicochetMatrix : public MatrixAnimation {
|
||||
public:
|
||||
RicochetMatrix(LEDHAL2D* _matrix, char* _refName, long _updateTime, uint16_t _numBalls,
|
||||
CRGB* _colors, uint8_t _numColors) : MatrixAnimation(_matrix, _refName, _updateTime),
|
||||
numBalls(_numBalls), colors(new CRGB[_numColors]), numColors(_numColors),
|
||||
balls(new RicochetHelper*[_numBalls]) {
|
||||
for(uint8_t i = 0; i < _numColors; i++) {
|
||||
colors[i] = _colors[i];
|
||||
}
|
||||
}
|
||||
virtual ~RicochetMatrix() { delete[] colors; delete[] balls; };
|
||||
|
||||
void initialize();
|
||||
void execute();
|
||||
private:
|
||||
uint16_t
|
||||
numBalls;
|
||||
CRGB*
|
||||
colors;
|
||||
uint8_t
|
||||
numColors;
|
||||
RicochetHelper**
|
||||
balls;
|
||||
};
|
||||
|
||||
#endif
|
||||
46
include/SmartMatrixPhysicalMatrix.h
Normal file
46
include/SmartMatrixPhysicalMatrix.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef SMARTMATRIXPHYSICALMATRIX_H
|
||||
#define SMARTMATRIXPHYSICALMATRIX_H
|
||||
|
||||
#include "SmartMatrix.h"
|
||||
#include "LEDHAL2D.h"
|
||||
|
||||
class SmartMatrixPhysicalMatrix : public LEDHAL2D {
|
||||
public:
|
||||
SmartMatrixPhysicalMatrix(SMLayerBackground<rgb24, 0>* _layer, char* ledName, int16_t width, int16_t height):
|
||||
LEDHAL2D(width, height, ledName, true), layer(_layer) {}
|
||||
virtual ~SmartMatrixPhysicalMatrix() {}
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, CRGB color) {
|
||||
layer->drawPixel(x, y, color);
|
||||
}
|
||||
|
||||
void setColor(int16_t pixel, CRGB color) {
|
||||
layer->drawPixel(pixel % getHeight(), (int)(pixel / getHeight()), color);
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t x, int16_t y) {
|
||||
rgb24 value = layer->readPixel(x, y);
|
||||
|
||||
return CRGB(value.red, value.green, value.blue);
|
||||
}
|
||||
|
||||
CRGB getColor(int16_t pixel) {
|
||||
rgb24 value = layer->readPixel(pixel % getHeight(), (int)(pixel / getHeight()));
|
||||
|
||||
return CRGB(value.red, value.green, value.blue);
|
||||
}
|
||||
|
||||
uint16_t getNumLEDs() {
|
||||
return getWidth() * getHeight();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateLEDs() {
|
||||
layer->swapBuffers();
|
||||
}
|
||||
|
||||
private:
|
||||
SMLayerBackground<rgb24, 0>* layer;
|
||||
};
|
||||
|
||||
#endif
|
||||
19
include/StripAnimation.h
Normal file
19
include/StripAnimation.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef STRIPANIMATION_H
|
||||
#define STRIPANIMATION_H
|
||||
|
||||
#include "AnimationBase.h"
|
||||
#include "LEDHAL.h"
|
||||
|
||||
class StripAnimation : public AnimationBase {
|
||||
public:
|
||||
StripAnimation(LEDHAL* _strip, char* _refName, long _updateTime) :
|
||||
AnimationBase(_refName, _updateTime), strip(_strip) {}
|
||||
virtual ~StripAnimation() {}
|
||||
|
||||
LEDHAL* getStrip() { return strip; }
|
||||
protected:
|
||||
LEDHAL*
|
||||
strip;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user