forked from xiaozhi/xiaozhi-esp32
Add Backlight and PowerSaveTimer
This commit is contained in:
36
main/boards/common/backlight.h
Normal file
36
main/boards/common/backlight.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_timer.h>
|
||||
|
||||
|
||||
class Backlight {
|
||||
public:
|
||||
Backlight();
|
||||
~Backlight();
|
||||
|
||||
void RestoreBrightness();
|
||||
void SetBrightness(uint8_t brightness, bool permanent = false);
|
||||
inline uint8_t brightness() const { return brightness_; }
|
||||
|
||||
protected:
|
||||
void OnTransitionTimer();
|
||||
virtual void SetBrightnessImpl(uint8_t brightness) = 0;
|
||||
|
||||
esp_timer_handle_t transition_timer_ = nullptr;
|
||||
uint8_t brightness_ = 0;
|
||||
uint8_t target_brightness_ = 0;
|
||||
uint8_t step_ = 1;
|
||||
};
|
||||
|
||||
|
||||
class PwmBacklight : public Backlight {
|
||||
public:
|
||||
PwmBacklight(gpio_num_t pin, bool output_invert = false);
|
||||
~PwmBacklight();
|
||||
|
||||
void SetBrightnessImpl(uint8_t brightness) override;
|
||||
};
|
||||
Reference in New Issue
Block a user