Compare commits
No commits in common. "9a368316583f71e7dfc7b396c4de06b1f787d35c" and "ce78825f6627eb7e727365a7b7e48ac716c52b20" have entirely different histories.
9a36831658
...
ce78825f66
@ -13,8 +13,5 @@
|
||||
"Acid": ["Chimes", "Pulse", "MPU5060", "IdleColors", "Rainbow"],
|
||||
"Flashlight": ["Flashlight"]
|
||||
},
|
||||
"surfaceMap": "default",
|
||||
"defaults": {
|
||||
"mqtt.ip": "10.0.0.2"
|
||||
}
|
||||
"surfaceMap": "default"
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ struct Variant {
|
||||
Integer,
|
||||
String,
|
||||
Color,
|
||||
Pointer,
|
||||
};
|
||||
|
||||
Variant(int v)
|
||||
@ -25,9 +24,6 @@ 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) {}
|
||||
|
||||
@ -37,16 +33,12 @@ 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;
|
||||
};
|
||||
|
||||
@ -96,7 +88,6 @@ struct InputEvent: public Variant {
|
||||
LoadConfigurationByName,
|
||||
SetColor,
|
||||
SaveConfigurationRequest,
|
||||
ConfigurationChanged,
|
||||
|
||||
// Firmware events
|
||||
FirmwareUpdate,
|
||||
@ -175,17 +166,6 @@ 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 {
|
||||
|
@ -146,9 +146,6 @@ ConfigService::loadProfile(const char* 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"];
|
||||
jsonConfig.clear();
|
||||
loadMap(configName);
|
||||
|
@ -37,7 +37,6 @@ struct ConfigService: public Task {
|
||||
const CoordinateMapping* coordMap() const { return &m_jsonMap; }
|
||||
const char* loadedProfile() const;
|
||||
void overrideProfile(const char* profileName);
|
||||
const char* getConfigValue(const char* key) const;
|
||||
|
||||
private:
|
||||
HardwareConfig m_config;
|
||||
|
@ -198,27 +198,20 @@ 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
|
||||
MQTTTelemetry::loop()
|
||||
{
|
||||
BufferedInputSource::loop();
|
||||
OnlineTaskMixin::loop();
|
||||
ConfigTaskMixin::loop();
|
||||
}
|
||||
|
||||
void
|
||||
MQTTTelemetry::onOnline()
|
||||
{
|
||||
const IPAddress server(10, 0, 0, 2);
|
||||
|
||||
m_needHeartbeat = true;
|
||||
m_mqtt.setServer(m_hostBuf, 1883);
|
||||
m_mqtt.setServer(server, 1883);
|
||||
m_mqtt.setBufferSize(1024);
|
||||
m_mqtt.setCallback(&MQTTTelemetry::s_callback);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin, ConfigTaskMixin {
|
||||
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
|
||||
public:
|
||||
MQTTTelemetry();
|
||||
void setSequencer(Sequencer* seq) { m_sequencer = seq; }
|
||||
@ -46,7 +46,6 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin, ConfigTaskMix
|
||||
}
|
||||
|
||||
void handleEventOnline(const InputEvent& evt) override;
|
||||
void handleConfigChange(const InputEvent& evt) override;
|
||||
void loop() override;
|
||||
|
||||
void loopOnline() override;
|
||||
@ -66,7 +65,6 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin, ConfigTaskMix
|
||||
bool m_isOn = true;
|
||||
static char s_topicBuf[128];
|
||||
static char s_payloadBuf[512];
|
||||
static char s_hostBuf[15];
|
||||
|
||||
void publishDoc(const char* topic);
|
||||
void publishDoc(const char* topic, bool retain);
|
||||
|
Loading…
Reference in New Issue
Block a user