mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-02 10:16:11 +00:00
feat: dual BLE+USB serial — single firmware replaces separate BLE/USB builds
- DualSerialInterface: enable()/disable() control BLE only, USB always on; USB state machine not read while BLE connected to avoid partial-frame corruption; reset USB on BLE disconnect for clean reconnect - Fix -UBLE_DEBUG_LOGGING (no space) to avoid PlatformIO SCons parse error - build.sh: drop separate USB/BLE builds, dual_settings only - wio-tracker-l1-eink: enable DUAL_SERIAL in companion_radio_ble build Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
7a49584af7
commit
5828600d48
@@ -231,8 +231,6 @@ build_companion_firmwares() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build_wio_tracker_l1_firmwares() {
|
build_wio_tracker_l1_firmwares() {
|
||||||
build_firmware "WioTrackerL1_companion_radio_usb_settings"
|
|
||||||
build_firmware "WioTrackerL1_companion_radio_ble_settings"
|
|
||||||
build_firmware "WioTrackerL1_companion_radio_dual_settings"
|
build_firmware "WioTrackerL1_companion_radio_dual_settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,22 +5,29 @@
|
|||||||
#include "SerialBLEInterface.h"
|
#include "SerialBLEInterface.h"
|
||||||
|
|
||||||
// Wraps BLE + USB serial interfaces: BLE takes priority when connected,
|
// Wraps BLE + USB serial interfaces: BLE takes priority when connected,
|
||||||
// USB is always ready as a fallback. Both state machines run continuously.
|
// USB is always ready as a fallback.
|
||||||
|
// enable()/disable() control BLE only — USB is always on.
|
||||||
|
// BLE state machine is only pumped when BLE is enabled; USB is not read while BLE is connected.
|
||||||
class DualSerialInterface : public BaseSerialInterface {
|
class DualSerialInterface : public BaseSerialInterface {
|
||||||
SerialBLEInterface _ble;
|
SerialBLEInterface _ble;
|
||||||
ArduinoSerialInterface _usb;
|
ArduinoSerialInterface _usb;
|
||||||
uint8_t _ble_buf[MAX_FRAME_SIZE];
|
uint8_t _ble_buf[MAX_FRAME_SIZE];
|
||||||
uint8_t _usb_buf[MAX_FRAME_SIZE];
|
uint8_t _usb_buf[MAX_FRAME_SIZE];
|
||||||
|
bool _ble_enabled;
|
||||||
|
bool _ble_was_connected;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
DualSerialInterface() : _ble_enabled(false), _ble_was_connected(false) {}
|
||||||
|
|
||||||
void begin(const char* ble_prefix, char* node_name, uint32_t pin_code, Stream& usb_stream) {
|
void begin(const char* ble_prefix, char* node_name, uint32_t pin_code, Stream& usb_stream) {
|
||||||
_ble.begin(ble_prefix, node_name, pin_code);
|
_ble.begin(ble_prefix, node_name, pin_code);
|
||||||
_usb.begin(usb_stream);
|
_usb.begin(usb_stream);
|
||||||
|
_usb.enable(); // USB is always on
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable() override { _ble.enable(); _usb.enable(); }
|
void enable() override { _ble.enable(); _ble_enabled = true; }
|
||||||
void disable() override { _ble.disable(); _usb.disable(); }
|
void disable() override { _ble.disable(); _ble_enabled = false; }
|
||||||
bool isEnabled() const override { return _ble.isEnabled() || _usb.isEnabled(); }
|
bool isEnabled() const override { return _ble_enabled; }
|
||||||
|
|
||||||
// Always true — USB is always available as fallback, so the mesh can send.
|
// Always true — USB is always available as fallback, so the mesh can send.
|
||||||
bool isConnected() const override { return true; }
|
bool isConnected() const override { return true; }
|
||||||
@@ -36,16 +43,26 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t checkRecvFrame(uint8_t dest[]) override {
|
size_t checkRecvFrame(uint8_t dest[]) override {
|
||||||
// Always pump both state machines: BLE needs this for TX queue drain and
|
if (_ble_enabled) {
|
||||||
// advertising watchdog; USB needs it to drain its input buffer.
|
size_t ble_len = _ble.checkRecvFrame(_ble_buf);
|
||||||
size_t ble_len = _ble.checkRecvFrame(_ble_buf);
|
bool ble_now = _ble.isConnected();
|
||||||
size_t usb_len = _usb.checkRecvFrame(_usb_buf);
|
|
||||||
|
|
||||||
if (_ble.isConnected()) {
|
if (ble_now) {
|
||||||
if (ble_len > 0) { memcpy(dest, _ble_buf, ble_len); return ble_len; }
|
_ble_was_connected = true;
|
||||||
} else {
|
if (ble_len > 0) { memcpy(dest, _ble_buf, ble_len); return ble_len; }
|
||||||
if (usb_len > 0) { memcpy(dest, _usb_buf, usb_len); return usb_len; }
|
return 0; // BLE active — don't read USB to keep its state machine clean
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_ble_was_connected) {
|
||||||
|
// BLE just disconnected — reset USB state machine so stale partial frames don't block it
|
||||||
|
_ble_was_connected = false;
|
||||||
|
_usb.enable();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t usb_len = _usb.checkRecvFrame(_usb_buf);
|
||||||
|
if (usb_len > 0) { memcpy(dest, _usb_buf, usb_len); return usb_len; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ build_flags = ${WioTrackerL1Eink.build_flags}
|
|||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
-D UI_RECENT_LIST_SIZE=6
|
-D UI_RECENT_LIST_SIZE=6
|
||||||
-D UI_SENSORS_PAGE=1
|
-D UI_SENSORS_PAGE=1
|
||||||
|
-D DUAL_SERIAL
|
||||||
build_src_filter = ${WioTrackerL1Eink.build_src_filter}
|
build_src_filter = ${WioTrackerL1Eink.build_src_filter}
|
||||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||||
+<helpers/ui/MomentaryButton.cpp>
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ extra_scripts = post:create-uf2.py
|
|||||||
extends = WioTrackerL1CompanionBLE
|
extends = WioTrackerL1CompanionBLE
|
||||||
build_flags = ${WioTrackerL1CompanionBLE.build_flags}
|
build_flags = ${WioTrackerL1CompanionBLE.build_flags}
|
||||||
-D DUAL_SERIAL=1
|
-D DUAL_SERIAL=1
|
||||||
-U BLE_DEBUG_LOGGING
|
-UBLE_DEBUG_LOGGING
|
||||||
|
|
||||||
[env:WioTrackerL1_companion_radio_dual]
|
[env:WioTrackerL1_companion_radio_dual]
|
||||||
extends = WioTrackerL1CompanionDual
|
extends = WioTrackerL1CompanionDual
|
||||||
|
|||||||
Reference in New Issue
Block a user