config: add new Configuration class to simplify handling json config update api
This commit is contained in:
@ -3,18 +3,12 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void
|
||||
Power::handleConfigChange(const InputEvent& event)
|
||||
Power::handleConfigChange(const Configuration& config)
|
||||
{
|
||||
const JsonObject& cfg = *event.as<JsonObject>();
|
||||
if (cfg.containsKey("power.milliamps")) {
|
||||
m_milliamps = cfg["power.milliamps"];
|
||||
}
|
||||
if (cfg.containsKey("power.volts")) {
|
||||
m_voltage = cfg["power.volts"];
|
||||
}
|
||||
if (cfg.containsKey("power.useBPM")) {
|
||||
m_useBPM = cfg["power.useBPM"];
|
||||
}
|
||||
m_milliamps = config.get("power.milliamps", m_milliamps);
|
||||
m_voltage = config.get("power.volts", m_voltage);
|
||||
m_useBPM = config.get("power.useBPM", m_useBPM);
|
||||
|
||||
if (m_voltage == 0 || m_milliamps == 0) {
|
||||
Log.notice("power: Impossible power config: %dma @ %dv", m_milliamps, m_voltage);
|
||||
m_valid = false;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <Figments.h>
|
||||
#include "../Config.h"
|
||||
|
||||
class Power: public Figment, ConfigTaskMixin {
|
||||
public:
|
||||
@ -27,7 +28,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void handleConfigChange(const InputEvent& event) override;
|
||||
void handleConfigChange(const Configuration& config) override;
|
||||
|
||||
void loop() override {
|
||||
ConfigTaskMixin::loop();
|
||||
|
Reference in New Issue
Block a user