Skip to content

Rework the API to use descriptors. #30

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

Merged
merged 4 commits into from
Nov 5, 2019
Merged

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Oct 23, 2019

Thank you so much for taking this on @dhalbert.

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".

I've added comments to the examples on which should work. I just confirmed that UART mostly still works. The client device safe moded for some reason but I'm out of debugging time. After a button reset it worked ok.

This requires adafruit/circuitpython#2236 and
relates to adafruit/circuitpython#586.

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.
@tannewt tannewt requested a review from dhalbert October 23, 2019 00:33
@tannewt
Copy link
Member Author

tannewt commented Oct 23, 2019

@theacodes This is the API we chatted about a while back. Would love your thoughts on it.

@theacodes
Copy link
Collaborator

theacodes commented Oct 23, 2019 via email

Copy link
Collaborator

@theacodes theacodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the descriptor design. 👍

Left some other comments, you can take or leave them.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete review, here are my comments so far.

This renames Smart* to BLE* and removes the smart recognition. It
is replaced by knowing the type of what we're interested at use
time only. Only printing Service lists is now dumber.

Interal variables to _bleio classes are now public as bleio_*
instead so that other classes in the library can access them and
its clearer what they are.
Copy link
Member Author

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, please take another look. Things have been simplified and the two bluefruit examples also updated.

@dhalbert
Copy link
Collaborator

dhalbert commented Nov 1, 2019

Some simple pylint failures.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the big talk we had: I have a much better understanding now of the internal structure. Any further internal changes will affect the user API very little or not at all. Only have minor stuff (and pylint fixes).

Thanks also for the reorg, removing the core.py stuff: the source structure is cleaner now.


ble = BLERadio()
while True:
while ble.connected and any(UARTService in connection for connection in ble.connections):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we really need a helper for this. Maybe:

ble.find_service(UARTService)

With a behavior of Helper method that looks through all connections for a given service and returns the first one found.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're merging this now and will look for API helpers, etc. when rewriting the current examples. Thanks and we'll keep all these in mind.

k = Keyboard(hid.devices)
kl = KeyboardLayoutUS(k)
while True:
while not ble.connected:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spinning on connected is becoming a pattern. Maybe a helper ble.wait_for_connection() with an optional timeout?

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this now to keep up with the corresponding CircuitPython PR: adafruit/circuitpython#2236

@dhalbert dhalbert merged commit 2d5ef97 into adafruit:master Nov 5, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 20, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1305 to 1.0.3 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1305#5 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.6.0 from 3.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#51 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#47 from Johennes/feature/numpy

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 3.0.0 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#34 from dhalbert/check-cpy-version
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#32 from dhalbert/doc-and-cleanup
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#31 from dhalbert/char-fixes-and-float
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#30 from tannewt/api_rework
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#29 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#25 from kattni/plotter-code
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#23 from kattni/update-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#22 from kattni/update-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#21 from kattni/cpb-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#18 from dhalbert/bleio-api-revamp
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#17 from dhalbert/demo-central
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#16 from dhalbert/pairing
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#15 from dhalbert/python-advertisement-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants