Commit 61f71930 authored by ducalex's avatar ducalex Committed by Me No Dev

The progress callback is now correctly invoked with Update.write (#3024)

The progress callback was only invoked with Update.writeStream before
parent ec40c4c9
......@@ -189,6 +189,9 @@ bool UpdateClass::_writeBuffer(){
//this ensures that partially written firmware will not be bootable
_buffer[0] = 0xFF;
}
if (!_progress && _progress_callback) {
_progress_callback(0, _size);
}
if(!ESP.flashEraseSector((_partition->address + _progress)/SPI_FLASH_SEC_SIZE)){
_abort(UPDATE_ERROR_ERASE);
return false;
......@@ -204,6 +207,9 @@ bool UpdateClass::_writeBuffer(){
_md5.add(_buffer, _bufferLen);
_progress += _bufferLen;
_bufferLen = 0;
if (_progress_callback) {
_progress_callback(_progress, _size);
}
return true;
}
......@@ -319,9 +325,6 @@ size_t UpdateClass::writeStream(Stream &data) {
_reset();
return 0;
}
if (_progress_callback) {
_progress_callback(0, _size);
}
if(_ledPin != -1) {
pinMode(_ledPin, OUTPUT);
......@@ -352,12 +355,6 @@ size_t UpdateClass::writeStream(Stream &data) {
if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer())
return written;
written += toRead;
if(_progress_callback) {
_progress_callback(_progress, _size);
}
}
if(_progress_callback) {
_progress_callback(_size, _size);
}
return written;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment