fix(serial): no 300 ms stall per frame with no USB host

With the phone not connected, every frame (each packet heard, each advert)
went to the USB port. With nobody holding it open the core either drops the
bytes or lets its buffer fill, and streamWriteUntil() then spun out its whole
timeout. Skip the write when the native USB Serial has no host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-12 15:07:18 +02:00
co-authored by Claude Opus 5.5
parent 7ad11b6f02
commit bca926eee2
+7
View File
@@ -32,6 +32,13 @@ size_t ArduinoSerialInterface::writeFrame(const uint8_t src[], size_t len) {
return 0;
}
// A native USB port with no host holding it open: the core drops the bytes
// (nRF52 TinyUSB, ESP32 USBCDC) or lets its buffer fill, and either way
// streamWriteUntil() would spin out the whole timeout on every frame -- the
// loop stalled 300 ms per packet heard while no phone was connected. A UART
// bridge's Serial always reads true, so those boards are unaffected.
if (_serial == (Stream*)&Serial && !Serial) return 0;
uint8_t hdr[3];
hdr[0] = '>';
hdr[1] = (len & 0xFF); // LSB