mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-06 07:16:32 +02:00
Add progress callback to Update::writeStream(). (#948)
This commit is contained in:
committed by
Me No Dev
parent
78acedd2cf
commit
2633fc3c74
@ -71,9 +71,15 @@ UpdateClass::UpdateClass()
|
||||
, _progress(0)
|
||||
, _command(U_FLASH)
|
||||
, _partition(NULL)
|
||||
, _progress_callback(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
UpdateClass& UpdateClass::onProgress(THandlerFunction_Progress fn) {
|
||||
_progress_callback = fn;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void UpdateClass::_reset() {
|
||||
if (_buffer)
|
||||
delete[] _buffer;
|
||||
@ -306,7 +312,9 @@ size_t UpdateClass::writeStream(Stream &data) {
|
||||
_reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_progress_callback) {
|
||||
_progress_callback(0, _size);
|
||||
}
|
||||
while(remaining()) {
|
||||
toRead = data.readBytes(_buffer + _bufferLen, (SPI_FLASH_SEC_SIZE - _bufferLen));
|
||||
if(toRead == 0) { //Timeout
|
||||
@ -321,6 +329,12 @@ 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user