40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#include "../Figments/Figments.h"
|
|
|
|
template<int Period>
|
|
class ColorSequenceInput: public InputSource {
|
|
public:
|
|
ColorSequenceInput(const std::vector<NSFastLED::CRGB> &colors, const char* name, Task::State initialState)
|
|
: InputSource(name, initialState), m_colors(colors) {}
|
|
|
|
InputEvent read() override {
|
|
if (m_reset) {
|
|
m_reset = false;
|
|
m_override = false;
|
|
return InputEvent{InputEvent::SetColor, m_colors[m_idx]};
|
|
}
|
|
if (!m_override) {
|
|
EVERY_N_SECONDS(Period) {
|
|
m_idx %= m_colors.size();
|
|
return InputEvent{InputEvent::SetColor, m_colors[m_idx++]};
|
|
}
|
|
}
|
|
return InputEvent{};
|
|
}
|
|
|
|
void handleEvent(const InputEvent& event) {
|
|
if (event.intent == InputEvent::SetColor) {
|
|
m_override = true;
|
|
}
|
|
}
|
|
|
|
void onStart() override {
|
|
m_reset = true;
|
|
}
|
|
|
|
private:
|
|
std::vector<NSFastLED::CRGB> m_colors;
|
|
int m_idx = 0;
|
|
bool m_reset = true;
|
|
bool m_override = false;
|
|
};
|