-
Notifications
You must be signed in to change notification settings - Fork 56
Bleio attribute api revamp #18
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 8000 ”, 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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0445d12
Initial BLE HID; works everywhere but iOS
dhalbert 89e8cdb
restore unimplemented boot keyboard and mouse
dhalbert ff05feb
Update to use new bleio API
dhalbert a643591
another API rework: less abstraction leakage
dhalbert 42e871d
rename bleio to _bleio
dhalbert 67b9341
explicate Appearance; forgot to add address.py
dhalbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2019 Dan Halbert for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_ble.address` | ||
==================================================== | ||
|
||
BLE Address | ||
|
||
* Author(s): Dan Halbert for Adafruit Industries | ||
|
||
""" | ||
|
||
from _bleio import UUID as _bleio_Address | ||
|
||
UUID = _bleio_Address | ||
"""`adafruit_ble.Address` is the same as `_bleio.Address`""" |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2019 Dan Halbert for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_ble.device_information` | ||
==================================================== | ||
|
||
Device Information Service (DIS) | ||
|
||
* Author(s): Dan Halbert for Adafruit Industries | ||
|
||
""" | ||
from _bleio import Attribute, Characteristic, Service, UUID | ||
|
||
class DeviceInformationService: | ||
"""This is a factory class only, and has no instances.""" | ||
|
||
@staticmethod | ||
def add_to_peripheral(peripheral, *, model_number=None, serial_number=None, | ||
firmware_revision=None, hardware_revision='', | ||
software_revision='', manufacturer=''): | ||
""" | ||
Add a Service with fixed Device Information Service characteristics to the given Peripheral. | ||
All values are optional. | ||
|
||
:param str model_number: Device model number. If None use `sys.platform`. | ||
:param str serial_number: Device serial number. If None use a hex representation of | ||
``microcontroller.cpu.id``. | ||
:param str firmware_revision: Device firmware revision. | ||
If None use ``os.uname().version``. | ||
:param str hardware_revision: Device hardware revision. | ||
:param str software_revision: Device software revision. | ||
:param str manufacturer: Device manufacturer name | ||
:return: the created Service | ||
|
||
Example:: | ||
|
||
peripheral = Peripheral() | ||
dis = DeviceInformationService.add_to_peripheral( | ||
peripheral, software_revision="1.2.4", manufacturer="Acme Corp") | ||
""" | ||
|
||
# Avoid creating constants with names if not necessary. Just takes up space. | ||
# Device Information Service UUID = 0x180A | ||
# Module Number UUID = 0x2A24 | ||
# Serial Number UUID = 0x2A25 | ||
# Firmware Revision UUID = 0x2A26 | ||
# Hardware Revision UUID = 0x2A27 | ||
# Software Revision UUID = 0x2A28 | ||
# Manufacturer Name UUID = 0x2A29 | ||
|
||
service = Service.add_to_peripheral(peripheral, UUID(0x180A)) | ||
|
||
if model_number is None: | ||
import sys | ||
model_number = sys.platform | ||
if serial_number is None: | ||
import microcontroller | ||
import binascii | ||
serial_number = binascii.hexlify(microcontroller.cpu.uid).decode('utf-8') # pylint: disable=no-member | ||
|
||
if firmware_revision is None: | ||
import os | ||
firmware_revision = os.uname().version | ||
|
||
# Values must correspond to UUID numbers. | ||
for uuid_num, value in zip( | ||
range(0x2A24, 0x2A29+1), | ||
(model_number, serial_number, | ||
firmware_revision, hardware_revision, software_revision, | ||
manufacturer)): | ||
|
||
Characteristic.add_to_service( | ||
service, UUID(uuid_num), properties=Characteristic.READ, | ||
read_perm=Attribute.OPEN, write_perm=Attribute.NO_ACCESS, | ||
fixed_length=True, max_length=len(value), | ||
initial_value=value) | ||
|
||
return service |
Oops, something went wrong.
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.
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.
What is appearance?
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.
An appearance is a constant saying what kind of device it is: https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.gap.appearance.xml
More readable: http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v5.x.x/doc/5.2.0/html/a01225.html