From 85a1f00417adf49ea71f4a09d045d7e5cf110652 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Mon, 6 May 2019 00:40:43 +0900 Subject: [PATCH] Supports AutoConnectUpdate --- examples/Update/Update.ino | 15 +++++++++++++-- src/AutoConnectUpdate.cpp | 7 ++++++- src/AutoConnectUpdate.h | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/examples/Update/Update.ino b/examples/Update/Update.ino index bf579a8..e0dc158 100644 --- a/examples/Update/Update.ino +++ b/examples/Update/Update.ino @@ -35,8 +35,19 @@ void setup() { // Responder of root page handled directly from WebServer class. server.on("/", []() { - String content = "Place the root page with the sketch application. "; - content += AUTOCONNECT_LINK(COG_24); + String content = R"( + + + + + + +Place the root page with the sketch application.  +__AC_LINK__ + + + )"; + content.replace("__AC_LINK__", String(AUTOCONNECT_LINK(COG_24))); server.send(200, "text/html", content); }); diff --git a/src/AutoConnectUpdate.cpp b/src/AutoConnectUpdate.cpp index 914d48b..a4dbd0c 100644 --- a/src/AutoConnectUpdate.cpp +++ b/src/AutoConnectUpdate.cpp @@ -7,6 +7,7 @@ * @copyright MIT license. */ +#include #include "AutoConnectUpdate.h" #include "AutoConnectUpdatePage.h" #include "AutoConnectJsonDefs.h" @@ -106,6 +107,10 @@ void AutoConnectUpdate::attach(AutoConnect& portal) { _status = UPDATE_IDLE; +#ifdef ARDUINO_ARCH_ESP32 + Update.onProgress(std::bind(&AutoConnectUpdate::_inProgress, this, std::placeholders::_1, std::placeholders::_2)); +#endif + // Attach this to the AutoConnectUpdate portal._update.reset(this); AC_DBG("AutoConnectUpdate attached\n"); @@ -389,7 +394,7 @@ String AutoConnectUpdate::_onResult(AutoConnectAux& result, PageArgument& args) resColor = String(F("red")); break; default: - resForm = String(F("No available update.")); + resForm = String(F("
No available update.")); resColor = String(F("red")); break; } diff --git a/src/AutoConnectUpdate.h b/src/AutoConnectUpdate.h index 1acfe85..49427b6 100644 --- a/src/AutoConnectUpdate.h +++ b/src/AutoConnectUpdate.h @@ -115,11 +115,21 @@ class AutoConnectUpdate : public HTTPUpdateClass { String _onUpdate(AutoConnectAux& update, PageArgument& args); String _onResult(AutoConnectAux& result, PageArgument& args); size_t _insertCatalog(AutoConnectRadio& radio, JsonVariant & responseBody); +#ifdef ARDUINO_ARCH_ESP32 + void _inProgress(size_t amount, size_t size) { + _amount = amount; + _binSize = size; + AC_DBG_DUMB("."); + } +#endif std::unique_ptr _catalog; /**< A catalog page for internally generated update binaries */ std::unique_ptr _progress; /**< An update in-progress page */ std::unique_ptr _result; /**< A update result page */ + size_t _amount; /**< Received amound bytes */ + size_t _binSize; /**< Updater binary size */ + private: AC_UPDATESTATUS_t _status; String _binName; /**< .bin name to update */