From 926b4913f13d7a57906ad665a13af1857016265c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Jan 2019 22:49:57 -0500 Subject: [PATCH 1/3] add a non-empty bluefruit_connect_simpletest.py --- examples/bluefruit_connect_simpletest.py | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/bluefruit_connect_simpletest.py b/examples/bluefruit_connect_simpletest.py index 70a1417..698042e 100644 --- a/examples/bluefruit_connect_simpletest.py +++ b/examples/bluefruit_connect_simpletest.py @@ -1 +1,24 @@ -# To be supplied +# Print out the color data from a ColorPacket. + +from adafruit_ble.uart import UARTServer +from adafruit_bluefruit_connect.packet import Packet +# Only the packet classes that are imported will be known to Packet. +from adafruit_bluefruit_connect.color_packet import ColorPacket + +uart_server = UARTServer() + +advertising_now = False + +while True: + if not uart_server.connected: + if not advertising_now: + uart_server.start_advertising() + advertising_now = True + continue + + # Connected, so no longer advertising + advertising_now = False + + packet = Packet.from_stream(uart_server) + if isinstance(packet, ColorPacket): + print(packet.color) From 8886bdf66ff896cf6cae51bee0d8dc8663653358 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Jan 2019 23:20:31 -0500 Subject: [PATCH 2/3] fix documentation problems --- adafruit_bluefruit_connect/__init__.py | 4 ++-- adafruit_bluefruit_connect/button_packet.py | 2 +- adafruit_bluefruit_connect/location_packet.py | 2 +- adafruit_bluefruit_connect/packet.py | 6 ++--- docs/api.rst | 23 ++++++++++++++++++- docs/examples.rst | 6 +++++ ...t.py => bluefruit_connect_crickit_test.py} | 0 7 files changed, 35 insertions(+), 8 deletions(-) rename examples/{crickit_controller_test.py => bluefruit_connect_crickit_test.py} (100%) diff --git a/adafruit_bluefruit_connect/__init__.py b/adafruit_bluefruit_connect/__init__.py index d3ea088..c07e956 100644 --- a/adafruit_bluefruit_connect/__init__.py +++ b/adafruit_bluefruit_connect/__init__.py @@ -21,7 +21,7 @@ # THE SOFTWARE. """ `adafruit_bluefruit_connect` -==================================================== +============================ This module helps you to communicate with the Adafruit Bluefruit Connect app or use its protocols. @@ -32,7 +32,7 @@ **Hardware:** - inline format: "* `Adafruit Feather nRF52840 Express `_" + Adafruit Feather nRF52840 Express **Software and Dependencies:** diff --git a/adafruit_bluefruit_connect/button_packet.py b/adafruit_bluefruit_connect/button_packet.py index 8e9529d..cead0ff 100644 --- a/adafruit_bluefruit_connect/button_packet.py +++ b/adafruit_bluefruit_connect/button_packet.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_bluefruit_connect.controller_packet` +`adafruit_bluefruit_connect.button_packet` ==================================================== Bluefruit Connect App Button data packet (button_name, pressed/released) diff --git a/adafruit_bluefruit_connect/location_packet.py b/adafruit_bluefruit_connect/location_packet.py index 3064099..c6d5932 100644 --- a/adafruit_bluefruit_connect/location_packet.py +++ b/adafruit_bluefruit_connect/location_packet.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_bluefruit_connect.controller_packet` +`adafruit_bluefruit_connect.location_packet` ==================================================== Bluefruit Connect App geographical location packet. diff --git a/adafruit_bluefruit_connect/packet.py b/adafruit_bluefruit_connect/packet.py index 80d3561..72ce294 100644 --- a/adafruit_bluefruit_connect/packet.py +++ b/adafruit_bluefruit_connect/packet.py @@ -59,7 +59,7 @@ class Packet: @classmethod def register_packet_type(cls): - """Register a new packet type, using this class and its `cls._TYPE_HEADER` + """Register a new packet type, using this class and its ``cls._TYPE_HEADER``. The ``from_bytes()`` and ``from_stream()`` methods will then be able to recognize this type of packet. """ @@ -97,11 +97,11 @@ def from_stream(cls, stream): """Read the next packet from the incoming stream. Wait as long as the timeout set on stream, using its own preset timeout. Return None if there was no input, otherwise return an instance - of one of the packet classes registered with `Packet`. + of one of the packet classes registered with ``Packet``. Raise an Error if the packet was not recognized or was malformed :param stream stream: an input stream that provides standard stream read operations, - such as `ble.UARTServer` or `busio.UART`. + such as ``ble.UARTServer`` or ``busio.UART``. """ header = stream.read(2) if len(header) != 2 or header[0] != ord(b'!'): diff --git a/docs/api.rst b/docs/api.rst index 0f45bd8..e59343d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,26 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" -.. automodule:: adafruit_bluefruit_connect +.. automodule:: adafruit_bluefruit_connect.packet + :members: + +.. automodule:: adafruit_bluefruit_connect.accelerometer_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.button_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.color_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.gyro_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.location_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.magnetometer_packet + :members: + +.. automodule:: adafruit_bluefruit_connect.quaternion_packet :members: diff --git a/docs/examples.rst b/docs/examples.rst index e2e685b..d68d69f 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,9 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/bluefruit_connect_simpletest.py :caption: examples/bluefruit_connect_simpletest.py :linenos: + +This test demonstrates controlling an Adafruit Crickit board with Bluetooth. + +.. literalinclude:: ../examples/bluefruit_connect_crickit_test.py + :caption: examples/bluefruit_connect_crickit_test.py + :linenos: diff --git a/examples/crickit_controller_test.py b/examples/bluefruit_connect_crickit_test.py similarity index 100% rename from examples/crickit_controller_test.py rename to examples/bluefruit_connect_crickit_test.py From 9be1322140827aa0d7f114ffc123911ff8197b45 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Jan 2019 23:29:08 -0500 Subject: [PATCH 3/3] add __init__.py to doc --- docs/api.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index e59343d..c32ec68 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,6 +4,9 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" +.. automodule:: adafruit_bluefruit_connect + :members: + .. automodule:: adafruit_bluefruit_connect.packet :members: