Skip to content

Commit a5d76ed

Browse files
committed
Affiche la progression OTA GitHub sur l'ecran
1 parent a6a4867 commit a5d76ed

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

custom_components/soundpanel7/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"iot_class": "local_polling",
99
"issue_tracker": "https://github.com/jjtronics/SoundPanel7/issues",
1010
"requirements": [],
11-
"version": "0.2.13",
11+
"version": "0.2.14",
1212
"zeroconf": [
1313
{
1414
"type": "_soundpanel7._tcp.local."

include/AppConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#pragma once
33
#include <stdint.h>
44

5-
#define SOUNDPANEL7_VERSION "0.2.13"
5+
#define SOUNDPANEL7_VERSION "0.2.14"
66
#define SOUNDPANEL7_BUILD_DATE __DATE__ " " __TIME__
77

88
#ifndef SOUNDPANEL7_BUILD_ENV

src/ReleaseUpdateManager.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "DebugLog.h"
1313
#include "JsonHelpers.h"
1414
#include "NetManager.h"
15+
#include "ui/UiManager.h"
1516

1617
#define Serial0 DebugSerial0
1718

@@ -82,8 +83,9 @@ bool selectManifestOtaForCurrentProfile(const String& payload, String& otaUrl, S
8283
}
8384
}
8485

85-
bool ReleaseUpdateManager::begin(NetManager* net) {
86+
bool ReleaseUpdateManager::begin(NetManager* net, UiManager* ui) {
8687
_net = net;
88+
_ui = ui;
8789
clearResult();
8890
clearInstallState();
8991
_busy = false;
@@ -151,6 +153,8 @@ void ReleaseUpdateManager::clearInstallState() {
151153
_installError[0] = '\0';
152154
_installRebootPending = false;
153155
_installRebootAtMs = 0;
156+
_lastInstallUiProgressPct = 255;
157+
_lastInstallLoggedProgressPct = 255;
154158
}
155159

156160
void ReleaseUpdateManager::cleanupInstallTransport() {
@@ -182,6 +186,42 @@ void ReleaseUpdateManager::setInstallError(const String& error) {
182186
sp7json::safeCopy(_installError, sizeof(_installError), error);
183187
}
184188

189+
void ReleaseUpdateManager::updateInstallUi(bool force) {
190+
if (!_ui) return;
191+
192+
uint8_t uiPct = _installProgressPct;
193+
if (uiPct < 100) {
194+
uiPct = (uint8_t)((uiPct / 5U) * 5U);
195+
}
196+
197+
const bool progressChanged = (uiPct != _lastInstallUiProgressPct);
198+
if (!force && !progressChanged) return;
199+
_lastInstallUiProgressPct = uiPct;
200+
201+
const char* title = "Mise a jour en cours";
202+
const char* detail = "Preparation de la mise a jour GitHub...";
203+
bool success = false;
204+
205+
if (strcmp(_installStatus, "starting") == 0) {
206+
detail = "Preparation de la mise a jour GitHub...";
207+
} else if (strcmp(_installStatus, "downloading") == 0) {
208+
detail = "Telechargement du firmware depuis GitHub...";
209+
} else if (strcmp(_installStatus, "verifying") == 0) {
210+
detail = "Verification du firmware...";
211+
} else if (strcmp(_installStatus, "rebooting") == 0 || strcmp(_installStatus, "success") == 0) {
212+
title = "Mise a jour terminee";
213+
detail = "Verification terminee. Redemarrage en cours...";
214+
success = true;
215+
uiPct = 100;
216+
_lastInstallUiProgressPct = 100;
217+
} else if (strcmp(_installStatus, "failed") == 0) {
218+
_ui->hideOtaStatusScreen();
219+
return;
220+
}
221+
222+
_ui->showOtaStatusScreen(title, detail, uiPct, success);
223+
}
224+
185225
void ReleaseUpdateManager::finishInstall(bool ok, const String& error) {
186226
_installInProgress = false;
187227
_installFinished = true;
@@ -193,10 +233,14 @@ void ReleaseUpdateManager::finishInstall(bool ok, const String& error) {
193233
_installProgressPct = 100;
194234
_installRebootPending = true;
195235
_installRebootAtMs = millis();
236+
updateInstallUi(true);
196237
} else {
197238
setInstallStatus("failed");
198239
setInstallError(error);
199240
_installRebootPending = false;
241+
if (_ui) {
242+
_ui->hideOtaStatusScreen();
243+
}
200244
}
201245
}
202246

@@ -276,7 +320,10 @@ bool ReleaseUpdateManager::startInstall() {
276320
_installError[0] = '\0';
277321
_installRebootPending = false;
278322
_installRebootAtMs = 0;
323+
_lastInstallUiProgressPct = 255;
324+
_lastInstallLoggedProgressPct = 255;
279325
setInstallStatus("starting");
326+
updateInstallUi(true);
280327
return true;
281328
}
282329

@@ -291,6 +338,7 @@ void ReleaseUpdateManager::processInstall() {
291338

292339
if (!_installHttp) {
293340
setInstallStatus("downloading");
341+
updateInstallUi(true);
294342
WiFi.setSleep(false);
295343

296344
_installClient = new WiFiClientSecure();
@@ -355,6 +403,7 @@ void ReleaseUpdateManager::processInstall() {
355403
if (remaining == 0) {
356404
uint8_t digest[32] = {0};
357405
setInstallStatus("verifying");
406+
updateInstallUi(true);
358407
mbedtls_sha256_finish(&_installSha, digest);
359408
cleanupInstallTransport();
360409

@@ -417,6 +466,11 @@ void ReleaseUpdateManager::processInstall() {
417466

418467
_installWrittenBytes += (uint32_t)written;
419468
_installProgressPct = (uint8_t)(((uint64_t)_installWrittenBytes * 100ULL) / (uint64_t)_installTotalBytes);
469+
if (_installProgressPct != _lastInstallLoggedProgressPct) {
470+
_lastInstallLoggedProgressPct = _installProgressPct;
471+
Serial0.printf("[REL] Install progress: %u%%\n", (unsigned)_installProgressPct);
472+
}
473+
updateInstallUi();
420474
}
421475

422476
bool ReleaseUpdateManager::fetchManifest(String& payload) {

src/ReleaseUpdateManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include <mbedtls/sha256.h>
88

99
class NetManager;
10+
class UiManager;
1011

1112
class ReleaseUpdateManager {
1213
public:
13-
bool begin(NetManager* net);
14+
bool begin(NetManager* net, UiManager* ui);
1415
void loop();
1516

1617
bool checkNow();
@@ -89,16 +90,20 @@ class ReleaseUpdateManager {
8990
void finishInstall(bool ok, const String& error = "");
9091
void cleanupInstallTransport();
9192
void processInstall();
93+
void updateInstallUi(bool force = false);
9294

9395
static uint32_t currentUnixTimestamp();
9496
static int compareVersions(const char* a, const char* b);
9597
static bool readNextVersionNumber(const char*& cursor, uint32_t& value, bool& hasValue);
9698

9799
WiFiClientSecure* _installClient = nullptr;
98100
HTTPClient* _installHttp = nullptr;
101+
UiManager* _ui = nullptr;
99102
mbedtls_sha256_context _installSha = {};
100103
bool _installShaActive = false;
101104
uint8_t _installBuffer[kInstallChunkSize] = {};
102105
Preferences _prefs;
103106
bool _prefsReady = false;
107+
uint8_t _lastInstallUiProgressPct = 255;
108+
uint8_t _lastInstallLoggedProgressPct = 255;
104109
};

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void setup() {
203203

204204
g_net.begin(&g_settings, &g_store);
205205
g_ota.begin(&g_settings, &g_ui);
206-
g_releaseUpdate.begin(&g_net);
206+
g_releaseUpdate.begin(&g_net, &g_ui);
207207
g_mqtt.begin(&g_store, &g_settings);
208208
g_web.begin(&g_store, &g_settings, &g_net, g_board, &g_history, &g_ota, &g_releaseUpdate, &g_mqtt, &g_ui);
209209

0 commit comments

Comments
 (0)