Files
renderbug-cpp/src/inputs/ColorCycle.h

41 lines
1.1 KiB
C++

#include <Figments.h>
#include <ArduinoLog.h>
template<int Period>
class ColorSequenceInput: public InputSource {
public:
ColorSequenceInput(const std::vector<CRGB> &colors, const char* name, Task::State initialState)
: InputSource(name, initialState), m_colors(colors) {}
InputEvent read() override {
EVERY_N_SECONDS(Period) {
m_idx %= m_colors.size();
m_reset = true;
m_idx++;
}
if (m_reset) {
m_reset = false;
Log.notice("Cycling %s color to %d [%d, %d, %d]", name, m_idx, m_colors[m_idx].r, m_colors[m_idx].g, m_colors[m_idx].b);
return InputEvent{InputEvent::SetColor, m_colors[m_idx]};
}
return InputEvent{};
}
void handleEvent(const InputEvent& evt) override {
if (evt.intent == InputEvent::Beat) {
m_idx %= m_colors.size();
m_reset = true;
m_idx++;
}
}
void onStart() override {
m_reset = true;
}
private:
std::vector<CRGB> m_colors;
unsigned int m_idx = 0;
bool m_reset = true;
};