Skip to content

Commit 61f7193

Browse files
ducalexme-no-dev
authored andcommitted
The progress callback is now correctly invoked with Update.write (#3024)
The progress callback was only invoked with Update.writeStream before
1 parent ec40c4c commit 61f7193

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libraries/Update/src/Updater.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ bool UpdateClass::_writeBuffer(){
189189
//this ensures that partially written firmware will not be bootable
190190
_buffer[0] = 0xFF;
191191
}
192+
if (!_progress && _progress_callback) {
193+
_progress_callback(0, _size);
194+
}
192195
if(!ESP.flashEraseSector((_partition->address + _progress)/SPI_FLASH_SEC_SIZE)){
193196
_abort(UPDATE_ERROR_ERASE);
194197
return false;
@@ -204,6 +207,9 @@ bool UpdateClass::_writeBuffer(){
204207
_md5.add(_buffer, _bufferLen);
205208
_progress += _bufferLen;
206209
_bufferLen = 0;
210+
if (_progress_callback) {
211+
_progress_callback(_progress, _size);
212+
}
207213
return true;
208214
}
209215

@@ -319,9 +325,6 @@ size_t UpdateClass::writeStream(Stream &data) {
319325
_reset();
320326
return 0;
321327
}
322-
if (_progress_callback) {
323-
_progress_callback(0, _size);
324-
}
325328

326329
if(_ledPin != -1) {
327330
pinMode(_ledPin, OUTPUT);
@@ -352,12 +355,6 @@ size_t UpdateClass::writeStream(Stream &data) {
352355
if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer())
353356
return written;
354357
written += toRead;
355-
if(_progress_callback) {
356-
_progress_callback(_progress, _size);
357-
}
358-
}
359-
if(_progress_callback) {
360-
_progress_callback(_size, _size);
361358
}
362359
return written;
363360
}

0 commit comments

Comments
 (0)