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,33 +0,0 @@
#ifndef ACTION_H
#define ACTION_H
#include "Arduino.h"
#include "functional"
#include "StreamEvent.h"
template <typename T>
class Action {
public:
Action(function<bool(StreamEvent*)> _funcEventMatchesAction, function<T*(StreamEvent*)> _funcInvokeAction,
function<void(Print*)> _funcDescribeAction) : funcEventMatchesAction(_funcEventMatchesAction),
funcInvokeAction(_funcInvokeAction), funcDescribeAction(_funcDescribeAction) {}
bool eventMatchesAction(StreamEvent* event) {
return funcEventMatchesAction(event);
}
void describeAction(Print* printStream) {
funcDescribeAction(printStream);
}
T* invokeAction(StreamEvent* event) {
return funcInvokeAction(event);
}
private:
function<bool(StreamEvent*)> funcEventMatchesAction;
function<T*(StreamEvent*)> funcInvokeAction;
function<void(Print*)> funcDescribeAction;
};
#endif

View File

@@ -2,17 +2,11 @@
#define CLEDCONTROLLERPHYSICALMATRIX_H
#include "LEDHAL2D.h"
enum ArrangementType {
HORIZONTALSCAN,
HORIZONTALSERPENTINE,
COLUMNSCAN,
COLUMNSERPENTINE
};
#include "ILEDArrangement.h"
class CLEDControllerPhysicalMatrix : public LEDHAL2D {
public:
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ArrangementType _arrangement,
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ILEDArrangement& _arrangement,
int16_t width, int16_t height): LEDHAL2D(width, height, ledName, true), controller(_controller), arrangement(_arrangement) {}
virtual ~CLEDControllerPhysicalMatrix() {}
@@ -33,25 +27,7 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D {
}
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?
}
return arrangement.XY(x, y, getWidth(), getHeight());
}
uint16_t getNumLEDs() {
@@ -60,13 +36,13 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D {
protected:
void updateLEDs() {
controller->showLeds();
controller->showLeds(255);
}
private:
CLEDController*
controller;
ArrangementType
ILEDArrangement&
arrangement;
};

View File

@@ -13,7 +13,7 @@ class CLEDControllerPhysicalStrip : public LEDHAL {
void setColor(int16_t pixel, CRGB color) { controller->leds()[pixel] = color; }
protected:
void updateLEDs() { controller->showLeds(); }
void updateLEDs() { controller->showLeds(255); }
private:

View File

@@ -1,41 +0,0 @@
#ifndef GULLSMANAGER_H
#define GULLSMANAGER_H
#include "Arduino.h"
#include "Action.h"
#include "LEDHAL.h"
#include "AnimationBase.h"
class GULLSManager {
public:
GULLSManager(Stream* _stream, uint16_t _maxHALs, uint16_t _maxAnimations,
uint16_t _maxResponseActions, uint16_t _maxAnimationBuilderActions);
bool addLEDHAL(LEDHAL* hal);
bool addAnimation(AnimationBase* animation);
bool addResponseAction(Action<char>* action);
bool addAnimationBuilderAction(Action<AnimationBase>* action);
void update();
private:
uint16_t
maxHALs,
maxAnimations,
maxResponseActions,
maxAnimationBuilderActions;
Stream*
stream;
LEDHAL**
hals;
AnimationBase**
animations;
Action<char>**
responseActions;
Action<AnimationBase>**
animationBuilderActions;
};
#endif

15
include/ILEDArrangement.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef ILEDARRANGEMENT_H
#define ILEDARRANGEMENT_H
#include <Arduino.h>
// Interface is not pure virtual
class ILEDArrangement {
public:
ILEDArrangement() {}
virtual ~ILEDArrangement() {}
virtual int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) = 0;
};
#endif

24
include/ScanArrangement.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef SCANARRANGEMENT_H
#define SCANARRANGEMENT_H
#include "ILEDArrangement.h"
class ScanArrangement : public ILEDArrangement {
public:
ScanArrangement(bool _isColumnScan) : isColumnScan(_isColumnScan) {}
virtual ~ScanArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
if(isColumnScan) {
return height * x + y;
} else {
return width * y + x;
}
}
private:
bool
isColumnScan;
};
#endif

View File

@@ -0,0 +1,31 @@
#ifndef SERPENTINEARRANGEMENT_H
#define SERPENTINEARRANGEMENT_H
#include "ILEDArrangement.h"
class SerpentineArrangement : public ILEDArrangement {
public:
SerpentineArrangement(bool _isColumnSerpentine) : isColumnSerpentine(_isColumnSerpentine) {}
virtual ~SerpentineArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
if(isColumnSerpentine) {
if(x & 0x1) {
return x * height + (height - 1 - y);
} else {
return x * height + y;
}
} else {
if(y & 0x1) {
return y * width + (width - 1 - x);
} else {
return y * width + x;
}
}
}
private:
bool
isColumnSerpentine;
};
#endif

View File

@@ -0,0 +1,46 @@
#ifndef TILEDSERPENTINEARRANGEMENT_H
#define TILEDSERPENTINEARRANGEMENT_H
#include "ILEDArrangement.h"
class TiledSerpentineArrangement : public ILEDArrangement {
public:
TiledSerpentineArrangement(bool _isColumnSerpentine, bool _isVerticallyTiled,
int16_t _tileWidth, int16_t _tileHeight) : isColumnSerpentine(_isColumnSerpentine),
isVerticallyTiled(_isVerticallyTiled), tileWidth(_tileWidth), tileHeight(_tileHeight) {}
virtual ~TiledSerpentineArrangement() {}
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
int16_t tileNumber = isVerticallyTiled ? y / tileHeight : x / tileHeight;
int16_t modX = x % tileWidth;
int16_t modY = y % tileHeight;
int16_t tilePosition = 0;
if(isColumnSerpentine) {
if (x & 0x1) {
tilePosition = modX * tileHeight + (tileHeight - 1 - modY);
} else {
tilePosition = modX * tileHeight + modY;
}
} else {
if (y & 0x1) {
tilePosition = modY * tileWidth + (tileWidth - 1 - modX);
} else {
tilePosition = modY * tileWidth + modX;
}
}
return tileWidth * tileHeight * tileNumber + tilePosition;
}
private:
bool
isColumnSerpentine,
isVerticallyTiled;
int16_t
tileWidth,
tileHeight;
};
#endif