adafruit_bluefruit_connect
¶
This module helps you to communicate with the Adafruit Bluefruit Connect App or use its protocols with boards that run Adafruit CircuitPython firmware.
Author(s): Dan Halbert for Adafruit Industries
adafruit_bluefruit_connect.packet
¶
Bluefruit Connect App packet superclass
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.packet.Packet¶
A Bluefruit app controller packet. A packet consists of these bytes, in order:
‘!’ - The first byte is always an exclamation point.
type - A single byte designating the type of packet: b’A’, b’B’, etc.
data … - Multiple bytes of data, varying by packet type.
checksum - A single byte checksum, computed by adding up all the data bytes and inverting the sum.
This is an abstract class.
- add_checksum(partial_packet: bytes) bytes ¶
Compute the checksum of partial_packet and return a new bytes with the checksum appended.
- static checksum(partial_packet: bytes) int ¶
Compute checksum for bytes, not including the checksum byte itself.
- classmethod from_bytes(packet: bytes) Packet ¶
Create an appropriate object of the correct class for the given packet bytes. Validate packet type, length, and checksum.
- classmethod from_stream(stream: RawIOBase) Packet | None ¶
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
. Raise an Error if the packet was not recognized or was malformed.If a packet of type “RT” (like
RawTextPacket
) is registered, it will be used to return the raw data line when no packet type was recognized.- Parameters:
stream (stream) – an input stream that provides standard stream read operations, such as
ble.UARTServer
orbusio.UART
.
- classmethod parse_private(packet: bytes) Packet | None ¶
Default implementation for subclasses. Assumes arguments to
__init__()
are exactly the values parsed usingcls._FMT_PARSE
. Subclasses may need to reimplement if that assumption is not correct.Do not call this directly. It’s called from
cls.from_bytes()
. pylint makes it difficult to call this method _parse(), hence the name.
adafruit_bluefruit_connect.accelerometer_packet
¶
Bluefruit Connect App Accelerometer data packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.accelerometer_packet.AccelerometerPacket(x: float, y: float, z: float)¶
A packet of x, y, z float values from an accelerometer.
- class adafruit_bluefruit_connect.button_packet.ButtonPacket(button: str, pressed: bool)¶
A packet containing a button name and its state.
Construct a ButtonPacket from a button name and the button’s state.
- Parameters:
- property button: str¶
A single character string (not bytes) specifying the button that the user pressed or released.
adafruit_bluefruit_connect.color_packet
¶
Bluefruit Connect App color data packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.color_packet.ColorPacket(color: Tuple)¶
A packet containing an RGB color value.
Construct a ColorPacket from a 3-element
tuple
of RGB values, or from an int color value 0xRRGGBB.- Parameters:
color (tuple/int) – an RGB
tuple
(red, green, blue)
or an int color value0xRRGGBB
- property color: tuple¶
A
tuple
(red, green blue)
representing the color the user chose in the BlueFruit Connect app.
adafruit_bluefruit_connect.gyro_packet
¶
Bluefruit Connect App Gyro data packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.gyro_packet.GyroPacket(x: float, y: float, z: float)¶
A packet of x, y, z float values from a gyroscope.
adafruit_bluefruit_connect.location_packet
¶
Bluefruit Connect App geographical location packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.location_packet.LocationPacket(latitude: float, longitude: float, altitude: float)¶
A packet of latitude, longitude, and altitude values.
Construct a LocationPacket from the given values.
adafruit_bluefruit_connect.magnetometer_packet
¶
Bluefruit Connect App Magnetometer data packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.magnetometer_packet.MagnetometerPacket(x: float, y: float, z: float)¶
A packet of x, y, z float values from a magnetometer.
adafruit_bluefruit_connect.quaternion_packet
¶
Bluefruit Connect App Quaternion data packet.
Author(s): Dan Halbert for Adafruit Industries
- class adafruit_bluefruit_connect.quaternion_packet.QuaternionPacket(x: float, y: float, z: float, w: float)¶
Device Motion data to describe device attitude. This data is derived from Accelerometer, Gyro, and Magnetometer readings.
Construct a QuaternionPacket from the given x, y, z, and w float values.
adafruit_bluefruit_connect.raw_text_packet
¶
Bluefruit Connect App raw text data packet.
Note that the raw text data packet is different from those used by the Controller module (e.g. Accelerometer, Control Pad, and Color Picker). Those use the bytes “!x” (where x is specific to the type of packet), followed by data specific to the packet, followed by a checksum. The UART text sender instead sends the bytes followed by a newline. There is no length indicator, no checksum, etc. Of course, that also precludes the use of an “!” at the beginning of the string.
Consequently, this packet type is MUCH simpler than the other packet types.
Author(s): Tony Hansen