Conversation
This is helpful for the UI, which needs to wait for connection changes, and checking multiple connection states for change may not be reliable if more than one changes at once.
We will allow simultaneous Bluetooth and USB connections, so it no longer makes sense to have USB override other states. Advertising takes priority since it is a temporary state. BLE and USB have equal priority, and we mix their color if both are connected.
Otherwise we never get the completion command, so this task keeps waiting. This lets the UI call the start advertising command safely in any state.
This was already supported implicitly by connecting to Bluetooth first and then plugging in USB. It is more intuitive if we could just enable BLE advertising using the bluetooth button even if USB is already connected.
We had already split off the peripheral since it has more than one instance. The same will now apply to the host. The check for LE connections without Pybricks was never used, and NUS is not supported, so this function can go.
This allows using a secondary device like a phone to monitor the connection.
This was accidentally negated in a17c1d2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows up to two Bluetooth host connections on Spike, which is needed for some upcoming applications. It also makes the existing support for simultaneous USB/BLE explicit. Until now, you'd have to connect BLE first, and then USB to make it work. Now you can do it in any order.
pbio/drv/bluetooth,usb: Add connection changed callback. Technically an independent cleanup. Services connection changes once instead of by polling.
pbio/sys/light: Change priority of USB light. Combining the green USB state with a blinking blue light is hard to see. Since advertising is a temporary state, keep this as blue/off/blue/off, even if there is already a host connected. The solid color returns when advertising is done. USB+BLE = Green+Blue = Cyan.
pbio/drv/bluetooth_btstack: Don't advertise if connected. Only start the operation when there are free connections left, or we're waiting forever.
pbio/sys/hmi: Support simultaneous USB and BLE host. Refactors the Powered Up HMI to take in the light update and connection callback introduced above.
pbio/drv/bluetooth: Split out connection checks. Minor cleanup as an existing connection platform hook became obsolete.
pbio/drv/bluetooth_btstack: Allow multiple hosts. This is the main change as far as actual driver code is concerned. It refactors the BTstack driver to not work with a singleton host handles, but
Nbluetooth hosts.Ongoing work:
We'll still want to protect new downloads being started while another is in progress. But that was already an issue before this PR since you could have USB and BLE connected at the same time. See pybricks/support#2551.