File tree 1 file changed +11
-9
lines changed
1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -433,7 +433,7 @@ bool UpdaterClass::_verifyEnd() {
433
433
return false ;
434
434
}
435
435
436
- size_t UpdaterClass::writeStream (Stream &data) {
436
+ size_t UpdaterClass::writeStream (Stream &data, uint16_t streamTimeout ) {
437
437
size_t written = 0 ;
438
438
size_t toRead = 0 ;
439
439
if (hasError () || !isRunning ())
@@ -446,6 +446,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
446
446
_reset ();
447
447
return 0 ;
448
448
}
449
+ unsigned long timeout = millis ();
449
450
if (_progress_callback) {
450
451
_progress_callback (0 , _size);
451
452
}
@@ -463,14 +464,15 @@ size_t UpdaterClass::writeStream(Stream &data) {
463
464
}
464
465
toRead = data.readBytes (_buffer + _bufferLen, bytesToRead);
465
466
if (toRead == 0 ) { // Timeout
466
- delay (100 );
467
- toRead = data.readBytes (_buffer + _bufferLen, bytesToRead);
468
- if (toRead == 0 ) { // Timeout
469
- _currentAddress = (_startAddress + _size);
470
- _setError (UPDATE_ERROR_STREAM);
471
- _reset ();
472
- return written;
473
- }
467
+ if (millis () - timeout > streamTimeout) {
468
+ _currentAddress = (_startAddress + _size);
469
+ _setError (UPDATE_ERROR_STREAM);
470
+ _reset ();
471
+ return written;
472
+ }
473
+ delay (100 );
474
+ } else {
475
+ timeout = millis ();
474
476
}
475
477
if (_ledPin != -1 ) {
476
478
digitalWrite (_ledPin, !_ledOn); // Switch LED off
You can’t perform that action at this time.
0 commit comments