Skip to content

Commit f454e41

Browse files
committed
[20211213] as requested by @dhalbert, rename TextPacket to RawTextpacket
1 parent eb60724 commit f454e41

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

adafruit_bluefruit_connect/packet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ def from_stream(cls, stream):
104104
break
105105

106106
# Didn't find a packet start.
107-
text_packet_cls = cls._type_to_class.get(b"TX", None)
108-
# Is TextPacket registered?
109-
# If so, read an entire line and pass that to TextPacket.
110-
if text_packet_cls:
107+
raw_text_packet_cls = cls._type_to_class.get(b"RT", None)
108+
# Is RawTextPacket registered?
109+
# If so, read an entire line and pass that to RawTextPacket.
110+
if raw_text_packet_cls:
111111
packet = bytes(start + stream.readline())
112-
return text_packet_cls(packet)
112+
return raw_text_packet_cls(packet)
113113

114114
# else loop and try again.
115115

adafruit_bluefruit_connect/text_packet.py renamed to adafruit_bluefruit_connect/raw_text_packet.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
`adafruit_bluefruit_connect.text_packet`
6+
`adafruit_bluefruit_connect.raw_text_packet`
77
====================================================
88
9-
Bluefruit Connect App text data packet.
9+
Bluefruit Connect App raw text data packet.
1010
11-
Note that the text data packet is different from those used by the
11+
Note that the raw text data packet is different from those used by the
1212
Controller module (e.g. Accelerometer, Control Pad, and Color Picker).
1313
Those use the bytes "!x" (where x is specific to the type of packet),
1414
followed by data specific to the packet, followed by a checksum.
1515
The UART text sender instead sends the bytes followed by a newline.
16-
There is no length indicator, no checksum, etc.
16+
There is no length indicator, no checksum, etc. Of course, that also
17+
precludes the use of an "!" at the beginning of the string.
1718
1819
Consequently, this packet type is MUCH simpler than the other packet types.
1920
@@ -24,13 +25,13 @@
2425
from .packet import Packet
2526

2627

27-
class TextPacket(Packet):
28+
class RawTextPacket(Packet):
2829
"""A packet containing a text string."""
2930

30-
_TYPE_HEADER = b"TX"
31+
_TYPE_HEADER = b"RT"
3132

3233
def __init__(self, text):
33-
"""Construct a TextPacket from a binary string."""
34+
"""Construct a RawTextPacket from a binary string."""
3435
if isinstance(text, bytes):
3536
self._text = text.strip()
3637
else:
@@ -43,4 +44,4 @@ def text(self):
4344

4445

4546
# Register this class with the superclass. This allows the user to import only what is needed.
46-
TextPacket.register_packet_type()
47+
RawTextPacket.register_packet_type()

docs/examples.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ This example demonstrates receiving text from the UART interface.
2424
.. literalinclude:: ../examples/bluefruitconnect_uart.py
2525
:caption: examples/bluefruitconnect_uart.py
2626
:linenos:
27+
28+
This example demonstrates receiving both a color (as in simpletest above)
29+
and raw text (using RawTextPacket).
30+
31+
.. literalinclude:: ../examples/bluefruitconnect_simpletest.py
32+
:caption: examples/bluefruitconnect_simpletest.py
33+
:linenos:
34+

examples/bluefruitconnect_simpletest2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4-
# Print out the color data from ColorPackets and text data from TextPackets.
4+
# Print out the color data from ColorPackets and text data from RawTextPackets.
55
# To use, start this program, and start the Adafruit Bluefruit LE Connect app.
66
# Connect, and then select colors on the Controller->Color Picker screen.
7-
# Select text by entering the UART screen and sending in in a string.
8-
# (Do NOT use a "!" as part of your string.)
7+
# Select text by entering the UART screen and sending a string.
8+
# (Do NOT use a "!" at the start of your string.)
99

1010
from adafruit_ble import BLERadio
1111
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
@@ -14,7 +14,7 @@
1414

1515
# Only the packet classes that are imported will be known to Packet.
1616
from adafruit_bluefruit_connect.color_packet import ColorPacket
17-
from adafruit_bluefruit_connect.text_packet import TextPacket
17+
from adafruit_bluefruit_connect.raw_text_packet import RawTextPacket
1818

1919
ble = BLERadio()
2020
uart_server = UARTService()
@@ -30,6 +30,6 @@
3030
packet = Packet.from_stream(uart_server)
3131
if isinstance(packet, ColorPacket):
3232
print(packet.color)
33-
elif isinstance(packet, TextPacket):
34-
print("Received Text Packet:")
33+
elif isinstance(packet, RawTextPacket):
34+
print("Received Raw Text Packet:")
3535
print(packet.text)

0 commit comments

Comments
 (0)