adafruit / Adafruit_CircuitPython_BluefruitConnect

This module helps you to communicate with the Adafruit Bluefruit Connect app or use its protocols
MIT License
17 stars 16 forks source link

Add support for a TextPacket, as sent using the UART module in the Ad… #33

Closed TonyLHansen closed 2 years ago

TonyLHansen commented 2 years ago

Add support for a TextPacket, as sent using the UART module in the AdaFruit BlueTooth app

This code provides an exception case to the Packet creation logic, similar to how the sample Arduino BLE code for the LED Glasses also has an exception case when the UART stream has data that does not start with a "!".

TonyLHansen commented 2 years ago

@FoamyGuy, I decided to add a separate simpletest2.py example.

dhalbert commented 2 years ago

OK, I see that if you find unknown characters, you turn it into a TextPacket. One reason for not doing this in the past is that if you get out of sync, and miss a beginning "!" in another packet, then you'll read text as a TextPacket indefinitely until the data happens to have a byte that is a newline.

If we do want to send arbitrary text, then perhaps we should add a real text packet type, with a header, and update the app. Then we can send the packet with a length header or similar.

TonyLHansen commented 2 years ago

@dhalbert, You are correct that it is possible for the packets to get out of sync if characters are missed.

However:

Possibly most important from my point of view:

I don't disagree with your statement that updating the app to have a real "send text" capability would be useful. However I think that approach can be dealt with separately, and shouldn't prevent changes that work with the current version of the app.

dhalbert commented 2 years ago

@TonyLHansen Thanks for the reply. I was missing the context of this change - I apologize if I seemed critical. Other people have asked for text packet functionality in the past, and were expecting a "!"-type packet.

How about we call this RawTextPacket or TextRawPacket, to distinguish its unusual data handling? If a regular text packet is added in the future, we can add a TextPacket class that does the usual header processing.

I would be fine with this PR after that.