-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refine _bleio #2236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine _bleio #2236
Conversation
This PR refines the _bleio API. It was originally motivated by the addition of a new CircuitPython service that enables reading and modifying files on the device. Moving the BLE lifecycle outside of the VM motivated a number of changes to remove heap allocations in some APIs. It also motivated unifying connection initiation to the Adapter class rather than the Central and Peripheral classes which have been removed. Adapter now handles the GAP portion of BLE including advertising, which has moved but is largely unchanged, and scanning, which has been enhanced to return an iterator of filtered results. Once a connection is created (either by us (aka Central) or a remote device (aka Peripheral)) it is represented by a new Connection class. This class knows the current connection state and can discover and instantiate remote Services along with their Characteristics and Descriptors. Relates to micropython#586
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really excellent! The refactoring to Connection
makes a lot of sense and really presents the right abstraction. Thank you for the big re-think!
The check failures are all in |
This makes Advertisement and Service definitions declarative by factoring out parsing logic out into shareable descriptor classes similar to how the Register library works. This also introduces SmartAdapter and SmartConnection which will auto-create the correct Advertisements and Services without requiring any direct use of UUIDs. Instead, classes are used to identify relevant objects to "recognize". This requires adafruit/circuitpython#2236 and relates to adafruit/circuitpython#586.
Thanks for the fast review @dhalbert. Please take another look. I'll be on a plane all Wednesday but will try to take a peek Thursday. |
@tannewt I'm confused about why there are now merge conflicts. |
@dhalbert Jeff fixed a typo in one of the comments I changed. Merged now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, great! Merging this to start rewriting other examples and testing with the new API.
Warning: use the correct version of Adafruit_CircuitPython_BLE with builds following this merge.
This PR refines the _bleio API. It was originally motivated by
the addition of a new CircuitPython service that enables reading
and modifying files on the device. Moving the BLE lifecycle outside
of the VM motivated a number of changes to remove heap allocations
in some APIs.
It also motivated unifying connection initiation to the Adapter class
rather than the Central and Peripheral classes which have been removed.
Adapter now handles the GAP portion of BLE including advertising, which
has moved but is largely unchanged, and scanning, which has been enhanced
to return an iterator of filtered results.
Once a connection is created (either by us (aka Central) or a remote
device (aka Peripheral)) it is represented by a new Connection class.
This class knows the current connection state and can discover and
instantiate remote Services along with their Characteristics and
Descriptors.
Relates to #586