Pushing up a preliminary version of GULLSManager

This commit is contained in:
2024-07-05 11:01:19 -04:00
parent 126cc58c67
commit 414a5bb749
5 changed files with 188 additions and 6 deletions

View File

@@ -8,20 +8,26 @@
template <typename T>
class Action {
public:
Action(function<bool(StreamEvent*)> _funcEventMatchesAction, function<T*(StreamEvent*)> _funcInvokeAction) :
funcEventMatchesAction(_funcEventMatchesAction), funcInvokeAction(_funcInvokeAction) {}
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

41
include/GULLSManager.h Normal file
View File

@@ -0,0 +1,41 @@
#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

9
include/GlobalSettings.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef GLOBALSETTINGS_H
#define GLOBALSETTINGS_H
#define MAX_RESPONSE_ACTIONS 15
#define MAX_ANIMATION_BUILDER_ACTIONS 30
#define MAX_ANIMATIONS 15
#define MAX_HALS 15
#endif

View File

@@ -10,7 +10,6 @@ class StreamEvent
handled = false;
code = _readFrom->read();
subCode = _readFrom->read();
flags = _readFrom->read();
if (flags & 0x01 == 1) {
@@ -29,8 +28,9 @@ class StreamEvent
virtual ~StreamEvent() { delete[] payload; }
void markHandled() { handled = true; }
uint8_t getCode() { return code; }
uint8_t getSubCode() { return subCode; }
uint16_t getPayloadSize() { return payloadSize; }
@@ -49,7 +49,6 @@ class StreamEvent
payloadSize;
uint8_t
code,
subCode,
flags;
bool
handled;