Skip to content

Commit 4c90cc1

Browse files
authored
Merge pull request #6 from dhalbert/add-simpletest
Improve tests and documentation
2 parents e15dde3 + 9be1322 commit 4c90cc1

File tree

8 files changed

+61
-8
lines changed

8 files changed

+61
-8
lines changed

adafruit_bluefruit_connect/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# THE SOFTWARE.
2222
"""
2323
`adafruit_bluefruit_connect`
24-
====================================================
24+
============================
2525
2626
This module helps you to communicate with the Adafruit Bluefruit Connect app or use its protocols.
2727
@@ -32,7 +32,7 @@
3232
3333
**Hardware:**
3434
35-
inline format: "* `Adafruit Feather nRF52840 Express <https://www.adafruit.com/product/4062>`_"
35+
Adafruit Feather nRF52840 Express <https://www.adafruit.com/product/4062>
3636
3737
**Software and Dependencies:**
3838

adafruit_bluefruit_connect/button_packet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_bluefruit_connect.controller_packet`
23+
`adafruit_bluefruit_connect.button_packet`
2424
====================================================
2525
2626
Bluefruit Connect App Button data packet (button_name, pressed/released)

adafruit_bluefruit_connect/location_packet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_bluefruit_connect.controller_packet`
23+
`adafruit_bluefruit_connect.location_packet`
2424
====================================================
2525
2626
Bluefruit Connect App geographical location packet.

adafruit_bluefruit_connect/packet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Packet:
5959

6060
@classmethod
6161
def register_packet_type(cls):
62-
"""Register a new packet type, using this class and its `cls._TYPE_HEADER`
62+
"""Register a new packet type, using this class and its ``cls._TYPE_HEADER``.
6363
The ``from_bytes()`` and ``from_stream()`` methods will then be able
6464
to recognize this type of packet.
6565
"""
@@ -97,11 +97,11 @@ def from_stream(cls, stream):
9797
"""Read the next packet from the incoming stream. Wait as long as the timeout
9898
set on stream, using its own preset timeout.
9999
Return None if there was no input, otherwise return an instance
100-
of one of the packet classes registered with `Packet`.
100+
of one of the packet classes registered with ``Packet``.
101101
Raise an Error if the packet was not recognized or was malformed
102102
103103
:param stream stream: an input stream that provides standard stream read operations,
104-
such as `ble.UARTServer` or `busio.UART`.
104+
such as ``ble.UARTServer`` or ``busio.UART``.
105105
"""
106106
header = stream.read(2)
107107
if len(header) != 2 or header[0] != ord(b'!'):

docs/api.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@
66
77
.. automodule:: adafruit_bluefruit_connect
88
:members:
9+
10+
.. automodule:: adafruit_bluefruit_connect.packet
11+
:members:
12+
13+
.. automodule:: adafruit_bluefruit_connect.accelerometer_packet
14+
:members:
15+
16+
.. automodule:: adafruit_bluefruit_connect.button_packet
17+
:members:
18+
19+
.. automodule:: adafruit_bluefruit_connect.color_packet
20+
:members:
21+
22+
.. automodule:: adafruit_bluefruit_connect.gyro_packet
23+
:members:
24+
25+
.. automodule:: adafruit_bluefruit_connect.location_packet
26+
:members:
27+
28+
.. automodule:: adafruit_bluefruit_connect.magnetometer_packet
29+
:members:
30+
31+
.. automodule:: adafruit_bluefruit_connect.quaternion_packet
32+
:members:

docs/examples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/bluefruit_connect_simpletest.py
77
:caption: examples/bluefruit_connect_simpletest.py
88
:linenos:
9+
10+
This test demonstrates controlling an Adafruit Crickit board with Bluetooth.
11+
12+
.. literalinclude:: ../examples/bluefruit_connect_crickit_test.py
13+
:caption: examples/bluefruit_connect_crickit_test.py
14+
:linenos:
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# To be supplied
1+
# Print out the color data from a ColorPacket.
2+
3+
from adafruit_ble.uart import UARTServer
4+
from adafruit_bluefruit_connect.packet import Packet
5+
# Only the packet classes that are imported will be known to Packet.
6+
from adafruit_bluefruit_connect.color_packet import ColorPacket
7+
8+
uart_server = UARTServer()
9+
10+
advertising_now = False
11+
12+
while True:
13+
if not uart_server.connected:
14+
if not advertising_now:
15+
uart_server.start_advertising()
16+
advertising_now = True
17+
continue
18+
19+
# Connected, so no longer advertising
20+
advertising_now = False
21+
22+
packet = Packet.from_stream(uart_server)
23+
if isinstance(packet, ColorPacket):
24+
print(packet.color)

0 commit comments

Comments
 (0)