animations: power: implement commands for brightness+power on/off

This commit is contained in:
Torrie Fischer
2023-12-11 07:58:17 +01:00
parent 58df15702d
commit 9c53d05ab1
2 changed files with 58 additions and 4 deletions

View File

@@ -10,15 +10,17 @@ public:
switch (evt.intent) {
case InputEvent::PowerToggle:
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;
case InputEvent::SetPower:
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;
case InputEvent::SetBrightness:
m_brightness = evt.asInt();
m_brightness = 255;
m_forced = false;
break;
case InputEvent::Beat:
m_beatDecay.set(0, 255);
@@ -40,7 +42,7 @@ public:
}
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 clippedBrightness = std::min(decayedBrightness, (uint8_t)255);
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:
AnimatedNumber m_powerState = 255;
@@ -59,4 +64,5 @@ private:
uint16_t m_milliamps = 500;
bool m_valid = true;
bool m_useBPM = false;
bool m_forced = false;
};