port to platformio
This commit is contained in:
32
src/inputs/ColorCycle.h
Normal file
32
src/inputs/ColorCycle.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#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 onStart() override {
|
||||
m_reset = true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<CRGB> m_colors;
|
||||
unsigned int m_idx = 0;
|
||||
bool m_reset = true;
|
||||
};
|
Reference in New Issue
Block a user