The beginnings of a rework

This commit is contained in:
2026-08-09 21:47:17 -04:00
parent 414a5bb749
commit 02a0bfee2b
13 changed files with 251 additions and 267 deletions

View File

@@ -1,127 +0,0 @@
#include "GULLSManager.h"
GULLSManager::GULLSManager(Stream* _stream, uint16_t _maxHALs, uint16_t _maxAnimations,
uint16_t _maxResponseActions, uint16_t _maxAnimationBuilderActions) {
stream = _stream;
maxHALs = _maxHALs;
maxAnimations = _maxAnimations;
maxResponseActions = _maxResponseActions;
maxAnimationBuilderActions = _maxAnimationBuilderActions;
hals = new LEDHAL*[maxHALs];
for(uint16_t i = 0; i < maxHALs; i++) {
hals[i] = nullptr;
}
animations = new AnimationBase*[maxAnimations];
for(uint16_t i = 0; i < maxAnimations; i++) {
animations[i] = nullptr;
}
responseActions = new Action<char>*[maxResponseActions];
for(uint16_t i = 0; i < maxResponseActions; i++) {
responseActions[i] = nullptr;
}
animationBuilderActions = new Action<AnimationBase>*[maxAnimationBuilderActions];
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
animationBuilderActions[i] = nullptr;
}
}
bool GULLSManager::addLEDHAL(LEDHAL* hal) {
for(uint16_t i = 0; i < maxHALs; i++) {
if(hals[i] == nullptr) {
hals[i] = hal;
return true;
}
}
return false;
}
bool GULLSManager::addAnimation(AnimationBase* animation) {
for(uint16_t i = 0; i < maxAnimations; i++) {
if(animations[i] == nullptr) {
animations[i] = animation;
return true;
}
}
return false;
}
bool GULLSManager::addResponseAction(Action<char>* action) {
for(uint16_t i = 0; i < maxResponseActions; i++) {
if(responseActions[i] == nullptr) {
responseActions[i] = action;
return true;
}
}
return false;
}
bool GULLSManager::addAnimationBuilderAction(Action<AnimationBase>* action) {
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
if(animationBuilderActions[i] == nullptr) {
animationBuilderActions[i] = action;
return true;
}
}
return false;
}
void GULLSManager::update() {
if(stream->available()) {
StreamEvent event(stream);
for(uint16_t i = 0; i < maxResponseActions; i++) {
if(responseActions[i] != nullptr) {
if(responseActions[i]->eventMatchesAction(&event)) {
stream->write(responseActions[i]->invokeAction(&event));
event.markHandled();
break;
}
}
}
if(!event.isHandled()) {
for(uint16_t i = 0; i < maxAnimationBuilderActions; i++) {
if(animationBuilderActions[i] != nullptr) {
if(animationBuilderActions[i]->eventMatchesAction(&event)) {
this->addAnimation(animationBuilderActions[i]->invokeAction(&event));
event.markHandled();
break;
}
}
}
}
if(!event.isHandled()) {
stream->print(F("ERROR: An event with code "));
stream->print(event.getCode());
stream->println(F(" was registered but went unprocessed by any actions!"));
}
}
for(uint16_t i = 0; i < maxAnimations; i++) {
if(animations[i] != nullptr) {
animations[i]->update();
}
}
for(uint16_t i = 0; i < maxHALs; i++) {
if(hals[i] != nullptr) {
hals[i]->show();
}
}
}

View File

@@ -1,59 +1,54 @@
#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);
#include "SerpentineArrangement.h"
#include "TiledSerpentineArrangement.h"
#define NUMLEDS 6
#define WIDTH 6
#define HEIGHT 18
#define TILE_WIDTH 6
#define TILE_HEIGHT 6
CRGB leds[NUMLEDS];
CRGB leds2[NUMLEDS];
CRGB leds3[NUMLEDS];
CRGB leds2D[WIDTH * HEIGHT];
CRGB someColor(255, 255, 255);
CRGB rainbow[] = {CRGB::Red, CRGB::Orange, CRGB::Yellow, CRGB::Green, CRGB::Blue, CRGB::Purple};
LEDHAL* hal;
LEDHAL2D* hal2D;
LEDHAL2D* smHAL;
rgb24 canRGB24Translate(rgb24 color) {
color.red = 0;
uint16_t shiftNumber = 0;
return color;
}
SerpentineArrangement arrangement(false);
TiledSerpentineArrangement tileArrangement(false, true, TILE_WIDTH, TILE_HEIGHT);
void setup() {
Serial.begin(115200);
Serial.println("Hello World!");
CLEDController* controller = &FastLED.addLeds<NEOPIXEL, 6>(leds, NUMLEDS);
CLEDController* controller2d = &FastLED.addLeds<NEOPIXEL, 7>(leds2, NUMLEDS);
CLEDController* controller2D = &FastLED.addLeds<NEOPIXEL, 7>(leds2D, WIDTH * HEIGHT);
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);
hal2D = new CLEDControllerPhysicalMatrix(controller2D, "Test Matrix", arrangement, WIDTH, HEIGHT);
}
void loop() {
// put your main code here, to run repeatedly:
for(uint8_t i = 0; i < 6; i++) {
hal->setColor(i, rainbow[(i + shiftNumber) % 6]);
}
for(uint8_t i = 0; i < HEIGHT; i++) {
hal2D->drawFastHLine(0, i, WIDTH, rainbow[(i + shiftNumber) % 6]);
}
hal->requestShow();
hal->show();
hal2D->requestShow();
hal2D->show();
shiftNumber++;
delay(300);
}