A number of changes to try to get to the point where I could use Wokwi for some basic testing of animations
This commit is contained in:
parent
414a5bb749
commit
67ac7aa752
@ -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
|
|
@ -60,7 +60,7 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateLEDs() {
|
void updateLEDs() {
|
||||||
controller->showLeds();
|
controller->showLeds(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -13,7 +13,7 @@ class CLEDControllerPhysicalStrip : public LEDHAL {
|
|||||||
void setColor(int16_t pixel, CRGB color) { controller->leds()[pixel] = color; }
|
void setColor(int16_t pixel, CRGB color) { controller->leds()[pixel] = color; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateLEDs() { controller->showLeds(); }
|
void updateLEDs() { controller->showLeds(255); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -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
|
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef SMARTMATRIXPHYSICALMATRIX_H
|
#ifndef SMARTMATRIXPHYSICALMATRIX_H
|
||||||
#define SMARTMATRIXPHYSICALMATRIX_H
|
#define SMARTMATRIXPHYSICALMATRIX_H
|
||||||
|
|
||||||
|
#ifdef CORE_TEENSY
|
||||||
|
|
||||||
#include "SmartMatrix.h"
|
#include "SmartMatrix.h"
|
||||||
#include "LEDHAL2D.h"
|
#include "LEDHAL2D.h"
|
||||||
|
|
||||||
@ -44,3 +46,4 @@ class SmartMatrixPhysicalMatrix : public LEDHAL2D {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
@ -10,6 +10,7 @@ class StreamEvent
|
|||||||
handled = false;
|
handled = false;
|
||||||
|
|
||||||
code = _readFrom->read();
|
code = _readFrom->read();
|
||||||
|
subCode = _readFrom->read();
|
||||||
flags = _readFrom->read();
|
flags = _readFrom->read();
|
||||||
|
|
||||||
if (flags & 0x01 == 1) {
|
if (flags & 0x01 == 1) {
|
||||||
@ -32,6 +33,8 @@ class StreamEvent
|
|||||||
|
|
||||||
uint8_t getCode() { return code; }
|
uint8_t getCode() { return code; }
|
||||||
|
|
||||||
|
uint8_t getSubCode() { return subCode; }
|
||||||
|
|
||||||
uint16_t getPayloadSize() { return payloadSize; }
|
uint16_t getPayloadSize() { return payloadSize; }
|
||||||
|
|
||||||
byte* getPayload() { return payload; }
|
byte* getPayload() { return payload; }
|
||||||
@ -40,7 +43,7 @@ class StreamEvent
|
|||||||
bool isResponse() { return flags & 0x02 == 2; }
|
bool isResponse() { return flags & 0x02 == 2; }
|
||||||
bool isDescribeRequest() { return flags & 0x04 == 4; }
|
bool isDescribeRequest() { return flags & 0x04 == 4; }
|
||||||
|
|
||||||
virtual ~StreamEvent() { delete[] payload; }
|
~StreamEvent() { delete[] payload; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte*
|
byte*
|
||||||
@ -49,6 +52,7 @@ class StreamEvent
|
|||||||
payloadSize;
|
payloadSize;
|
||||||
uint8_t
|
uint8_t
|
||||||
code,
|
code,
|
||||||
|
subCode,
|
||||||
flags;
|
flags;
|
||||||
bool
|
bool
|
||||||
handled;
|
handled;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = teensy36
|
default_envs = uno
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
|
|
||||||
@ -22,3 +22,14 @@ lib_deps =
|
|||||||
pixelmatix/SmartMatrix@^4.0.3
|
pixelmatix/SmartMatrix@^4.0.3
|
||||||
pfeerick/elapsedMillis@^1.0.6
|
pfeerick/elapsedMillis@^1.0.6
|
||||||
adafruit/Adafruit GFX Library@^1.11.9
|
adafruit/Adafruit GFX Library@^1.11.9
|
||||||
|
arduino-libraries/SD@^1.3.0
|
||||||
|
|
||||||
|
[env:uno]
|
||||||
|
platform = atmelavr
|
||||||
|
board = uno
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
fastled/FastLED@^3.7.0
|
||||||
|
pfeerick/elapsedMillis@^1.0.6
|
||||||
|
adafruit/Adafruit GFX Library@^1.11.9
|
||||||
|
arduino-libraries/SD@^1.3.0
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
17
src/main.cpp
17
src/main.cpp
@ -1,7 +1,9 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#ifdef CORE_TEENSY
|
||||||
#include "MatrixHardware_Teensy3_ShieldV1toV3.h"
|
#include "MatrixHardware_Teensy3_ShieldV1toV3.h"
|
||||||
#include "SmartMatrix.h"
|
#include "SmartMatrix.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
#include "LEDHAL.h"
|
#include "LEDHAL.h"
|
||||||
@ -12,6 +14,8 @@
|
|||||||
|
|
||||||
#define NUMLEDS 24
|
#define NUMLEDS 24
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CORE_TEENSY
|
||||||
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 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 kMatrixWidth = 96; // known working: 32, 64, 96, 128
|
||||||
@ -25,7 +29,7 @@ const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
|
|||||||
|
|
||||||
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
|
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
|
||||||
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
|
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
|
||||||
|
#endif
|
||||||
|
|
||||||
CRGB leds[NUMLEDS];
|
CRGB leds[NUMLEDS];
|
||||||
CRGB leds2[NUMLEDS];
|
CRGB leds2[NUMLEDS];
|
||||||
@ -37,21 +41,10 @@ LEDHAL* hal;
|
|||||||
LEDHAL2D* hal2D;
|
LEDHAL2D* hal2D;
|
||||||
LEDHAL2D* smHAL;
|
LEDHAL2D* smHAL;
|
||||||
|
|
||||||
rgb24 canRGB24Translate(rgb24 color) {
|
|
||||||
color.red = 0;
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
CLEDController* controller = &FastLED.addLeds<NEOPIXEL, 6>(leds, NUMLEDS);
|
CLEDController* controller = &FastLED.addLeds<NEOPIXEL, 6>(leds, NUMLEDS);
|
||||||
CLEDController* controller2d = &FastLED.addLeds<NEOPIXEL, 7>(leds2, NUMLEDS);
|
|
||||||
|
|
||||||
hal = new CLEDControllerPhysicalStrip(controller, "Test Strip");
|
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() {
|
void loop() {
|
||||||
|
Loading…
Reference in New Issue
Block a user