handleSerial(): 100ms RX timeout (experimental)

experimental - this should avoid lockups when ESP32 is constantly receiving data (noise, junk, excessive communication)
This commit is contained in:
Frank
2023-03-16 11:30:12 +01:00
parent 0b841c0788
commit d9b5b9d4d6
2 changed files with 10 additions and 2 deletions

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2303141
#define VERSION 2303160
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@@ -4,6 +4,9 @@
* Adalight and TPM2 handler
*/
#define SERIAL_MAXTIME_MILLIS 100 // to avoid blocking other activities, do not spend more than 100ms with continouus reading
// at 115200 baud, 100ms is enough to send/receive 1280 chars
enum class AdaState {
Header_A,
Header_d,
@@ -87,6 +90,7 @@ void handleSerial()
{
if (pinManager.isPinAllocated(hardwareRX)) return;
if (!Serial) return; // WLEDMM - serial not connected (USB CDC)
if (((pinManager.isPinAllocated(hardwareTX)) && (pinManager.getPinOwner(hardwareTX) != PinOwner::DebugOut))) return; // WLEDMM serial TX is necessary for adalight / TPM2
#ifdef WLED_ENABLE_ADALIGHT
static auto state = AdaState::Header_A;
@@ -96,7 +100,8 @@ void handleSerial()
static byte red = 0x00;
static byte green = 0x00;
while (Serial.available() > 0)
unsigned long startTime = millis();
while ((Serial.available() > 0) && (millis() - startTime < SERIAL_MAXTIME_MILLIS))
{
yield();
byte next = Serial.peek();
@@ -217,6 +222,9 @@ void handleSerial()
Serial.read(); //discard the byte
}
#endif
//#ifdef WLED_DEBUG
if ((millis() - startTime) > SERIAL_MAXTIME_MILLIS) { USER_PRINTLN(F("handleSerial(): need a break after >100ms of activity.")); }
//#endif
// If Continuous Serial Streaming is enabled, send new LED data as bytes
if (continuousSendLED && (lastUpdate != strip.getLastShow())){