From 043095b6052950907611738a15492f38643dfb80 Mon Sep 17 00:00:00 2001 From: hcoohb Date: Tue, 2 Feb 2021 00:59:27 +1000 Subject: [PATCH] fix esp8266 remote_transmitter using incorrect timings (#1465) * replace delay by delayMicroseconds in delay_microseconds_accurate * Use delay(0) to let wifi and os function run * Linting * Remove unneeded delayMicroseconds, keep it for low usec * Avoid micros() overflow issue --- esphome/core/helpers.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index f0e0c65f66..3e7472d2fe 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -171,15 +171,17 @@ uint8_t crc8(uint8_t *data, uint8_t len) { } return crc; } + void delay_microseconds_accurate(uint32_t usec) { if (usec == 0) return; - - if (usec <= 16383UL) { + if (usec < 5000UL) { delayMicroseconds(usec); - } else { - delay(usec / 1000UL); - delayMicroseconds(usec % 1000UL); + return; + } + uint32_t start = micros(); + while (micros() - start < usec) { + delay(0); } }