renderbug-cpp/firmware/inputs/ColorCycle.h

40 lines
1.0 KiB
C
Raw Normal View History

2019-05-10 05:17:29 +00:00
#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 {
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:
std::vector<NSFastLED::CRGB> m_colors;
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
};