2019-05-10 05:17:29 +00:00
|
|
|
#include "../Figments/Figments.h"
|
|
|
|
|
2021-03-28 21:50:31 +00:00
|
|
|
using CRGB = NSFastLED::CRGB;
|
|
|
|
|
2019-05-10 05:17:29 +00:00
|
|
|
template<int Period>
|
|
|
|
class ColorSequenceInput: public InputSource {
|
|
|
|
public:
|
2021-03-28 21:50:31 +00:00
|
|
|
ColorSequenceInput(const std::vector<CRGB> &colors, const char* name, Task::State initialState)
|
2019-05-10 05:17:29 +00:00
|
|
|
: InputSource(name, initialState), m_colors(colors) {}
|
|
|
|
|
|
|
|
InputEvent read() override {
|
2021-03-28 01:19:55 +00:00
|
|
|
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++]};
|
|
|
|
}
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
|
|
|
return InputEvent{};
|
|
|
|
}
|
|
|
|
|
2021-03-28 01:19:55 +00:00
|
|
|
void handleEvent(const InputEvent& event) {
|
|
|
|
if (event.intent == InputEvent::SetColor) {
|
|
|
|
m_override = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onStart() override {
|
|
|
|
m_reset = true;
|
|
|
|
}
|
|
|
|
|
2019-05-10 05:17:29 +00:00
|
|
|
private:
|
2021-03-28 21:50:31 +00:00
|
|
|
std::vector<CRGB> m_colors;
|
2019-05-10 05:17:29 +00:00
|
|
|
int m_idx = 0;
|
2021-03-28 01:19:55 +00:00
|
|
|
bool m_reset = true;
|
|
|
|
bool m_override = false;
|
2019-05-10 05:17:29 +00:00
|
|
|
};
|