Report the real USB client connection state in companion builds

ArduinoSerialInterface::isConnected() always returned true, so any
companion build with a USB interface believes a client is attached from
boot onwards. Two user visible effects:

- new message notifications never fire, because MyMesh only notifies
  the UI (display, buzzer) while no client is connected
- on builds that also expose BLE the home screen shows '< Connected >'
  instead of the BLE pairing PIN, so a freshly flashed device cannot be
  paired at all

Add an optional connection check callback and wire it up per platform:
native USB-CDC (TinyUSB on nRF52/RP2040/ESP32 with USB_MODE=0) exposes
real DTR through (bool)Serial. The ESP32 USB-Serial-JTAG peripheral has
no DTR concept - it reports 'connected' as soon as the host enumerated
the device - so fall back to frame activity there. Plain UARTs keep the
previous assume-connected behaviour.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Fable 5 committed 2026-08-14 20:13:36 +02:00
1 parent d929643524
commit ab492ba187
3 files changed
+43 -5

No files matched your search

+3 -1
View File
@@ -13,7 +13,8 @@ void ArduinoSerialInterface::disable() {
_isEnabled = false;
}
bool ArduinoSerialInterface::isConnected() const {
bool ArduinoSerialInterface::isConnected() const {
if (_conn_check) return _conn_check();
return true; // no way of knowing, so assume yes
}
@@ -65,6 +66,7 @@ size_t ArduinoSerialInterface::checkRecvFrame(uint8_t dest[]) {
if (_frame_len > MAX_FRAME_SIZE) _frame_len = MAX_FRAME_SIZE; // truncate
memcpy(dest, rx_buf, _frame_len);
_state = RECV_STATE_IDLE; // reset state, for next frame
_last_frame_ms = millis(); // a real client is talking to us
return _frame_len;
}
}