forked from xiaozhi/xiaozhi-esp32
feat: add led strip class
This commit is contained in:
@@ -6,9 +6,6 @@
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#define BLINK_INFINITE -1
|
||||
#define BLINK_TASK_STOPPED_BIT BIT0
|
||||
#define BLINK_TASK_RUNNING_BIT BIT1
|
||||
|
||||
#define DEFAULT_BRIGHTNESS 4
|
||||
#define HIGH_BRIGHTNESS 16
|
||||
@@ -16,12 +13,12 @@
|
||||
|
||||
class Led {
|
||||
public:
|
||||
Led(gpio_num_t gpio);
|
||||
Led(gpio_num_t gpio, uint8_t max_leds);
|
||||
~Led();
|
||||
|
||||
void BlinkOnce();
|
||||
void Blink(int times, int interval_ms);
|
||||
void StartContinuousBlink(int interval_ms);
|
||||
led_strip_handle_t led_strip() { return led_strip_; }
|
||||
uint8_t max_leds() { return max_leds_; }
|
||||
|
||||
void TurnOn();
|
||||
void TurnOff();
|
||||
void SetColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
@@ -30,18 +27,12 @@ public:
|
||||
void SetRed(uint8_t brightness = DEFAULT_BRIGHTNESS) { SetColor(brightness, 0, 0); }
|
||||
void SetGreen(uint8_t brightness = DEFAULT_BRIGHTNESS) { SetColor(0, brightness, 0); }
|
||||
void SetBlue(uint8_t brightness = DEFAULT_BRIGHTNESS) { SetColor(0, 0, brightness); }
|
||||
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
TaskHandle_t blink_task_ = nullptr;
|
||||
uint8_t max_leds_ = -1;
|
||||
led_strip_handle_t led_strip_ = nullptr;
|
||||
uint8_t r_ = 0, g_ = 0, b_ = 0;
|
||||
int blink_counter_ = 0;
|
||||
int blink_interval_ms_ = 0;
|
||||
esp_timer_handle_t blink_timer_ = nullptr;
|
||||
|
||||
void StartBlinkTask(int times, int interval_ms);
|
||||
void OnBlinkTimer();
|
||||
};
|
||||
|
||||
#endif // _LED_H_
|
||||
|
||||
Reference in New Issue
Block a user