mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Make Updater be able to run inside async callbacks (#2096)
This commit is contained in:
parent
dd81336b79
commit
2f933e20fa
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user