36 lines
940 B
C++
36 lines
940 B
C++
#pragma once
|
|
|
|
#include "led.h"
|
|
#include <driver/gpio.h>
|
|
#include <led_strip.h>
|
|
#include <esp_timer.h>
|
|
#include <mutex>
|
|
|
|
// WS2812 RGB LED — aligned with xiaozhi-server SingleLed (RMT driver)
|
|
class SingleLed : public Led {
|
|
public:
|
|
SingleLed(gpio_num_t gpio);
|
|
~SingleLed();
|
|
|
|
void SetState(LedState state) override;
|
|
|
|
private:
|
|
void SetColor(uint8_t r, uint8_t g, uint8_t b);
|
|
void TurnOn();
|
|
void TurnOff();
|
|
void StartContinuousBlink(int interval_ms);
|
|
void StartBreathing(int period_ms);
|
|
void OnBlinkTimer();
|
|
void OnBreathingTimer();
|
|
|
|
std::mutex mutex_;
|
|
led_strip_handle_t led_strip_ = nullptr;
|
|
esp_timer_handle_t blink_timer_ = nullptr;
|
|
esp_timer_handle_t breath_timer_ = nullptr;
|
|
LedState current_state_ = LedState::kOff;
|
|
uint8_t r_ = 0, g_ = 0, b_ = 0; // peak color for steady/blink/breath
|
|
int blink_counter_ = 0;
|
|
int breath_phase_ = 0;
|
|
int breath_steps_ = 0;
|
|
};
|