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..c32ec68 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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: 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 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)