diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 0b2e7491b..bd70e95f3 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -14,6 +14,10 @@ #endif #ifdef WITH_RS232_BRIDGE +#ifdef WITH_USB_SERIAL_BRIDGE +#include +extern Adafruit_USBD_CDC bridgeSerial; +#endif #include "helpers/bridges/RS232Bridge.h" #define WITH_BRIDGE #endif diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 60e0a9fd2..62486629c 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -3,6 +3,10 @@ #include "MyMesh.h" +#ifdef WITH_USB_SERIAL_BRIDGE +Adafruit_USBD_CDC bridgeSerial; +#endif + #ifdef DISPLAY_CLASS #include "UITask.h" static UITask ui_task(display); @@ -36,6 +40,10 @@ static unsigned long userBtnDownAt = 0; #endif void setup() { +#ifdef WITH_USB_SERIAL_BRIDGE + // Register the second CDC interface before Serial mounts the USB device. + bridgeSerial.begin(115200); +#endif Serial.begin(115200); delay(1000); diff --git a/src/helpers/bridges/RS232Bridge.cpp b/src/helpers/bridges/RS232Bridge.cpp index f719d342e..19c243056 100644 --- a/src/helpers/bridges/RS232Bridge.cpp +++ b/src/helpers/bridges/RS232Bridge.cpp @@ -2,6 +2,10 @@ #include +#ifdef WITH_USB_SERIAL_BRIDGE +#include +#endif + #ifdef WITH_RS232_BRIDGE RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager *mgr, mesh::RTCClock *rtc) @@ -9,6 +13,9 @@ RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager * void RS232Bridge::begin() { BRIDGE_DEBUG_PRINTLN("Initializing at %d baud...\n", _prefs->bridge_baud); +#ifdef WITH_USB_SERIAL_BRIDGE + static_cast(_serial)->begin(_prefs->bridge_baud); +#else #if !defined(WITH_RS232_BRIDGE_RX) || !defined(WITH_RS232_BRIDGE_TX) #error "WITH_RS232_BRIDGE_RX and WITH_RS232_BRIDGE_TX must be defined" #endif @@ -28,6 +35,7 @@ void RS232Bridge::begin() { #error RS232Bridge was not tested on the current platform #endif ((HardwareSerial *)_serial)->begin(_prefs->bridge_baud); +#endif // Update bridge state _initialized = true; @@ -35,7 +43,11 @@ void RS232Bridge::begin() { void RS232Bridge::end() { BRIDGE_DEBUG_PRINTLN("Stopping...\n"); +#ifdef WITH_USB_SERIAL_BRIDGE + static_cast(_serial)->end(); +#else ((HardwareSerial *)_serial)->end(); +#endif // Update bridge state _initialized = false;