config: add new Configuration class to simplify handling json config update api
This commit is contained in:
@@ -9,6 +9,50 @@
|
||||
#include <LittleFS.h>
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
ConfigTaskMixin::handleEvent(const InputEvent &evt)
|
||||
{
|
||||
if (evt.intent == InputEvent::ConfigurationChanged) {
|
||||
const JsonObject& cfg = *evt.as<JsonObject>();
|
||||
handleConfigChange(Configuration(cfg));
|
||||
}
|
||||
}
|
||||
|
||||
Configuration::Configuration(const JsonObject& data)
|
||||
: m_json(data)
|
||||
{
|
||||
}
|
||||
|
||||
const char*
|
||||
Configuration::get(const char* key, const char* defaultVal) const
|
||||
{
|
||||
if (m_json.containsKey(key)) {
|
||||
return m_json[key];
|
||||
} else {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Configuration::get(const char* key, int defaultVal) const
|
||||
{
|
||||
if (m_json.containsKey(key)) {
|
||||
return m_json[key];
|
||||
} else {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Configuration::get(const char* key, bool defaultVal) const
|
||||
{
|
||||
if (m_json.containsKey(key)) {
|
||||
return m_json[key];
|
||||
} else {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
StaticJsonDocument<1024> jsonConfig;
|
||||
|
||||
constexpr uint16_t HardwareConfig::MAX_LED_NUM;
|
||||
|
Reference in New Issue
Block a user