config: implement reading app-specific configs from profile
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Torrie Fischer 2023-02-18 18:44:44 +01:00
parent 7152d70a02
commit 9a36831658
5 changed files with 21 additions and 5 deletions

View File

@ -13,5 +13,8 @@
"Acid": ["Chimes", "Pulse", "MPU5060", "IdleColors", "Rainbow"],
"Flashlight": ["Flashlight"]
},
"surfaceMap": "default"
"surfaceMap": "default",
"defaults": {
"mqtt.ip": "10.0.0.2"
}
}

View File

@ -146,6 +146,9 @@ 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);

View File

@ -37,6 +37,7 @@ 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;

View File

@ -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
MQTTTelemetry::loop()
{
BufferedInputSource::loop();
OnlineTaskMixin::loop();
ConfigTaskMixin::loop();
}
void
MQTTTelemetry::onOnline()
{
const IPAddress server(10, 0, 0, 2);
m_needHeartbeat = true;
m_mqtt.setServer(server, 1883);
m_mqtt.setServer(m_hostBuf, 1883);
m_mqtt.setBufferSize(1024);
m_mqtt.setCallback(&MQTTTelemetry::s_callback);
}

View File

@ -12,7 +12,7 @@
#include <WiFi.h>
#endif
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin, ConfigTaskMixin {
public:
MQTTTelemetry();
void setSequencer(Sequencer* seq) { m_sequencer = seq; }
@ -46,6 +46,7 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
}
void handleEventOnline(const InputEvent& evt) override;
void handleConfigChange(const InputEvent& evt) override;
void loop() override;
void loopOnline() override;
@ -65,6 +66,7 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
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);