|
- #pragma once
-
- #include <cstdint>
- #include <string>
-
-
- struct Color {
- uint8_t r, g, b;
- };
-
- typedef uint16_t Fixed;
- constexpr int factor = 65536;
- constexpr int shift = 16;
-
-
- struct Gradient {
- Color at(Fixed x) const;
-
- unsigned int n_colors;
- Color colors[];
- };
-
- struct Pattern {
- void step(Color[], int, int64_t &last_us, Fixed &offset) const;
-
- int cycle_length;
- int cycle_time_ms;
- bool reverse;
- bool march;
- Gradient gradient;
- };
-
- class LEDStrip {
- public:
- LEDStrip(int length);
-
- void step();
-
- virtual void show() const = 0;
-
- void setPattern(const Pattern* _pattern) { pattern = _pattern; }
- const Pattern* getPattern() const { return pattern; }
-
- int getLength() const { return length; }
-
- protected:
- const int length;
- const Pattern *pattern;
- Color *pixels;
-
- private:
- int64_t last_us;
- Fixed offset;
- };
-
- class TerminalLEDs : public LEDStrip {
- public:
- TerminalLEDs(int length) : LEDStrip(length) {}
- void show() const;
- };
|