reduce memory usage of ota

This commit is contained in:
Terrence
2025-01-13 05:00:14 +08:00
parent 7049522fc9
commit 58c1cd81c6
2 changed files with 19 additions and 15 deletions

View File

@@ -62,6 +62,8 @@ void Application::CheckNewVersion() {
vTaskDelay(pdMS_TO_TICKS(3000)); vTaskDelay(pdMS_TO_TICKS(3000));
} while (GetDeviceState() != kDeviceStateIdle); } while (GetDeviceState() != kDeviceStateIdle);
// Use main task to do the upgrade
Schedule([this, &board, display]() {
SetDeviceState(kDeviceStateUpgrading); SetDeviceState(kDeviceStateUpgrading);
display->SetIcon(FONT_AWESOME_DOWNLOAD); display->SetIcon(FONT_AWESOME_DOWNLOAD);
@@ -69,6 +71,7 @@ void Application::CheckNewVersion() {
// 预先关闭音频输出,避免升级过程有音频操作 // 预先关闭音频输出,避免升级过程有音频操作
board.GetAudioCodec()->EnableOutput(false); board.GetAudioCodec()->EnableOutput(false);
vTaskDelay(pdMS_TO_TICKS(1000));
ota_.StartUpgrade([display](int progress, size_t speed) { ota_.StartUpgrade([display](int progress, size_t speed) {
char buffer[64]; char buffer[64];
@@ -79,6 +82,7 @@ void Application::CheckNewVersion() {
// If upgrade success, the device will reboot and never reach here // If upgrade success, the device will reboot and never reach here
ESP_LOGI(TAG, "Firmware upgrade failed..."); ESP_LOGI(TAG, "Firmware upgrade failed...");
SetDeviceState(kDeviceStateIdle); SetDeviceState(kDeviceStateIdle);
});
} else { } else {
ota_.MarkCurrentVersionValid(); ota_.MarkCurrentVersionValid();
display->ShowNotification("版本 " + ota_.GetCurrentVersion()); display->ShowNotification("版本 " + ota_.GetCurrentVersion());

View File

@@ -165,7 +165,7 @@ void Ota::Upgrade(const std::string& firmware_url) {
return; return;
} }
std::vector<char> buffer(4096); std::vector<char> buffer(512);
size_t total_read = 0, recent_read = 0; size_t total_read = 0, recent_read = 0;
auto last_calc_time = esp_timer_get_time(); auto last_calc_time = esp_timer_get_time();
while (true) { while (true) {