From 745de9844c234118e59cadc44d6060993a22b129 Mon Sep 17 00:00:00 2001 From: devoh747 Date: Wed, 9 Oct 2019 15:07:19 -0400 Subject: [PATCH 1/2] Fix for Issue #24 added "try" --- examples/ble_color_picker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/ble_color_picker.py b/examples/ble_color_picker.py index 00c5d2f..b434f6a 100755 --- a/examples/ble_color_picker.py +++ b/examples/ble_color_picker.py @@ -17,7 +17,10 @@ pass while uart_server.connected: - packet = Packet.from_stream(uart_server) + try: + packet = Packet.from_stream(uart_server) + except (ValueError, OSError): + pass if isinstance(packet, ColorPacket): print(packet.color) pixels.fill(packet.color) From 7566483e2dbdb1bf6c71d5629a2ed37b113c7cff Mon Sep 17 00:00:00 2001 From: devoh747 Date: Thu, 10 Oct 2019 17:11:07 -0400 Subject: [PATCH 2/2] Update ble_color_picker.py If you use ble_color_picker.py and make more complicated animations like https://github.com/gallaugher/PythonSmartTie you can issue packets faster than you can process them and get a ValueError. I use a try to catch it and print out a message but continue to the next loop iteration which grabs the next packet. This fixes crashes/hangs in John's code.. and I think is helpful in this example code. --- examples/ble_color_picker.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/ble_color_picker.py b/examples/ble_color_picker.py index b434f6a..679e78f 100755 --- a/examples/ble_color_picker.py +++ b/examples/ble_color_picker.py @@ -19,8 +19,9 @@ while uart_server.connected: try: packet = Packet.from_stream(uart_server) - except (ValueError, OSError): - pass + except ValueError: + print("Caught a bad packet with a ValueError, discarding and trying again") + continue if isinstance(packet, ColorPacket): print(packet.color) pixels.fill(packet.color)