figments: input: add pointer type to variant, and new config update event

This commit is contained in:
Torrie Fischer 2023-02-18 18:44:17 +01:00
parent ce78825f66
commit 7152d70a02

View File

@ -13,6 +13,7 @@ struct Variant {
Integer,
String,
Color,
Pointer,
};
Variant(int v)
@ -24,6 +25,9 @@ struct Variant {
Variant(const CRGB &v)
: type(Color), m_value{.asRGB={v.r, v.g, v.b}} {}
Variant(void* p)
: type(Pointer), m_value{.asPointer=p} {}
Variant()
: type(Null) {}
@ -33,12 +37,16 @@ struct Variant {
CRGB asRGB() const;
int asInt() const;
bool asBool() const;
template<typename T> T* as() const {
return (T*)m_value.asPointer;
}
private:
union {
int asInt;
const char* asString;
uint8_t asRGB[3];
void* asPointer;
} m_value;
};
@ -88,6 +96,7 @@ struct InputEvent: public Variant {
LoadConfigurationByName,
SetColor,
SaveConfigurationRequest,
ConfigurationChanged,
// Firmware events
FirmwareUpdate,
@ -166,6 +175,17 @@ private:
std::function<InputEvent(const InputEvent)> m_func;
};
class ConfigTaskMixin : public virtual Loopable {
public:
void handleEvent(const InputEvent &evt) override {
if (evt.intent == InputEvent::ConfigurationChanged) {
handleConfigChange(evt);
}
}
virtual void handleConfigChange(const InputEvent& evt) {}
};
class OnlineTaskMixin : public virtual Loopable {
public:
void handleEvent(const InputEvent &evt) override {