From ba2443275614b93d1f9c825bfbd86388e54a8775 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Sun, 5 Jun 2016 12:42:59 +0300 Subject: [PATCH] Make Updater be able to run inside async callbacks --- cores/esp8266/Updater.cpp | 11 ++++++----- cores/esp8266/Updater.h | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 131d29ab2f..4764742463 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -14,7 +14,8 @@ extern "C" { extern "C" uint32_t _SPIFFS_start; UpdaterClass::UpdaterClass() -: _error(0) +: _async(false) +, _error(0) , _buffer(0) , _bufferLen(0) , _size(0) @@ -202,13 +203,13 @@ bool UpdaterClass::end(bool evenIfRemaining){ bool UpdaterClass::_writeBuffer(){ - yield(); + if(!_async) yield(); bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE); - yield(); + if(!_async) yield(); if (result) { result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen); } - yield(); + if(!_async) yield(); if (!result) { _error = UPDATE_ERROR_WRITE; @@ -240,7 +241,7 @@ size_t UpdaterClass::write(uint8_t *data, size_t len) { return len - left; } left -= toBuff; - yield(); + if(!_async) yield(); } //lets see whats left memcpy(_buffer + _bufferLen, data + (len - left), left); diff --git a/cores/esp8266/Updater.h b/cores/esp8266/Updater.h index 49a1c4504e..dae62795f6 100644 --- a/cores/esp8266/Updater.h +++ b/cores/esp8266/Updater.h @@ -37,6 +37,11 @@ class UpdaterClass { */ bool begin(size_t size, int command = U_FLASH); + /* + Run Updater from asynchronous callbacs + */ + void runAsync(bool async){ _async = async; } + /* Writes a buffer to the flash and increments the address Returns the amount written @@ -143,6 +148,7 @@ class UpdaterClass { bool _verifyHeader(uint8_t data); bool _verifyEnd(); + bool _async; uint8_t _error; uint8_t *_buffer; size_t _bufferLen;