animations: power: implement commands for brightness+power on/off
This commit is contained in:
parent
58df15702d
commit
9c53d05ab1
@ -2,6 +2,54 @@
|
|||||||
#include "../Static.h"
|
#include "../Static.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
doBrightness(Args& args, Print& out)
|
||||||
|
{
|
||||||
|
String nextVal = args[1];
|
||||||
|
uint8_t newBrightness = (uint8_t)atoi(nextVal.c_str());
|
||||||
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::SetBrightness, newBrightness});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
doOn(Args& args, Print& out)
|
||||||
|
{
|
||||||
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::SetPower, 255});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
doOff(Args& args, Print& out)
|
||||||
|
{
|
||||||
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::SetPower, 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
doForceBrightness(Args& args, Print& out)
|
||||||
|
{
|
||||||
|
String nextVal = args[1];
|
||||||
|
uint8_t newBrightness = (uint8_t)atoi(nextVal.c_str());
|
||||||
|
Static<Power>::instance()->forceBrightness(newBrightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Power::forceBrightness(uint8_t v)
|
||||||
|
{
|
||||||
|
m_forced = true;
|
||||||
|
FastLED.setBrightness(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<Command> _commands = {
|
||||||
|
{"brightness", doBrightness},
|
||||||
|
{"brightness-force", doForceBrightness},
|
||||||
|
{"on", doOn},
|
||||||
|
{"off", doOff}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<Command>&
|
||||||
|
Power::commands() const
|
||||||
|
{
|
||||||
|
return _commands;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Power::handleConfigChange(const Configuration& config)
|
Power::handleConfigChange(const Configuration& config)
|
||||||
{
|
{
|
||||||
|
@ -10,15 +10,17 @@ public:
|
|||||||
switch (evt.intent) {
|
switch (evt.intent) {
|
||||||
case InputEvent::PowerToggle:
|
case InputEvent::PowerToggle:
|
||||||
m_powerState = m_powerState.value() <= 128 ? 255 : 0;
|
m_powerState = m_powerState.value() <= 128 ? 255 : 0;
|
||||||
//Log.info("POWER TOGGLE %d", m_powerState.value());
|
m_forced = false;
|
||||||
|
Log.notice("Power toggled to %t", m_powerState);
|
||||||
break;
|
break;
|
||||||
case InputEvent::SetPower:
|
case InputEvent::SetPower:
|
||||||
m_powerState = evt.asInt() == 0 ? 0 : 255;
|
m_powerState = evt.asInt() == 0 ? 0 : 255;
|
||||||
Log.notice("Power is now %d", m_powerState);
|
m_forced = false;
|
||||||
|
Log.notice("Power state is now %t", m_powerState);
|
||||||
break;
|
break;
|
||||||
case InputEvent::SetBrightness:
|
case InputEvent::SetBrightness:
|
||||||
m_brightness = evt.asInt();
|
m_brightness = evt.asInt();
|
||||||
m_brightness = 255;
|
m_forced = false;
|
||||||
break;
|
break;
|
||||||
case InputEvent::Beat:
|
case InputEvent::Beat:
|
||||||
m_beatDecay.set(0, 255);
|
m_beatDecay.set(0, 255);
|
||||||
@ -40,7 +42,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void render(Display* dpy) const override {
|
void render(Display* dpy) const override {
|
||||||
if (F_LIKELY(m_valid)) {
|
if (F_LIKELY(m_valid && !m_forced)) {
|
||||||
const uint8_t decayedBrightness = scale8((uint8_t)m_brightness, m_useBPM ? ease8InOutCubic((uint8_t)m_beatDecay) : 255);
|
const uint8_t decayedBrightness = scale8((uint8_t)m_brightness, m_useBPM ? ease8InOutCubic((uint8_t)m_beatDecay) : 255);
|
||||||
const uint8_t clippedBrightness = std::min(decayedBrightness, (uint8_t)255);
|
const uint8_t clippedBrightness = std::min(decayedBrightness, (uint8_t)255);
|
||||||
const uint8_t scaledBrightness = scale8(m_powerState, clippedBrightness);
|
const uint8_t scaledBrightness = scale8(m_powerState, clippedBrightness);
|
||||||
@ -50,6 +52,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void forceBrightness(uint8_t v);
|
||||||
|
|
||||||
|
const std::vector<Command>& commands() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AnimatedNumber m_powerState = 255;
|
AnimatedNumber m_powerState = 255;
|
||||||
@ -59,4 +64,5 @@ private:
|
|||||||
uint16_t m_milliamps = 500;
|
uint16_t m_milliamps = 500;
|
||||||
bool m_valid = true;
|
bool m_valid = true;
|
||||||
bool m_useBPM = false;
|
bool m_useBPM = false;
|
||||||
|
bool m_forced = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user