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
156160void 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+
185225void 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
422476bool ReleaseUpdateManager::fetchManifest (String& payload) {
0 commit comments