forked from xiaozhi/xiaozhi-esp32
v1.8.0: Audio 代码重构与低功耗优化 (#943)
* Reconstruct Audio Code * Remove old IoT implementation * Add MQTT-UDP documentation * OTA升级失败时,可以继续使用
This commit is contained in:
32
main/boards/common/sleep_timer.h
Normal file
32
main/boards/common/sleep_timer.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <esp_timer.h>
|
||||
#include <esp_pm.h>
|
||||
|
||||
class SleepTimer {
|
||||
public:
|
||||
SleepTimer(int seconds_to_light_sleep = 20, int seconds_to_deep_sleep = -1);
|
||||
~SleepTimer();
|
||||
|
||||
void SetEnabled(bool enabled);
|
||||
void OnEnterLightSleepMode(std::function<void()> callback);
|
||||
void OnExitLightSleepMode(std::function<void()> callback);
|
||||
void OnEnterDeepSleepMode(std::function<void()> callback);
|
||||
void WakeUp();
|
||||
|
||||
private:
|
||||
void CheckTimer();
|
||||
|
||||
esp_timer_handle_t sleep_timer_ = nullptr;
|
||||
bool enabled_ = false;
|
||||
int ticks_ = 0;
|
||||
int seconds_to_light_sleep_;
|
||||
int seconds_to_deep_sleep_;
|
||||
bool in_light_sleep_mode_ = false;
|
||||
|
||||
std::function<void()> on_enter_light_sleep_mode_;
|
||||
std::function<void()> on_exit_light_sleep_mode_;
|
||||
std::function<void()> on_enter_deep_sleep_mode_;
|
||||
};
|
||||
Reference in New Issue
Block a user