forked from xiaozhi/xiaozhi-esp32
fix audio pm (#1004)
This commit is contained in:
@@ -62,12 +62,25 @@ void PowerSaveTimer::PowerSaveCheck() {
|
||||
ticks_++;
|
||||
if (seconds_to_sleep_ != -1 && ticks_ >= seconds_to_sleep_) {
|
||||
if (!in_sleep_mode_) {
|
||||
ESP_LOGI(TAG, "Enabling power save mode");
|
||||
in_sleep_mode_ = true;
|
||||
if (on_enter_sleep_mode_) {
|
||||
on_enter_sleep_mode_();
|
||||
}
|
||||
|
||||
if (cpu_max_freq_ != -1) {
|
||||
// Disable wake word detection
|
||||
auto& audio_service = app.GetAudioService();
|
||||
is_wake_word_running_ = audio_service.IsWakeWordRunning();
|
||||
if (is_wake_word_running_) {
|
||||
audio_service.EnableWakeWordDetection(false);
|
||||
}
|
||||
// Disable audio input
|
||||
auto codec = Board::GetInstance().GetAudioCodec();
|
||||
if (codec) {
|
||||
codec->EnableInput(false);
|
||||
}
|
||||
|
||||
esp_pm_config_t pm_config = {
|
||||
.max_freq_mhz = cpu_max_freq_,
|
||||
.min_freq_mhz = 40,
|
||||
@@ -85,6 +98,7 @@ void PowerSaveTimer::PowerSaveCheck() {
|
||||
void PowerSaveTimer::WakeUp() {
|
||||
ticks_ = 0;
|
||||
if (in_sleep_mode_) {
|
||||
ESP_LOGI(TAG, "Exiting power save mode");
|
||||
in_sleep_mode_ = false;
|
||||
|
||||
if (cpu_max_freq_ != -1) {
|
||||
@@ -94,6 +108,13 @@ void PowerSaveTimer::WakeUp() {
|
||||
.light_sleep_enable = false,
|
||||
};
|
||||
esp_pm_configure(&pm_config);
|
||||
|
||||
// Enable wake word detection
|
||||
auto& app = Application::GetInstance();
|
||||
auto& audio_service = app.GetAudioService();
|
||||
if (is_wake_word_running_) {
|
||||
audio_service.EnableWakeWordDetection(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (on_exit_sleep_mode_) {
|
||||
|
||||
@@ -22,6 +22,7 @@ private:
|
||||
esp_timer_handle_t power_save_timer_ = nullptr;
|
||||
bool enabled_ = false;
|
||||
bool in_sleep_mode_ = false;
|
||||
bool is_wake_word_running_ = false;
|
||||
int ticks_ = 0;
|
||||
int cpu_max_freq_;
|
||||
int seconds_to_sleep_;
|
||||
|
||||
@@ -70,6 +70,12 @@ void SleepTimer::CheckTimer() {
|
||||
if (on_enter_light_sleep_mode_) {
|
||||
on_enter_light_sleep_mode_();
|
||||
}
|
||||
|
||||
auto& audio_service = app.GetAudioService();
|
||||
bool is_wake_word_running = audio_service.IsWakeWordRunning();
|
||||
if (is_wake_word_running) {
|
||||
audio_service.EnableWakeWordDetection(false);
|
||||
}
|
||||
|
||||
app.Schedule([this, &app]() {
|
||||
while (in_light_sleep_mode_) {
|
||||
@@ -86,12 +92,17 @@ void SleepTimer::CheckTimer() {
|
||||
lvgl_port_resume();
|
||||
|
||||
auto wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||
ESP_LOGI(TAG, "Wake up from light sleep, wakeup_reason: %d", wakeup_reason);
|
||||
if (wakeup_reason != ESP_SLEEP_WAKEUP_TIMER) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
WakeUp();
|
||||
});
|
||||
|
||||
if (is_wake_word_running) {
|
||||
audio_service.EnableWakeWordDetection(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (seconds_to_deep_sleep_ != -1 && ticks_ >= seconds_to_deep_sleep_) {
|
||||
|
||||
Reference in New Issue
Block a user