Allow Bluetooth to be toggled off/on with Bluetooth button.#247
Merged
Conversation
The code: if pressed then user_program_start(true) made it read as if this call was starting the code on pressing the button, which isn't quite what this is doing. So rename to make this clearer, since we'll be adding a similar routine for the Bluetooth button UI.
dlech
reviewed
Jun 5, 2024
It doesn't take that many bytes and it helps keep the code much cleaner.
Using advertising as the debounce state only applies when Bluetooth is enabled.
Being not-connected naturally extends to USB when we add it.
This is less fragile than starting and stopping the process.
This reverts 8c8340b. At this point, we don't need an extra status flag. Bluetooth is the only communication method, and we can't communicate a status if it is disabled. So we can avoid changing the protocol for now. We can add appropriate flags if we add USB support, in which case communicating the active connection type may make sense.
395315f to
3e29eb3
Compare
Member
Author
|
In rare occasions it can get stuck at the bottom of the This seems odd as it would have traversed this path too all the time so far when running a really short program. Or maybe we just haven't noticed it before? |
|
I have a question that if I want set bluetooth off by default, how to change this? Thanks. |
Member
Author
You no longer need to use builds from this pull request. You can use the nightly build which already includes this feature. The setting also persists. So Bluetooth will still be off when you reboot the hub. |
|
Thanks a lot. |
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.
Implements toggling Bluetooth on and off with the Bluetooth button on Spike Prime and Mindstorms Robot Inventor.
See pybricks/support#1615 for context, use cases, and user interface considerations.
This is a slightly more minimalist approach compared to #195. It adds
PBIO_PYBRICKS_STATUS_BLUETOOTH_BLE_ENABLEDto the protocol instead ofPBIO_PYBRICKS_STATUS_BLUETOOTH_BUTTON_PRESSEDandPBIO_PYBRICKS_STATUS_BLUETOOTH_SHUTDOWN.The
hmiis implemented similar to the existing code for the start/stop program button, and separated from the actual Bluetooth start/stop logic. Thehmimay request a Bluetooth toggle, but it is up tosys/bluetoothwhether to do anything with that. This prevents Bluetooth from being toggled if is currently being used or while a program is running.The
PBIO_PYBRICKS_STATUS_BLUETOOTH_BLE_ENABLEDflag is only used for raising exceptions when the user tries to create remote peripheral or broadcast/observe.Persistency is a separate task that can be added later. This was holding up previous merges, but we should be able to get started without it.
Thanks to everyone for asking about this feature and thanks to @nkarstens for creating #195!