Skip to content

Commit c9eca4b

Browse files
committed
Add support for a TextPacket, as sent using the UART module in the AdaFruit BlueTooth app
1 parent c24bc05 commit c9eca4b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

adafruit_bluefruit_connect/packet.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,17 @@ def from_stream(cls, stream):
101101
# Timeout: nothing more read.
102102
return None
103103
break
104-
# Didn't find a packet start. Loop and try again.
104+
# Didn't find a packet start.
105+
else:
106+
text_packet_cls = cls._type_to_class.get(b"TX", None)
107+
# Is TextPacket registered?
108+
# If so, read an entire line and pass that to TextPacket.
109+
if text_packet_cls:
110+
ln = stream.readline()
111+
packet = bytes(start + ln)
112+
return text_packet_cls(packet)
113+
114+
# else loop and try again.
105115

106116
header = bytes(start + packet_type)
107117
packet_class = cls._type_to_class.get(header, None)

adafruit_bluefruit_connect/text_packet.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
2222
"""
2323

24-
import struct
25-
2624
from .packet import Packet
2725

2826

0 commit comments

Comments
 (0)