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)¶ Compute the checksum of partial_packet and return a new bytes with the checksum appended.
-
static
checksum
(partial_packet)¶ Compute checksum for bytes, not including the checksum byte itself.
-
classmethod
from_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)¶ 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 malformedParameters: stream (stream) – an input stream that provides standard stream read operations, such as ble.UARTServer
orbusio.UART
.
-
classmethod
parse_private
(packet)¶ 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.
-
classmethod
register_packet_type
()¶ Register a new packet type, using this class and its
cls._TYPE_HEADER
. Thefrom_bytes()
andfrom_stream()
methods will then be able to recognize this type of packet.
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, y, z)¶ A packet of x, y, z float values from an accelerometer.
adafruit_bluefruit_connect.button_packet
¶
Bluefruit Connect App Button data packet (button_name, pressed/released)
- Author(s): Dan Halbert for Adafruit Industries
A packet containing a button name and its state.
Construct a ButtonPacket from a button name and the button’s state.
Parameters: Code for Button 1 on the Bluefruit LE Connect app Control Pad screen.
Button 2.
Button 3.
Button 4.
Down Button.
Left Button.
Right Button.
Up Button.
A single character string (not bytes) specifying the button that the user pressed or released.
Construct a ButtonPacket from an incoming packet. Do not call this directly; call Packet.from_bytes() instead. pylint makes it difficult to call this method _parse(), hence the name.
True
if button is pressed, orFalse
if it is released.
Return the bytes needed to send this packet.
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)¶ 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
-
color
¶ A
tuple
(red, green blue)
representing the color the user chose in the BlueFruit Connect app.
-
classmethod
parse_private
(packet)¶ Construct a ColorPacket from an incoming packet. Do not call this directly; call Packet.from_bytes() instead. pylint makes it difficult to call this method _parse(), hence the name.
-
to_bytes
()¶ Return the bytes needed to send this packet.
-
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, y, z)¶ 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, longitude, altitude)¶ A packet of latitude, longitude, and altitude values.
Construct a LocationPacket from the given values.
-
altitude
¶ The altitude value.
-
latitude
¶ The latitude value.
-
longitude
¶ The longitude value.
-
to_bytes
()¶ Return the bytes needed to send this packet.
-
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, y, z)¶ 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, y, z, w)¶ 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.
-
to_bytes
()¶ Return the bytes needed to send this packet.
-
w
¶ The w value.
-