diff --git a/src/SerialCom.h b/src/SerialCom.h index db77a74..442ef5b 100644 --- a/src/SerialCom.h +++ b/src/SerialCom.h @@ -82,15 +82,22 @@ namespace SerialCom { } Serial.print("Receiving:"); - while (sensorSerial.available()) { - serialRxBuf[rxBufIdx++] = sensorSerial.read(); - Serial.print("."); - - // Without this delay, receiving data breaks for reasons that are beyond me - delay(15); - - if (rxBufIdx >= 64) { - clearRxBuf(); + long now = millis(); + long lastMsg = now; + // wait for data with a timeout. + while (millis() - lastMsg < 15) + { + if (sensorSerial->available()) + { + lastMsg = millis(); // re-init the timeout timer since we received new data. + + serialRxBuf[rxBufIdx++] = sensorSerial->read(); + Serial.print("."); + + if (rxBufIdx >= 64) + { + clearRxBuf(); + } } } Serial.println("Done.");