animations: power: make configurable

This commit is contained in:
2023-02-19 18:45:28 +01:00
parent 8223688d7b
commit d824dbfa45
3 changed files with 48 additions and 27 deletions

View File

@@ -0,0 +1,30 @@
#include "./Power.h"
#include "../Static.h"
#include <ArduinoJson.h>
void
Power::handleConfigChange(const InputEvent& event)
{
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"];
}
if (m_voltage == 0 || m_milliamps == 0) {
Log.notice("power: Impossible power config: %dma @ %dv", m_milliamps, m_voltage);
m_valid = false;
} else {
Log.notice("power: Configured to use %dma @ %dv", m_milliamps, m_voltage);
m_valid = true;
FastLED.setMaxPowerInVoltsAndMilliamps(m_voltage, m_milliamps);
}
}
STATIC_ALLOC(Power);
STATIC_TASK(Power);