set power safe mode

This commit is contained in:
Terrence
2024-11-15 23:07:20 +08:00
parent 58de3852c5
commit 15891f5840
11 changed files with 20 additions and 6 deletions

View File

@@ -4,7 +4,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
set(PROJECT_VER "0.8.1")
set(PROJECT_VER "0.8.2")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(xiaozhi)

View File

@@ -275,17 +275,19 @@ void Application::Start() {
audio_decode_queue_.emplace_back(std::move(data));
cv_.notify_all();
});
protocol_->OnAudioChannelOpened([this, codec]() {
protocol_->OnAudioChannelOpened([this, codec, &board]() {
if (protocol_->GetServerSampleRate() != codec->output_sample_rate()) {
ESP_LOGW(TAG, "服务器的音频采样率 %d 与设备输出的采样率 %d 不一致,重采样后可能会失真",
protocol_->GetServerSampleRate(), codec->output_sample_rate());
}
SetDecodeSampleRate(protocol_->GetServerSampleRate());
board.SetPowerSaveMode(false);
});
protocol_->OnAudioChannelClosed([this]() {
protocol_->OnAudioChannelClosed([this, &board]() {
Schedule([this]() {
SetChatState(kChatStateIdle);
});
board.SetPowerSaveMode(true);
});
protocol_->OnIncomingJson([this](const cJSON* root) {
// Parse JSON data

View File

@@ -43,6 +43,7 @@ public:
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) = 0;
virtual bool GetBatteryLevel(int &level, bool& charging);
virtual std::string GetJson();
virtual void SetPowerSaveMode(bool enabled) = 0;
};
#define DECLARE_BOARD(BOARD_CLASS_NAME) \

View File

@@ -114,3 +114,7 @@ std::string Ml307Board::GetBoardJson() {
board_json += "\"iccid\":\"" + modem_.GetIccid() + "\"}";
return board_json;
}
void Ml307Board::SetPowerSaveMode(bool enabled) {
// TODO: Implement power save mode for ML307
}

View File

@@ -20,6 +20,7 @@ public:
virtual Mqtt* CreateMqtt() override;
virtual Udp* CreateUdp() override;
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
virtual void SetPowerSaveMode(bool enabled) override;
};
#endif // ML307_BOARD_H

View File

@@ -114,3 +114,8 @@ std::string WifiBoard::GetBoardJson() {
board_json += "\"mac\":\"" + SystemInfo::GetMacAddress() + "\"}";
return board_json;
}
void WifiBoard::SetPowerSaveMode(bool enabled) {
auto& wifi_station = WifiStation::GetInstance();
wifi_station.SetPowerSaveMode(enabled);
}

View File

@@ -17,6 +17,7 @@ public:
virtual Mqtt* CreateMqtt() override;
virtual Udp* CreateUdp() override;
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
virtual void SetPowerSaveMode(bool enabled) override;
};
#endif // WIFI_BOARD_H

View File

@@ -1,6 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
78/esp-wifi-connect: "~1.3.0"
78/esp-wifi-connect: "~1.4.0"
78/esp-opus-encoder: "~1.1.0"
78/esp-ml307: "~1.6.0"
espressif/led_strip: "^2.4.1"

View File

@@ -169,7 +169,6 @@ void Ota::Upgrade(const std::string& firmware_url) {
size_t total_read = 0, recent_read = 0;
auto last_calc_time = esp_timer_get_time();
while (true) {
taskYIELD(); // Avoid watchdog timeout
int ret = http->Read(buffer.data(), buffer.size());
if (ret < 0) {
ESP_LOGE(TAG, "Failed to read HTTP data: %s", esp_err_to_name(ret));

View File

@@ -14,6 +14,7 @@ CONFIG_USE_WAKENET=y
CONFIG_SR_WN_WN9_NIHAOXIAOZHI_TTS=y
CONFIG_USE_MULTINET=n
ESP_TASK_WDT_TIMEOUT_S=10
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y

View File

@@ -64,7 +64,7 @@ def get_board_name(folder):
return "bread-compact-wifi"
elif "KevinBox1" in basename:
return "kevin-box-1"
if basename.startswith("v0.7"):
if basename.startswith("v0.7") or basename.startswith("v0.8"):
return basename.split("_")[1]
raise Exception(f"Unknown board name: {basename}")