Files
xiaozhi-esp32/main/boards/common/led.h

39 lines
1.1 KiB
C
Raw Normal View History

2024-11-06 06:18:56 +08:00
#ifndef _LED_H_
#define _LED_H_
2024-10-29 00:22:29 +08:00
#include <led_strip.h>
2024-11-29 11:06:05 +08:00
#include <esp_timer.h>
2024-10-29 00:22:29 +08:00
#include <atomic>
2024-11-29 11:06:05 +08:00
#include <mutex>
2024-10-29 00:22:29 +08:00
2024-11-18 06:17:39 +08:00
#define DEFAULT_BRIGHTNESS 4
#define HIGH_BRIGHTNESS 16
#define LOW_BRIGHTNESS 2
2024-10-29 00:22:29 +08:00
2024-11-06 06:18:56 +08:00
class Led {
2024-10-29 00:22:29 +08:00
public:
2024-12-17 14:03:45 +08:00
Led(gpio_num_t gpio, uint8_t max_leds);
2024-11-06 06:18:56 +08:00
~Led();
2024-10-29 00:22:29 +08:00
2024-12-17 14:03:45 +08:00
led_strip_handle_t led_strip() { return led_strip_; }
uint8_t max_leds() { return max_leds_; }
2024-10-29 00:22:29 +08:00
void TurnOn();
void TurnOff();
void SetColor(uint8_t r, uint8_t g, uint8_t b);
void SetWhite(uint8_t brightness = DEFAULT_BRIGHTNESS) { SetColor(brightness, brightness, brightness); }
void SetGrey(uint8_t brightness = DEFAULT_BRIGHTNESS) { SetColor(brightness, brightness, brightness); }
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); }
2024-12-17 14:03:45 +08:00
2024-10-29 00:22:29 +08:00
private:
2024-11-29 11:06:05 +08:00
std::mutex mutex_;
2024-12-17 14:03:45 +08:00
uint8_t max_leds_ = -1;
2024-10-29 00:22:29 +08:00
led_strip_handle_t led_strip_ = nullptr;
uint8_t r_ = 0, g_ = 0, b_ = 0;
};
2024-11-06 06:18:56 +08:00
#endif // _LED_H_