From 575de96004ae3aa58230c79163ba246b4e62cd9b Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Fri, 17 Mar 2023 11:52:40 +1300 Subject: [PATCH] show OTA message --- include/ota.h | 6 +++--- src/main.cpp | 2 +- src/ota.cpp | 13 +++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/ota.h b/include/ota.h index b118699..0a1371b 100644 --- a/include/ota.h +++ b/include/ota.h @@ -1,13 +1,13 @@ #ifndef _OTA_H #define _OTA_H -#include "globals.h" - +#include +#include typedef void (*preUpdateCallback_t)(void); namespace OTA { - void setupOta(preUpdateCallback_t preUpdateCallback); + void setupOta(preUpdateCallback_t preUpdateCallback, setPriorityMessageCallback_t _setPriorityMessageCallback, clearPriorityMessageCallback_t _clearPriorityMessageCallback); void checkForUpdate(); extern TaskHandle_t otaTask; void otaLoop(void* pvParameters); diff --git a/src/main.cpp b/src/main.cpp index 86f6fe0..d784063 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -280,7 +280,7 @@ void setup() { housekeeping::cyclicTimer.attach(30, housekeeping::doHousekeeping); - OTA::setupOta(prepareOta); + OTA::setupOta(prepareOta, setPriorityMessage, clearPriorityMessage); attachInterrupt(BTN_1, buttonHandler, CHANGE); diff --git a/src/ota.cpp b/src/ota.cpp index 523ca98..ac2ff60 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -13,10 +13,14 @@ namespace OTA { Ticker cyclicTimer; preUpdateCallback_t preUpdateCallback; + setPriorityMessageCallback_t setPriorityMessageCallback; + clearPriorityMessageCallback_t clearPriorityMessageCallback; String forceUpdateURL; - void setupOta(preUpdateCallback_t _preUpdateCallback) { + void setupOta(preUpdateCallback_t _preUpdateCallback, setPriorityMessageCallback_t _setPriorityMessageCallback, clearPriorityMessageCallback_t _clearPriorityMessageCallback) { preUpdateCallback = _preUpdateCallback; + setPriorityMessageCallback = _setPriorityMessageCallback; + clearPriorityMessageCallback = _clearPriorityMessageCallback; #ifdef OTA_POLL cyclicTimer.attach(1060 * 60 * 24, checkForUpdate); #endif @@ -38,9 +42,12 @@ namespace OTA { if (shouldExecuteFirmwareUpdate) { ESP_LOGD(TAG, "Firmware update available"); if (preUpdateCallback) preUpdateCallback(); + setPriorityMessageCallback("Starting OTA update"); mqtt::publishStatusMsg("Starting OTA update"); esp32FOTA.execOTA(); + setPriorityMessageCallback("Rebooting"); delay(1000); + clearPriorityMessageCallback(); esp_restart(); } else { ESP_LOGD(TAG, "No firmware update available"); @@ -59,11 +66,13 @@ namespace OTA { esp32FOTA esp32FOTA(OTA_APP, APP_VERSION, false, false); esp32FOTA.setCertFileSystem(&LittleFS); mqtt::publishStatusMsg("Starting forced OTA update"); + setPriorityMessageCallback("Starting OTA update"); esp32FOTA.forceUpdate(forceUpdateURL, false); forceUpdateURL = ""; ESP_LOGD(TAG, "Forced OTA done"); - forceUpdateURL = ""; + setPriorityMessageCallback("Rebooting"); delay(1000); + clearPriorityMessageCallback(); esp_restart(); }