Skip to content

Commit 7304f9b

Browse files
author
adrionics
authored
Update Updater.cpp
1 parent 0328fde commit 7304f9b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/esp8266/Updater.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "eboot_command.h"
44
#include <interrupts.h>
55
#include <esp8266_peri.h>
6+
#include <PolledTimeout.h>
67

78
//#define DEBUG_UPDATER Serial
89

@@ -446,7 +447,7 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) {
446447
_reset();
447448
return 0;
448449
}
449-
unsigned long timeout = millis();
450+
esp8266::polledTimeout::oneShotMs timeOut(streamTimeout);
450451
if (_progress_callback) {
451452
_progress_callback(0, _size);
452453
}
@@ -464,15 +465,15 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) {
464465
}
465466
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
466467
if(toRead == 0) { //Timeout
467-
if (millis() - timeout > streamTimeout) {
468+
if (timeOut) {
468469
_currentAddress = (_startAddress + _size);
469470
_setError(UPDATE_ERROR_STREAM);
470471
_reset();
471472
return written;
472473
}
473474
delay(100);
474475
} else {
475-
timeout = millis();
476+
timeOut.reset();
476477
}
477478
if(_ledPin != -1) {
478479
digitalWrite(_ledPin, !_ledOn); // Switch LED off

0 commit comments

Comments
 (0)