forked from xiaozhi/xiaozhi-esp32
feat: modify CircularStrip constructor parameter types and add SetMultiColors method (#1750)
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
#include "circular_strip.h"
|
||||
#include "application.h"
|
||||
#include <esp_log.h>
|
||||
#include <algorithm>
|
||||
|
||||
#define TAG "CircularStrip"
|
||||
|
||||
#define BLINK_INFINITE -1
|
||||
|
||||
CircularStrip::CircularStrip(gpio_num_t gpio, uint8_t max_leds) : max_leds_(max_leds) {
|
||||
CircularStrip::CircularStrip(gpio_num_t gpio, uint16_t max_leds) : max_leds_(max_leds) {
|
||||
// If the gpio is not connected, you should use NoLed class
|
||||
assert(gpio != GPIO_NUM_NC);
|
||||
|
||||
@@ -66,6 +67,17 @@ void CircularStrip::SetSingleColor(uint8_t index, StripColor color) {
|
||||
led_strip_refresh(led_strip_);
|
||||
}
|
||||
|
||||
void CircularStrip::SetMultiColors(const std::vector<StripColor>& colors) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
esp_timer_stop(strip_timer_);
|
||||
int count = std::min(max_leds_, static_cast<int>(colors.size()));
|
||||
for (int i = 0; i < count; i++) {
|
||||
colors_[i] = colors[i];
|
||||
led_strip_set_pixel(led_strip_, i, colors[i].red, colors[i].green, colors[i].blue);
|
||||
}
|
||||
led_strip_refresh(led_strip_);
|
||||
}
|
||||
|
||||
void CircularStrip::Blink(StripColor color, int interval_ms) {
|
||||
for (int i = 0; i < max_leds_; i++) {
|
||||
colors_[i] = color;
|
||||
|
||||
@@ -18,13 +18,14 @@ struct StripColor {
|
||||
|
||||
class CircularStrip : public Led {
|
||||
public:
|
||||
CircularStrip(gpio_num_t gpio, uint8_t max_leds);
|
||||
CircularStrip(gpio_num_t gpio, uint16_t max_leds);
|
||||
virtual ~CircularStrip();
|
||||
|
||||
void OnStateChanged() override;
|
||||
void SetBrightness(uint8_t default_brightness, uint8_t low_brightness);
|
||||
void SetAllColor(StripColor color);
|
||||
void SetSingleColor(uint8_t index, StripColor color);
|
||||
void SetMultiColors(const std::vector<StripColor>& colors);
|
||||
void Blink(StripColor color, int interval_ms);
|
||||
void Breathe(StripColor low, StripColor high, int interval_ms);
|
||||
void Scroll(StripColor low, StripColor high, int length, int interval_ms);
|
||||
|
||||
Reference in New Issue
Block a user