Skip to content

Improve tests and documentation #6

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 3 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions adafruit_bluefruit_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -32,7 +32,7 @@

**Hardware:**

inline format: "* `Adafruit Feather nRF52840 Express <https://www.adafruit.com/product/4062>`_"
Adafruit Feather nRF52840 Express <https://www.adafruit.com/product/4062>

**Software and Dependencies:**

Expand Down
2 changes: 1 addition & 1 deletion adafruit_bluefruit_connect/button_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion adafruit_bluefruit_connect/location_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions adafruit_bluefruit_connect/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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'!'):
Expand Down
24 changes: 24 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@

.. automodule:: adafruit_bluefruit_connect
:members:

.. 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:
6 changes: 6 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
25 changes: 24 additions & 1 deletion examples/bluefruit_connect_simpletest.py
Original file line number Diff line number Diff line change
@@ -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)