circular_strip.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef _CIRCULAR_STRIP_H_
  2. #define _CIRCULAR_STRIP_H_
  3. #include "led.h"
  4. #include <driver/gpio.h>
  5. #include <led_strip.h>
  6. #include <esp_timer.h>
  7. #include <atomic>
  8. #include <mutex>
  9. #include <vector>
  10. #define DEFAULT_BRIGHTNESS 32
  11. #define LOW_BRIGHTNESS 4
  12. struct StripColor {
  13. uint8_t red = 0, green = 0, blue = 0;
  14. };
  15. class CircularStrip : public Led {
  16. public:
  17. CircularStrip(gpio_num_t gpio, uint8_t max_leds);
  18. virtual ~CircularStrip();
  19. void OnStateChanged() override;
  20. void SetBrightness(uint8_t default_brightness, uint8_t low_brightness);
  21. void SetAllColor(StripColor color);
  22. void SetSingleColor(uint8_t index, StripColor color);
  23. void Blink(StripColor color, int interval_ms);
  24. void Breathe(StripColor low, StripColor high, int interval_ms);
  25. void Scroll(StripColor low, StripColor high, int length, int interval_ms);
  26. private:
  27. std::mutex mutex_;
  28. TaskHandle_t blink_task_ = nullptr;
  29. led_strip_handle_t led_strip_ = nullptr;
  30. int max_leds_ = 0;
  31. std::vector<StripColor> colors_;
  32. int blink_counter_ = 0;
  33. int blink_interval_ms_ = 0;
  34. esp_timer_handle_t strip_timer_ = nullptr;
  35. std::function<void()> strip_callback_ = nullptr;
  36. uint8_t default_brightness_ = DEFAULT_BRIGHTNESS;
  37. uint8_t low_brightness_ = LOW_BRIGHTNESS;
  38. void StartStripTask(int interval_ms, std::function<void()> cb);
  39. void Rainbow(StripColor low, StripColor high, int interval_ms);
  40. void FadeOut(int interval_ms);
  41. };
  42. #endif // _CIRCULAR_STRIP_H_