Allow cancellation of download, dont block the device

This commit is contained in:
jpirnay
2026-04-21 14:26:21 +02:00
parent 9b27564931
commit d4c475470b
3 changed files with 143 additions and 61 deletions
+13
View File
@@ -3,6 +3,8 @@
#include <functional>
#include <string>
#include "esp_https_ota.h"
class OtaUpdater {
bool updateAvailable = false;
std::string latestVersion;
@@ -11,6 +13,8 @@ class OtaUpdater {
size_t processedSize = 0;
size_t totalSize = 0;
bool render = false;
esp_https_ota_handle_t otaHandle = nullptr;
bool cancelRequested = false;
public:
enum OtaUpdaterError {
@@ -21,6 +25,8 @@ class OtaUpdater {
UPDATE_OLDER_ERROR,
INTERNAL_UPDATE_ERROR,
OOM_ERROR,
UPDATE_CANCELLED,
UPDATE_IN_PROGRESS,
};
size_t getOtaSize() const { return otaSize; }
@@ -30,10 +36,17 @@ class OtaUpdater {
size_t getTotalSize() const { return totalSize; }
bool getRender() const { return render; }
void clearRender() { render = false; }
bool isUpdateInProgress() const { return otaHandle != nullptr; }
OtaUpdater() = default;
bool isUpdateNewer() const;
const std::string& getLatestVersion() const;
OtaUpdaterError checkForUpdate();
OtaUpdaterError beginInstallUpdate();
OtaUpdaterError performInstallUpdateStep();
void cancelUpdate();
void cleanupUpdate();
OtaUpdaterError installUpdate();
};