Compare commits
2 Commits
ce78825f66
...
9a36831658
Author | SHA1 | Date | |
---|---|---|---|
9a36831658 | |||
7152d70a02 |
@ -13,5 +13,8 @@
|
|||||||
"Acid": ["Chimes", "Pulse", "MPU5060", "IdleColors", "Rainbow"],
|
"Acid": ["Chimes", "Pulse", "MPU5060", "IdleColors", "Rainbow"],
|
||||||
"Flashlight": ["Flashlight"]
|
"Flashlight": ["Flashlight"]
|
||||||
},
|
},
|
||||||
"surfaceMap": "default"
|
"surfaceMap": "default",
|
||||||
|
"defaults": {
|
||||||
|
"mqtt.ip": "10.0.0.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -146,6 +146,9 @@ ConfigService::loadProfile(const char* profileName)
|
|||||||
Log.warning("config: Could not load profile %s!", profileName);
|
Log.warning("config: Could not load profile %s!", profileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonObject defaults = jsonConfig["defaults"];
|
||||||
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::ConfigurationChanged, &defaults});
|
||||||
|
|
||||||
String configName = jsonConfig["surfaceMap"];
|
String configName = jsonConfig["surfaceMap"];
|
||||||
jsonConfig.clear();
|
jsonConfig.clear();
|
||||||
loadMap(configName);
|
loadMap(configName);
|
||||||
|
@ -37,6 +37,7 @@ struct ConfigService: public Task {
|
|||||||
const CoordinateMapping* coordMap() const { return &m_jsonMap; }
|
const CoordinateMapping* coordMap() const { return &m_jsonMap; }
|
||||||
const char* loadedProfile() const;
|
const char* loadedProfile() const;
|
||||||
void overrideProfile(const char* profileName);
|
void overrideProfile(const char* profileName);
|
||||||
|
const char* getConfigValue(const char* key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HardwareConfig m_config;
|
HardwareConfig m_config;
|
||||||
|
@ -198,20 +198,27 @@ MQTTTelemetry::handleEventOnline(const InputEvent& evt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MQTTTelemetry::handleConfigChange(const InputEvent& event)
|
||||||
|
{
|
||||||
|
const JsonObject* obj = static_cast<JsonObject*>(event.value().asPointer());
|
||||||
|
strncpy(m_hostBuf, obj["mqtt.ip"].c_str(), sizeof(m_hostBuf));
|
||||||
|
m_mqtt.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MQTTTelemetry::loop()
|
MQTTTelemetry::loop()
|
||||||
{
|
{
|
||||||
BufferedInputSource::loop();
|
BufferedInputSource::loop();
|
||||||
OnlineTaskMixin::loop();
|
OnlineTaskMixin::loop();
|
||||||
|
ConfigTaskMixin::loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MQTTTelemetry::onOnline()
|
MQTTTelemetry::onOnline()
|
||||||
{
|
{
|
||||||
const IPAddress server(10, 0, 0, 2);
|
|
||||||
|
|
||||||
m_needHeartbeat = true;
|
m_needHeartbeat = true;
|
||||||
m_mqtt.setServer(server, 1883);
|
m_mqtt.setServer(m_hostBuf, 1883);
|
||||||
m_mqtt.setBufferSize(1024);
|
m_mqtt.setBufferSize(1024);
|
||||||
m_mqtt.setCallback(&MQTTTelemetry::s_callback);
|
m_mqtt.setCallback(&MQTTTelemetry::s_callback);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
|
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin, ConfigTaskMixin {
|
||||||
public:
|
public:
|
||||||
MQTTTelemetry();
|
MQTTTelemetry();
|
||||||
void setSequencer(Sequencer* seq) { m_sequencer = seq; }
|
void setSequencer(Sequencer* seq) { m_sequencer = seq; }
|
||||||
@ -46,6 +46,7 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleEventOnline(const InputEvent& evt) override;
|
void handleEventOnline(const InputEvent& evt) override;
|
||||||
|
void handleConfigChange(const InputEvent& evt) override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
void loopOnline() override;
|
void loopOnline() override;
|
||||||
@ -65,6 +66,7 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
|
|||||||
bool m_isOn = true;
|
bool m_isOn = true;
|
||||||
static char s_topicBuf[128];
|
static char s_topicBuf[128];
|
||||||
static char s_payloadBuf[512];
|
static char s_payloadBuf[512];
|
||||||
|
static char s_hostBuf[15];
|
||||||
|
|
||||||
void publishDoc(const char* topic);
|
void publishDoc(const char* topic);
|
||||||
void publishDoc(const char* topic, bool retain);
|
void publishDoc(const char* topic, bool retain);
|
||||||
|
Loading…
Reference in New Issue
Block a user