Skip to content

Commit 2f933e2

Browse files
me-no-devigrr
authored andcommitted
Make Updater be able to run inside async callbacks (#2096)
1 parent dd81336 commit 2f933e2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

cores/esp8266/Updater.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ extern "C" {
1414
extern "C" uint32_t _SPIFFS_start;
1515

1616
UpdaterClass::UpdaterClass()
17-
: _error(0)
17+
: _async(false)
18+
, _error(0)
1819
, _buffer(0)
1920
, _bufferLen(0)
2021
, _size(0)
@@ -202,13 +203,13 @@ bool UpdaterClass::end(bool evenIfRemaining){
202203

203204
bool UpdaterClass::_writeBuffer(){
204205

205-
yield();
206+
if(!_async) yield();
206207
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
207-
yield();
208+
if(!_async) yield();
208209
if (result) {
209210
result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
210211
}
211-
yield();
212+
if(!_async) yield();
212213

213214
if (!result) {
214215
_error = UPDATE_ERROR_WRITE;
@@ -240,7 +241,7 @@ size_t UpdaterClass::write(uint8_t *data, size_t len) {
240241
return len - left;
241242
}
242243
left -= toBuff;
243-
yield();
244+
if(!_async) yield();
244245
}
245246
//lets see whats left
246247
memcpy(_buffer + _bufferLen, data + (len - left), left);

cores/esp8266/Updater.h

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class UpdaterClass {
3737
*/
3838
bool begin(size_t size, int command = U_FLASH);
3939

40+
/*
41+
Run Updater from asynchronous callbacs
42+
*/
43+
void runAsync(bool async){ _async = async; }
44+
4045
/*
4146
Writes a buffer to the flash and increments the address
4247
Returns the amount written
@@ -143,6 +148,7 @@ class UpdaterClass {
143148
bool _verifyHeader(uint8_t data);
144149
bool _verifyEnd();
145150

151+
bool _async;
146152
uint8_t _error;
147153
uint8_t *_buffer;
148154
size_t _bufferLen;

0 commit comments

Comments
 (0)