Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens BLE reconnection behavior (especially on Android) by ensuring cached GATT/service/characteristic references are cleared during disconnect and by reducing reliance on stale Android BluetoothGatt state across reconnects. It also refines LEGO Control+/TechnicMove handling by making port index mapping safer and by adding a feedback-driven completion path for PLAYVM calibration.
Changes:
- Introduces a
OnDeviceDisconnecting()hook onBluetoothDeviceand implements it across device types to clear cached characteristic references before native disconnect/cleanup. - Adds an Android BLE “refresh service cache” reflection call during GATT disconnect/close to mitigate stale service/characteristic caching between reconnects.
- Updates ControlPlus/TechnicMove logic: safer port-id-to-channel mapping, a dedicated output-feedback callback hook, and a PLAYVM calibration wait based on hub feedback (with timeout fallback).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| BrickController2/BrickController2/DeviceManagement/Wedo2Device.cs | Clears cached characteristic references on disconnect to avoid stale native objects after reconnect. |
| BrickController2/BrickController2/DeviceManagement/Vengit/SBrickLightDevice.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/TechnicMoveDevice.cs | Filters unsupported configurations, adds feedback-based PLAYVM calibration wait, and updates port/channel mapping for non-index port IDs. |
| BrickController2/BrickController2/DeviceManagement/SBrickDevice.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/PfxBrickDevice.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/MouldKing/MK_DIY.cs | Clears cached characteristic reference on disconnect. |
| BrickController2/BrickController2/DeviceManagement/Lego/RemoteControl.cs | Clears cached characteristic reference on disconnect. |
| BrickController2/BrickController2/DeviceManagement/ControlPlusDevice.cs | Adds disconnect cleanup, safe port-id mapping via TryGetChannelIndex, feedback hook for message 0x82, and debug-only logging. |
| BrickController2/BrickController2/DeviceManagement/CircuitCubeDevice.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuwizzDevice.cs | Clears cached characteristic reference on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuWizz3Device.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuWizz2Device.cs | Clears cached characteristic references on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs | Adds abstract OnDeviceDisconnecting() and invokes it as part of the disconnect sequence; makes disconnect callback invocation more robust. |
| BrickController2/BrickController2.Android/PlatformServices/BluetoothLE/BluetoothLEDevice.cs | Adds reflective BluetoothGatt.refresh() call before close/dispose to reduce stale service caching across reconnects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // if PLAYVM enabled, suppress A / B / C channels — all controlled via PLAYVM commands, | ||
| // and the hub is still settling after PLAYVM_CALIBRATE_STEERING when the output task starts | ||
| // or if LED channels (3-8) all share PORT_6LEDS — suppress initial burst to avoid flooding the hub's BLE receive buffer | ||
| if ((_applyPlayVmMode && channel < CHANNEL_C) || | ||
| (channel > CHANNEL_C && channel < NumberOfChannels)) | ||
| { |
There was a problem hiding this comment.
Pull request overview
This PR hardens Bluetooth LE reconnection behavior by introducing a disconnect hook to clear cached GATT characteristic references (avoiding stale native Android objects), and adds an Android-specific GATT service-cache refresh on disconnect. It also improves Control+ port-to-channel mapping safety and enhances Technic Move PLAYVM calibration handling.
Changes:
- Add
OnDeviceDisconnecting()lifecycle hook to clear cachedIGattCharacteristicreferences across BLE devices before native disconnect. - Add Android
BluetoothGatt.refresh()(reflection) on disconnect to reduce stale service caching between reconnects. - Improve Control+ message parsing with
TryGetChannelIndex(...)and update Technic Move PLAYVM calibration to wait for hub feedback (with timeout fallback).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| BrickController2/BrickController2/DeviceManagement/BluetoothDevice.cs | Adds OnDeviceDisconnecting() hook and ensures callback handling is safe during disconnect. |
| BrickController2/BrickController2/DeviceManagement/ControlPlusDevice.cs | Switches to TryGetChannelIndex to avoid invalid indexing and adds a disconnect cleanup for cached characteristic. |
| BrickController2/BrickController2/DeviceManagement/TechnicMoveDevice.cs | Filters unsupported channel configs, improves init suppression for LED/PLAYVM, and waits for PLAYVM calibration feedback instead of fixed delays. |
| BrickController2/BrickController2/DeviceManagement/Wedo2Device.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/SBrickDevice.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/Vengit/SBrickLightDevice.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/PfxBrickDevice.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/MouldKing/MK_DIY.cs | Clears cached characteristic on disconnect. |
| BrickController2/BrickController2/DeviceManagement/Lego/RemoteControl.cs | Clears cached characteristic on disconnect. |
| BrickController2/BrickController2/DeviceManagement/CircuitCubeDevice.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuwizzDevice.cs | Clears cached characteristic on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuWizz2Device.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2/DeviceManagement/BuWizz3Device.cs | Clears cached characteristics on disconnect. |
| BrickController2/BrickController2.Android/PlatformServices/BluetoothLE/BluetoothLEDevice.cs | Adds reflected BluetoothGatt.refresh() before closing GATT to mitigate stale service cache on Android. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
No description provided.