diff --git a/include/Action.h b/include/Action.h deleted file mode 100644 index 7ec83fa..0000000 --- a/include/Action.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ACTION_H -#define ACTION_H - -#include "Arduino.h" -#include "functional" -#include "StreamEvent.h" - -template -class Action { - public: - Action(function _funcEventMatchesAction, function _funcInvokeAction, - function _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 funcEventMatchesAction; - function funcInvokeAction; - function funcDescribeAction; -}; - -#endif \ No newline at end of file diff --git a/include/CLEDControllerPhysicalMatrix.h b/include/CLEDControllerPhysicalMatrix.h index c9f3f29..206fdf5 100644 --- a/include/CLEDControllerPhysicalMatrix.h +++ b/include/CLEDControllerPhysicalMatrix.h @@ -60,7 +60,7 @@ class CLEDControllerPhysicalMatrix : public LEDHAL2D { protected: void updateLEDs() { - controller->showLeds(); + controller->showLeds(255); } private: diff --git a/include/CLEDControllerPhysicalStrip.h b/include/CLEDControllerPhysicalStrip.h index 2427c7e..4863663 100644 --- a/include/CLEDControllerPhysicalStrip.h +++ b/include/CLEDControllerPhysicalStrip.h @@ -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: diff --git a/include/GULLSManager.h b/include/GULLSManager.h deleted file mode 100644 index 39875c2..0000000 --- a/include/GULLSManager.h +++ /dev/null @@ -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* action); - - bool addAnimationBuilderAction(Action* action); - - void update(); - private: - uint16_t - maxHALs, - maxAnimations, - maxResponseActions, - maxAnimationBuilderActions; - Stream* - stream; - LEDHAL** - hals; - AnimationBase** - animations; - Action** - responseActions; - Action** - animationBuilderActions; -}; - -#endif \ No newline at end of file diff --git a/include/SmartMatrixPhysicalMatrix.h b/include/SmartMatrixPhysicalMatrix.h index 5f02a2d..17b5b9f 100644 --- a/include/SmartMatrixPhysicalMatrix.h +++ b/include/SmartMatrixPhysicalMatrix.h @@ -1,6 +1,8 @@ #ifndef SMARTMATRIXPHYSICALMATRIX_H #define SMARTMATRIXPHYSICALMATRIX_H +#ifdef CORE_TEENSY + #include "SmartMatrix.h" #include "LEDHAL2D.h" @@ -43,4 +45,5 @@ class SmartMatrixPhysicalMatrix : public LEDHAL2D { SMLayerBackground* layer; }; +#endif #endif \ No newline at end of file diff --git a/include/StreamEvent.h b/include/StreamEvent.h index 3d8431a..ab5c3bb 100644 --- a/include/StreamEvent.h +++ b/include/StreamEvent.h @@ -10,6 +10,7 @@ class StreamEvent handled = false; code = _readFrom->read(); + subCode = _readFrom->read(); flags = _readFrom->read(); if (flags & 0x01 == 1) { @@ -32,6 +33,8 @@ class StreamEvent uint8_t getCode() { return code; } + uint8_t getSubCode() { return subCode; } + uint16_t getPayloadSize() { return payloadSize; } byte* getPayload() { return payload; } @@ -40,7 +43,7 @@ class StreamEvent bool isResponse() { return flags & 0x02 == 2; } bool isDescribeRequest() { return flags & 0x04 == 4; } - virtual ~StreamEvent() { delete[] payload; } + ~StreamEvent() { delete[] payload; } private: byte* @@ -49,6 +52,7 @@ class StreamEvent payloadSize; uint8_t code, + subCode, flags; bool handled; diff --git a/platformio.ini b/platformio.ini index c797682..5ee5bab 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = teensy36 +default_envs = uno [common] @@ -22,3 +22,14 @@ lib_deps = pixelmatix/SmartMatrix@^4.0.3 pfeerick/elapsedMillis@^1.0.6 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 diff --git a/src/GULLSManager.cpp b/src/GULLSManager.cpp deleted file mode 100644 index 99a7588..0000000 --- a/src/GULLSManager.cpp +++ /dev/null @@ -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*[maxResponseActions]; - - for(uint16_t i = 0; i < maxResponseActions; i++) { - responseActions[i] = nullptr; - } - - animationBuilderActions = new Action*[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* action) { - for(uint16_t i = 0; i < maxResponseActions; i++) { - if(responseActions[i] == nullptr) { - responseActions[i] = action; - return true; - } - } - - return false; -} - -bool GULLSManager::addAnimationBuilderAction(Action* 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(); - } - } -} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 00c54e8..22dabce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include +#ifdef CORE_TEENSY #include "MatrixHardware_Teensy3_ShieldV1toV3.h" #include "SmartMatrix.h" +#endif #include "FastLED.h" #include "LEDHAL.h" @@ -12,6 +14,8 @@ #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 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_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions); - +#endif CRGB leds[NUMLEDS]; CRGB leds2[NUMLEDS]; @@ -37,21 +41,10 @@ LEDHAL* hal; LEDHAL2D* hal2D; LEDHAL2D* smHAL; -rgb24 canRGB24Translate(rgb24 color) { - color.red = 0; - - return color; -} - void setup() { CLEDController* controller = &FastLED.addLeds(leds, NUMLEDS); - CLEDController* controller2d = &FastLED.addLeds(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() {