forked from xiaozhi/xiaozhi-esp32
添加普通LED支持,支持不同状态亮度设置和呼吸灯效果 (#283)
This commit is contained in:
45
main/led/gpio_led.h
Normal file
45
main/led/gpio_led.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _GPIO_LED_H_
|
||||
#define _GPIO_LED_H_
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include "led.h"
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <esp_timer.h>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
class GpioLed : public Led {
|
||||
public:
|
||||
GpioLed(gpio_num_t gpio, int output_invert=0);
|
||||
virtual ~GpioLed();
|
||||
|
||||
void OnStateChanged() override;
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
TaskHandle_t blink_task_ = nullptr;
|
||||
ledc_channel_config_t ledc_channel_ = {0};
|
||||
bool ledc_initialized_ = false;
|
||||
uint32_t duty_ = 0;
|
||||
int blink_counter_ = 0;
|
||||
int blink_interval_ms_ = 0;
|
||||
esp_timer_handle_t blink_timer_ = nullptr;
|
||||
bool fade_up_ = true;
|
||||
|
||||
void StartBlinkTask(int times, int interval_ms);
|
||||
void OnBlinkTimer();
|
||||
|
||||
void BlinkOnce();
|
||||
void Blink(int times, int interval_ms);
|
||||
void StartContinuousBlink(int interval_ms);
|
||||
void TurnOn();
|
||||
void TurnOff();
|
||||
void SetBrightness(uint8_t brightness);
|
||||
void StartFadeTask();
|
||||
void OnFadeEnd();
|
||||
static bool FadeCallback(const ledc_cb_param_t *param, void *user_arg);
|
||||
};
|
||||
|
||||
#endif // _GPIO_LED_H_
|
||||
Reference in New Issue
Block a user