Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -143,6 +148,7 @@ class UpdaterClass {
bool _verifyHeader(uint8_t data);
bool _verifyEnd();

bool _async;
uint8_t _error;
uint8_t *_buffer;
size_t _bufferLen;
Expand Down