Working on preliminary version of ActionEngine
This commit is contained in:
parent
37cdd714a9
commit
126cc58c67
@ -28,7 +28,7 @@
|
|||||||
| TextMatrix | :heavy_check_mark: | | |
|
| TextMatrix | :heavy_check_mark: | | |
|
||||||
| TripCyclingMatrix | | | |
|
| TripCyclingMatrix | | | |
|
||||||
| TripCyclingStrip | | | |
|
| TripCyclingStrip | | | |
|
||||||
| GIFMatrix | :heavy_check_mark: | | |
|
| GIFMatrix | :heavy_check_mark: | :heavy_check_mark: | |
|
||||||
| FlameMatrix | :heavy_check_mark: | | |
|
| FlameMatrix | :heavy_check_mark: | | |
|
||||||
| RainfallMatrix | :heavy_check_mark: | | |
|
| RainfallMatrix | :heavy_check_mark: | | |
|
||||||
| Conway'sMatrix | :heavy_check_mark: | | |
|
| Conway'sMatrix | :heavy_check_mark: | | |
|
||||||
|
27
include/Action.h
Normal file
27
include/Action.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#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) :
|
||||||
|
funcEventMatchesAction(_funcEventMatchesAction), funcInvokeAction(_funcInvokeAction) {}
|
||||||
|
|
||||||
|
bool eventMatchesAction(StreamEvent* event) {
|
||||||
|
return funcEventMatchesAction(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
T* invokeAction(StreamEvent* event) {
|
||||||
|
return funcInvokeAction(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
function<bool(StreamEvent*)> funcEventMatchesAction;
|
||||||
|
function<T*(StreamEvent*)> funcInvokeAction;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
58
include/StreamEvent.h
Normal file
58
include/StreamEvent.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef STREAMEVENT_H
|
||||||
|
#define STREAMEVENT_H
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
class StreamEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StreamEvent(Stream* _readFrom) {
|
||||||
|
handled = false;
|
||||||
|
|
||||||
|
code = _readFrom->read();
|
||||||
|
subCode = _readFrom->read();
|
||||||
|
flags = _readFrom->read();
|
||||||
|
|
||||||
|
if (flags & 0x01 == 1) {
|
||||||
|
uint16_t payloadSizeMSB = _readFrom->read() << 8;
|
||||||
|
|
||||||
|
payloadSize == payloadSizeMSB | _readFrom->read();
|
||||||
|
|
||||||
|
payload = new byte[payloadSize];
|
||||||
|
|
||||||
|
_readFrom->readBytes(payload, payloadSize);
|
||||||
|
} else {
|
||||||
|
payloadSize = 0;
|
||||||
|
payload = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~StreamEvent() { delete[] payload; }
|
||||||
|
|
||||||
|
uint8_t getCode() { return code; }
|
||||||
|
uint8_t getSubCode() { return subCode; }
|
||||||
|
|
||||||
|
uint16_t getPayloadSize() { return payloadSize; }
|
||||||
|
|
||||||
|
byte* getPayload() { return payload; }
|
||||||
|
|
||||||
|
bool isHandled() { return handled; }
|
||||||
|
bool isResponse() { return flags & 0x02 == 2; }
|
||||||
|
bool isDescribeRequest() { return flags & 0x04 == 4; }
|
||||||
|
|
||||||
|
virtual ~StreamEvent() { delete[] payload; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
byte*
|
||||||
|
payload;
|
||||||
|
uint16_t
|
||||||
|
payloadSize;
|
||||||
|
uint8_t
|
||||||
|
code,
|
||||||
|
subCode,
|
||||||
|
flags;
|
||||||
|
bool
|
||||||
|
handled;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user