diff --git a/lib/Figments/Input.h b/lib/Figments/Input.h index 242ea18..30b6e36 100644 --- a/lib/Figments/Input.h +++ b/lib/Figments/Input.h @@ -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 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 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 {