Adds AutoConnectOTA ticker

pull/197/head
Hieromon Ikasamo 5 years ago
parent dd194db876
commit 0b46a0e041
  1. 19
      src/AutoConnectOTA.cpp

@ -8,9 +8,14 @@
*/ */
#include <functional> #include <functional>
#if defined(ARDUINO_ARCH_ESP8266)
#include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <Update.h>
#endif
#include <StreamString.h>
#include "AutoConnectOTA.h" #include "AutoConnectOTA.h"
#include "AutoConnectOTAPage.h" #include "AutoConnectOTAPage.h"
#include <StreamString.h>
/** /**
* A destructor. Release the OTA operation pages. * A destructor. Release the OTA operation pages.
@ -110,10 +115,14 @@ void AutoConnectOTA::_buildAux(AutoConnectAux* aux, const AutoConnectOTA::ACPage
bool AutoConnectOTA::_open(const char* filename, const char* mode) { bool AutoConnectOTA::_open(const char* filename, const char* mode) {
AC_UNUSED(mode); AC_UNUSED(mode);
_binName = String(strchr(filename, '/') + sizeof(char)); _binName = String(strchr(filename, '/') + sizeof(char));
#ifdef ARDUINO_ARCH_ESP8266
WiFiUDP::stopAll(); WiFiUDP::stopAll();
#endif
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
// It only supports FLASH as a sketch area for updating. // It only supports FLASH as a sketch area for updating.
if (Update.begin(maxSketchSpace, U_FLASH, _tickerPort, _tickerOn)) { if (Update.begin(maxSketchSpace, U_FLASH)) {
if (_tickerPort != -1)
pinMode(static_cast<uint8_t>(_tickerPort), OUTPUT);
_status = OTA_START; _status = OTA_START;
AC_DBG("%s updating start\n", filename); AC_DBG("%s updating start\n", filename);
return true; return true;
@ -131,6 +140,8 @@ bool AutoConnectOTA::_open(const char* filename, const char* mode) {
*/ */
size_t AutoConnectOTA::_write(const uint8_t *buf, const size_t size) { size_t AutoConnectOTA::_write(const uint8_t *buf, const size_t size) {
size_t wsz = 0; size_t wsz = 0;
if (_tickerPort != -1)
digitalWrite(_tickerPort, digitalRead(_tickerPort) ^ 0x01);
if (!_err.length()) { if (!_err.length()) {
_status = OTA_PROGRESS; _status = OTA_PROGRESS;
wsz = Update.write(const_cast<uint8_t*>(buf), size); wsz = Update.write(const_cast<uint8_t*>(buf), size);
@ -162,6 +173,8 @@ void AutoConnectOTA::_close(const HTTPUploadStatus status) {
AC_DBG_DUMB(" aborted\n"); AC_DBG_DUMB(" aborted\n");
} }
} }
if (_tickerPort != -1)
digitalWrite(_tickerPort, !_tickerOn);
} }
/** /**
@ -169,7 +182,7 @@ void AutoConnectOTA::_close(const HTTPUploadStatus status) {
* Reflect the flash result of Update class to the page. * Reflect the flash result of Update class to the page.
* @param result Upload post-process page * @param result Upload post-process page
* @param args Unused * @param args Unused
* @return none * @return Empty string
*/ */
String AutoConnectOTA::_updated(AutoConnectAux& result, PageArgument& args) { String AutoConnectOTA::_updated(AutoConnectAux& result, PageArgument& args) {
AC_UNUSED(args); AC_UNUSED(args);

Loading…
Cancel
Save