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