ESP32 Native version of Blinky, featureful controller code for WS2811/WS2812/NeoPixels
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

63 lines
1.1KB

  1. #pragma once
  2. #include <cstdint>
  3. #include <string>
  4. struct Color {
  5. uint8_t r, g, b;
  6. } __attribute__ ((packed));
  7. typedef uint16_t Fixed;
  8. constexpr int factor = 65536;
  9. constexpr int shift = 16;
  10. struct Gradient {
  11. Color at(Fixed x) const;
  12. unsigned int n_colors;
  13. Color colors[];
  14. };
  15. struct Pattern {
  16. void step(Color[], int, int64_t &last_us, Fixed &offset) const;
  17. int cycle_length;
  18. int cycle_time_ms;
  19. bool reverse;
  20. bool march;
  21. Gradient gradient;
  22. };
  23. class LEDStrip {
  24. public:
  25. LEDStrip(int length = 0);
  26. void step();
  27. virtual void show() = 0;
  28. virtual void length_changing(int) {};
  29. void setPattern(const Pattern *_pattern) { pattern = _pattern; }
  30. const Pattern* getPattern() const { return pattern; }
  31. void setLength(int length);
  32. int getLength() const { return length; }
  33. protected:
  34. int length;
  35. const Pattern *pattern;
  36. Color *pixels;
  37. private:
  38. int64_t last_us;
  39. Fixed offset;
  40. };
  41. class TerminalLEDs : public LEDStrip {
  42. public:
  43. TerminalLEDs(int length = 0) : LEDStrip(length) {}
  44. void show();
  45. };