Skip to content

Commit 7e8cc9c

Browse files
committed
Merge remote-tracking branch 'adafruit/master'
2 parents 59fa8a2 + b710480 commit 7e8cc9c

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

adafruit_bluefruit_connect/button_packet.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
class ButtonPacket(Packet):
3838
"""A packet containing a button name and its state."""
3939

40-
B_1 = '1'
40+
BUTTON_1 = '1'
4141
"""Code for Button 1 on the Bluefruit LE Connect app Control Pad screen."""
42-
B_2 = '2'
42+
BUTTON_2 = '2'
4343
"""Button 2."""
44-
B_3 = '3'
44+
BUTTON_3 = '3'
4545
"""Button 3."""
46-
B_4 = '4'
47-
"""Button 4"""
46+
BUTTON_4 = '4'
47+
"""Button 4."""
4848
#pylint: disable= invalid-name
4949
UP = '5'
5050
"""Up Button."""
@@ -80,6 +80,7 @@ def __init__(self, button, pressed):
8080
def parse_private(cls, packet):
8181
"""Construct a ButtonPacket from an incoming packet.
8282
Do not call this directly; call Packet.from_bytes() instead.
83+
pylint makes it difficult to call this method _parse(), hence the name.
8384
"""
8485
button, pressed = struct.unpack(cls._FMT_PARSE, packet)
8586
if not pressed in b'01':

adafruit_bluefruit_connect/color_packet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, color):
6060
def parse_private(cls, packet):
6161
"""Construct a ColorPacket from an incoming packet.
6262
Do not call this directly; call Packet.from_bytes() instead.
63+
pylint makes it difficult to call this method _parse(), hence the name.
6364
"""
6465
return cls(struct.unpack(cls._FMT_PARSE, packet))
6566

adafruit_bluefruit_connect/packet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def parse_private(cls, packet):
122122
is not correct.
123123
124124
Do not call this directly. It's called from ``cls.from_bytes()``.
125+
pylint makes it difficult to call this method _parse(), hence the name.
125126
"""
126127
return cls(*struct.unpack(cls._FMT_PARSE, packet))
127128

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Stream accelerometer data from your phone or tablet.
2+
# To use, start this program, and start the Adafruit Bluefruit LE Connect app.
3+
# Connect and go to the Controller screen. Turn on
4+
# STREAM SENSOR DATA -> Accelerometer to send data from the device's
5+
# accelerometer. See how it matches what this prints.
6+
7+
from adafruit_ble.uart import UARTServer
8+
from adafruit_bluefruit_connect.packet import Packet
9+
# Only the packet classes that are imported will be known to Packet.
10+
from adafruit_bluefruit_connect.accelerometer_packet import AccelerometerPacket
11+
12+
uart_server = UARTServer()
13+
14+
while True:
15+
# Advertise when not connected.
16+
uart_server.start_advertising()
17+
while not uart_server.connected:
18+
pass
19+
20+
while uart_server.connected:
21+
packet = Packet.from_stream(uart_server)
22+
if isinstance(packet, AccelerometerPacket):
23+
print(packet.x, packet.y, packet.z)

0 commit comments

Comments
 (0)