G.U.L.L.S. rebuilt to use PlatformIO

This commit is contained in:
2024-07-01 19:18:45 -04:00
commit f934849576
55 changed files with 4082 additions and 0 deletions

18
src/AlternateMatrix.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "AlternateMatrix.h"
void AlternateMatrix::execute() {
if(type == AlternateType::HORIZONTAL_ALTERNATE) {
for(int16_t i = 0; i < matrix->getHeight(); i++) {
matrix->drawFastHLine(0, i, matrix->getWidth(),
colors[(i + alternateInt) % numColors]);
}
} else if(type == AlternateType::VERTICAL_ALTERNATE) {
for(int16_t i = 0; i < matrix->getWidth(); i++) {
matrix->drawFastVLine(i, 0, matrix->getHeight(),
colors[(i + alternateInt) % numColors]);
}
}
alternateInt++;
matrix->requestShow();
}

10
src/AlternateStrip.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "AlternateStrip.h"
void AlternateStrip::execute() {
for(int16_t i = 0; i < strip->getNumLEDs(); i++) {
strip->setColor(i, colors[(i + alternateInt) % numColors]);
}
alternateInt++;
strip->requestShow();
}

23
src/CollisionMatrix.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "CollisionMatrix.h"
void CollisionMatrix::execute() {
if(collisionInt == 0) {
matrix->clearLEDs();
}
if(type == CollisionType::HORIZONTAL_COLLISION) {
matrix->drawFastHLine(0, collisionInt, matrix->getWidth(), color1);
matrix->drawFastHLine(0, matrix->getHeight() - collisionInt - 1, matrix->getWidth(), color2);
} else if(type == CollisionType::VERTICAL_COLLISION) {
matrix->drawFastVLine(collisionInt, 0, matrix->getHeight(), color1);
matrix->drawFastVLine(matrix->getWidth() - 1 - collisionInt, 0, matrix->getHeight(), color2);
}
collisionInt++;
if(collisionInt >= (type == CollisionType::HORIZONTAL_COLLISION ? matrix->getHeight() : matrix->getWidth())) {
collisionInt = 0;
}
matrix->requestShow();
}

18
src/CollisionStrip.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "CollisionStrip.h"
void CollisionStrip::execute() {
if(collisionInt == 0) {
strip->clearLEDs();
}
strip->setColor(collisionInt, color1);
strip->setColor(strip->getNumLEDs() - collisionInt - 1, color2);
collisionInt++;
if(collisionInt >= strip->getNumLEDs()) {
collisionInt = 0;
}
strip->requestShow();
}

View File

@@ -0,0 +1,54 @@
#include "ColorRandomizerMatrix.h"
void ColorRandomizerMatrix::execute() {
if(fade && isFading) {
CRGB color;
if(colorRandomizerInt == 0) {
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
color = matrix->getColor(0, i);
} else {
color = matrix->getColor(i, 0);
}
fadingValues[i].red = (ceil((float)color.red/scale));
fadingValues[i].green = (ceil((float)color.green/scale));
fadingValues[i].blue = (ceil((float)color.blue/scale));
}
colorRandomizerInt++;
} else if(colorRandomizerInt > 0 && colorRandomizerInt < scale + 1) {
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
matrix->drawFastHLine(0, i, matrix->getWidth(), matrix->getColor(0, i) - fadingValues[i]);
} else {
matrix->drawFastVLine(i, 0, matrix->getHeight(), matrix->getColor(i, 0) - fadingValues[i]);
}
}
colorRandomizerInt++;
} else {
colorRandomizerInt = 0;
isFading = false;
}
} else {
uint8_t rand;
for(uint16_t i = 0; i < type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER ? matrix->getHeight() : matrix->getWidth(); i++) {
rand = random(0, numColors);
if(type == ColorRandomizerType::HORIZONTAL_COLORRANDOMIZER) {
matrix->drawFastHLine(0, i, matrix->getWidth(), colors[rand]);
} else {
matrix->drawFastVLine(i, 0, matrix->getHeight(), colors[rand]);
}
}
if(fade) {
isFading = true;
}
}
matrix->requestShow();
}

View File

@@ -0,0 +1,42 @@
#include "ColorRandomizerStrip.h"
void ColorRandomizerStrip::execute() {
if(fade && isFading) {
CRGB color;
if(colorRandomizerInt == 0) {
for(uint16_t i = 0; i < strip->getNumLEDs(); i++) {
color = strip->getColor(i);
fadingValues[i].red = (ceil((float)color.red/scale));
fadingValues[i].green = (ceil((float)color.green/scale));
fadingValues[i].blue = (ceil((float)color.blue/scale));
}
colorRandomizerInt++;
} else if(colorRandomizerInt > 0 && colorRandomizerInt < scale + 1) {
for(uint16_t i = 0; i < strip->getNumLEDs(); i++) {
strip->setColor(i, strip->getColor(i) - fadingValues[i]);
}
colorRandomizerInt++;
} else {
colorRandomizerInt = 0;
isFading = false;
}
} else {
uint8_t rand;
for(uint16_t i = 0; i < strip->getNumLEDs(); i++) {
rand = random(0, numColors);
strip->setColor(i, colors[rand]);
}
if(fade) {
isFading = true;
}
}
strip->requestShow();
}

24
src/CycleLightMatrix.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "CycleLightMatrix.h"
void CycleLightMatrix::execute() {
if(cycleLightInt == 0) {
matrix->clearLEDs();
}
if(type == CycleLightType::HORIZONTAL_CYCLELIGHT) {
matrix->drawFastHLine(0, cycleLightInt, matrix->getWidth(),
colors[cycleLightColor % numColors]);
} else if(type == CycleLightType::VERTICAL_CYCLELIGHT) {
matrix->drawFastVLine(cycleLightInt, 0, matrix->getHeight(),
colors[cycleLightColor % numColors]);
}
cycleLightInt++;
if(cycleLightInt >= (type == CycleLightType::HORIZONTAL_CYCLELIGHT ? matrix->getHeight() : matrix->getWidth())) {
cycleLightInt = 0;
cycleLightColor++;
}
matrix->requestShow();
}

18
src/CycleLightStrip.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "CycleLightStrip.h"
void CycleLightStrip::execute() {
if(cycleLightInt == 0) {
strip->clearLEDs();
}
strip->setColor(cycleLightInt, colors[cycleLightColor % numColors]);
cycleLightInt++;
if(cycleLightInt >= strip->getNumLEDs()) {
cycleLightInt = 0;
cycleLightColor++;
}
strip->requestShow();
}

42
src/CycloneHelper.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include "CycloneHelper.h"
void CycloneHelper::updateAndRedraw(LEDHAL2D* matrix) {
matrix->drawPixel(nextPoint.getX(), nextPoint.getY(), color);
// This will create an ungodly number of stack allocations and destroys
for(uint8_t i = 0; i < numberOfTails; i++) {
if(!tailPoints[i].isOrigin()) {
matrix->drawPixel(tailPoints[i].getX(), tailPoints[i].getY(), tailColors[numberOfTails - i - 1]);
}
}
Point2D tempPoint = nextPoint;
// This is risky, if the logic is wrong, this is infinite
// Find the next position on the circle that actually is different
do {
currentDrawAngle += spinDirection;
if(currentDrawAngle > 359) {
currentDrawAngle = 0;
} else if(currentDrawAngle < 0) {
currentDrawAngle = 359;
}
tempPoint = Point2D(
originX + (uint16_t) round(radius * cosf(currentDrawAngle)),
originY + (uint16_t) round(radius * sinf(currentDrawAngle))
);
} while(tempPoint == nextPoint);
//Slide all tailpoints back one
for(uint8_t i = numberOfTails - 1; i >= 1; i--) {
tailPoints[i] = tailPoints[i - 1];
}
// Point we just drew becomes the first tail point
tailPoints[0] = nextPoint;
// Point we just discovered becomes the next point to draw
nextPoint = tempPoint;
}

37
src/DecodingBitStream.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "DecodingBitStream.h"
uint16_t DecodingBitStream::getCode()
{
uint16_t returnCode;
verifyEnoughBits();
returnCode = bitBuffer & (int)(pow(2, numberOfBitsInCode) - 1);
bitBuffer >>= numberOfBitsInCode;
bitsAvailable -= numberOfBitsInCode;
return returnCode;
}
void DecodingBitStream::verifyEnoughBits()
{
while(bytesAvailable != 0 && (bitsAvailable <= 8 || bitsAvailable <= numberOfBitsInCode))
{
bitBuffer |= stream->read() << bitsAvailable;
bitsAvailable += 8;
bytesAvailable--;
}
}
uint16_t DecodingBitStream::getNumberOfBitsToRepresentValue(uint16_t value)
{
uint16_t count = 0;
while(value > 0)
{
value >>= 1;
count++;
}
return count;
}

75
src/FireworksMatrix.cpp Normal file
View File

@@ -0,0 +1,75 @@
#include "FireworksMatrix.h"
void FireworksMatrix::initialize() {
for(uint8_t i = 0; i < maxFireworks; i++) {
fireworks[i].isActive = false;
}
uint8_t third = maxFireworks / 6;
for(uint8_t i = 0; i < third; i++) {
randomSeed(random(0, 100000000));
fireworks[i].radius = random(1, maxRadius + 1);
fireworks[i].currentRadius = 1;
fireworks[i].xPos = random(fireworks[i].radius, matrix->getWidth() - fireworks[i].radius);
fireworks[i].yPos = matrix->getHeight();
fireworks[i].yMaxHeight = random(fireworks[i].radius, matrix->getHeight() - fireworks[i].radius);
fireworks[i].color = colors[random(0, numColors)];
fireworks[i].isActive = true;
}
resetTimer();
}
void FireworksMatrix::execute() {
matrix->clearLEDs();
uint8_t totalInactive = 0;
for(uint8_t i = 0; i < maxFireworks; i++) {
if(!fireworks[i].isActive) {
totalInactive++;
}
}
for(uint8_t i = 0; i < totalInactive; i++) {
randomSeed(random(0, 100000000));
if(random(0, 1000) > 500) {
for(uint8_t j = 0; j < maxFireworks; j++) {
if(!fireworks[j].isActive) {
fireworks[j].radius = random(1, maxRadius + 1);
fireworks[j].currentRadius = 1;
fireworks[j].xPos = random(fireworks[j].radius, matrix->getWidth() - fireworks[j].radius);
fireworks[j].yPos = matrix->getHeight();
fireworks[j].yMaxHeight = random(fireworks[j].radius, matrix->getHeight() - fireworks[j].radius);
fireworks[j].color = colors[random(0, numColors)];
fireworks[j].isActive = true;
break;
}
}
}
}
for(uint8_t i = 0; i < maxFireworks; i++) {
if(fireworks[i].isActive) {
if(fireworks[i].yMaxHeight == fireworks[i].yPos &&
fireworks[i].currentRadius == fireworks[i].radius) {
fireworks[i].isActive = false;
} else if(fireworks[i].yMaxHeight == fireworks[i].yPos &&
fireworks[i].currentRadius < fireworks[i].radius) {
matrix->drawCircle(fireworks[i].xPos, fireworks[i].yPos, fireworks[i].currentRadius,
fireworks[i].color);
fireworks[i].currentRadius++;
} else if(fireworks[i].yPos > fireworks[i].yMaxHeight) {
matrix->drawPixel(fireworks[i].xPos, fireworks[i].yPos, fireworks[i].color);
fireworks[i].yPos--;
}
}
}
matrix->requestShow();
}

59
src/FluidColorMatrix.cpp Normal file
View File

@@ -0,0 +1,59 @@
#include "FluidColorMatrix.h"
void FluidColorMatrix::initialize() {
uint8_t step = 0;
switch(resolution) {
case FluidColorResolution::FULL_FLUIDCOLOR:
numColors = 255;
step = 1;
break;
case FluidColorResolution::HALF_FLUIDCOLOR:
numColors = 128;
step = 2;
break;
case FluidColorResolution::QUATER_FLUIDCOLOR:
numColors = 64;
step = 4;
break;
case FluidColorResolution::EIGHTH_FLUIDCOLOR:
default:
numColors = 32;
step = 8;
break;
}
colors = new CRGB[numColors];
for(uint16_t i = 0; i < numColors; i+=step) {
colors[i/step] = CRGB(CHSV(i, 255, 255));
}
}
void FluidColorMatrix::execute() {
switch(type) {
case FluidColorType::PIXEL_BY_PIXEL_FLUIDCOLOR:
for(int16_t x = 0; x < matrix->getWidth(); x++) {
for(int16_t y = 0; y < matrix->getHeight(); y++) {
matrix->drawPixel(x, y,
colors[((matrix->getWidth() * y + x) + colorShifter) % numColors]);
}
}
break;
case FluidColorType::HORIZONTAL_FLUIDCOLOR:
for(int16_t y = 0; y < matrix->getHeight(); y++) {
matrix->drawFastHLine(0, y, matrix->getWidth(),
colors[(y + colorShifter) % numColors]);
}
break;
case FluidColorType::VERTICAL_FLUIDCOLOR:
default:
for(int16_t x = 0; x < matrix->getWidth(); x++) {
matrix->drawFastVLine(x, 0, matrix->getHeight(),
colors[(x + colorShifter) % numColors]);
}
break;
}
colorShifter++;
matrix->requestShow();
}

36
src/GIFMatrix.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "GIFMatrix.h"
void GIFMatrix::buildCodeTable() {
// I am not confident this is going to work, it's a lot of memory cleanup,
// memory that is dynamic, and I'm afraid it's going to cause destructive memory
// corruption
if(currentCodeTable != nullptr) {
for(uint16_t i = 0; i < sizeof(currentCodeTable)/sizeof(uint16_t*); i++) {
delete currentCodeTable[i];
}
delete currentCodeTable;
}
}
void GIFMatrix::drawForArray(CRGB* colorTable, uint16_t* indexes, uint16_t startingXPosition, uint16_t imageWidth) {
for(uint16_t i = 0; i < sizeof(indexes)/sizeof(uint16_t); i++) {
matrix->drawPixel(currentXPosition, currentYPosition, colorTable[indexes[i]]);
currentXPosition++;
if(currentXPosition >= (imageWidth + startingXPosition)) {
currentXPosition = startingXPosition;
currentYPosition++;
}
}
}
uint16_t GIFMatrix::readWord() {
uint16_t lsb = dataFile->read();
uint16_t msb = dataFile->read();
return (msb << 8) | lsb;
}

1730
src/GULLS_GFX.cpp Normal file

File diff suppressed because it is too large Load Diff

13
src/PlasmaMatrix.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "PlasmaMatrix.h"
void PlasmaMatrix::execute() {
for(uint16_t x = 0; x < matrix->getWidth(); x++) {
for(uint16_t y = 0; y < matrix->getHeight(); y++) {
uint8_t color = (plasma[x][y] + paletteShift) % 256;
matrix->drawPixel(x, y, palette[color]);
}
}
matrix->requestShow();
}

33
src/Point2D.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef POINT2D_H
#define POINT2D_H
#include "Arduino.h"
class Point2D {
public:
Point2D() : x(0), y(0) {}
Point2D(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
virtual ~Point2D() {}
void setX(uint16_t _x) { x = _x; }
void setY(uint16_t _y) { y = _y; }
uint16_t getX() { return x; }
uint16_t getY() { return y; }
bool isOrigin() { return x == 0 && y == 0; }
bool operator==(const Point2D& other) {
return this->x == other.x && this->y == other.y;
}
bool operator!=(const Point2D other) {
return this->x != other.x || this->y != other.y;
}
private:
uint16_t
x,
y;
};
#endif

14
src/RicochetHelper.cpp Normal file
View File

@@ -0,0 +1,14 @@
#include "RicochetHelper.h"
void RicochetHelper::updatePositions() {
currentX += xDir;
currentY += yDir;
if(currentX >= width || currentX < 0) {
xDir *= -1;
}
if(currentY >= height || currentY < 0) {
yDir *= -1;
}
}

26
src/RicochetMatrix.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "RicochetMatrix.h"
void RicochetMatrix::initialize() {
for(uint16_t i = 0; i < numBalls; i++) {
if(balls[i] != NULL) {
delete balls[i];
}
randomSeed(random(0, 10000000));
balls[i] = new RicochetHelper(random(0, matrix->getWidth()), random(0, matrix->getHeight()),
matrix->getWidth(), matrix->getHeight(), colors[random(0, numColors)]);
}
}
void RicochetMatrix::execute() {
matrix->clearLEDs();
for(uint16_t i = 0; i < numBalls; i++) {
balls[i]->updatePositions();
matrix->drawPixel(balls[i]->getCurrentXPos(), balls[i]->getCurrentYPos(),
balls[i]->getCurrentColor());
}
matrix->requestShow();
}

59
src/main.cpp Normal file
View File

@@ -0,0 +1,59 @@
#include <Arduino.h>
#include "MatrixHardware_Teensy3_ShieldV1toV3.h"
#include "SmartMatrix.h"
#include "FastLED.h"
#include "LEDHAL.h"
#include "LEDHAL2D.h"
#include "CLEDControllerPhysicalStrip.h"
#include "CLEDControllerPhysicalMatrix.h"
#include "SmartMatrixPhysicalMatrix.h"
#define NUMLEDS 24
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 96; // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 64; // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = SMARTMATRIX_OPTIONS_BOTTOM_TO_TOP_STACKING; // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
CRGB leds[NUMLEDS];
CRGB leds2[NUMLEDS];
CRGB leds3[NUMLEDS];
CRGB someColor(255, 255, 255);
LEDHAL* hal;
LEDHAL2D* hal2D;
LEDHAL2D* smHAL;
rgb24 canRGB24Translate(rgb24 color) {
color.red = 0;
return color;
}
void setup() {
CLEDController* controller = &FastLED.addLeds<NEOPIXEL, 6>(leds, NUMLEDS);
CLEDController* controller2d = &FastLED.addLeds<NEOPIXEL, 7>(leds2, NUMLEDS);
hal = new CLEDControllerPhysicalStrip(controller, "Test Strip");
hal2D = new CLEDControllerPhysicalMatrix(controller2d, "Test Matrix", ArrangementType::COLUMNSERPENTINE, 6, 4);
smHAL = new SmartMatrixPhysicalMatrix(&backgroundLayer, "Test SM Matrix", kMatrixWidth, kMatrixHeight);
canRGB24Translate(someColor);
}
void loop() {
// put your main code here, to run repeatedly:
}