Optimize sleepdelay

Optimize sleepdelay (#10379)
This commit is contained in:
Theo Arends 2021-01-03 16:30:45 +01:00
parent c33d5efd72
commit f9403c8489
1 changed files with 12 additions and 6 deletions

View File

@ -367,13 +367,19 @@ void BacklogLoop(void) {
void SleepDelay(uint32_t mseconds) {
if (mseconds) {
for (uint32_t wait = 0; wait < mseconds; wait++) {
// ESP8266 does an optimistic_yield(1000) in Serial.available()
// ESP32 does not so needs delay here
#ifdef ESP32
delay(1);
uint32_t wait = millis() + mseconds;
while (!TimeReached(wait)) {
#ifdef ESP8266
if ((wait - millis()) > 10) { // ESP8266 does an optimistic_yield(10000) in Serial.available()
#endif
if (Serial.available()) { break; } // We need to service serial buffer ASAP as otherwise we get uart buffer overrun
if (Serial.available()) { return; } // We need to service serial buffer ASAP as otherwise we get uart buffer overrun
#ifdef ESP8266
} else {
#endif
delay(1);
#ifdef ESP8266
}
#endif // ESP8266
}
} else {
delay(0);