From 646cdd8afdb302368cf94102c99ffcf7f0986882 Mon Sep 17 00:00:00 2001 From: Nina Zakharenko Date: Sat, 13 Jun 2020 22:58:13 -0700 Subject: [PATCH 1/2] Rename uart_server to uart_service for consistency --- examples/ble_bluefruit_color_picker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ble_bluefruit_color_picker.py b/examples/ble_bluefruit_color_picker.py index b5360e0..dbde5d8 100755 --- a/examples/ble_bluefruit_color_picker.py +++ b/examples/ble_bluefruit_color_picker.py @@ -9,8 +9,8 @@ from adafruit_bluefruit_connect.color_packet import ColorPacket ble = BLERadio() -uart_server = UARTService() -advertisement = ProvideServicesAdvertisement(uart_server) +uart_service = UARTService() +advertisement = ProvideServicesAdvertisement(uart_service) pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1) @@ -22,7 +22,7 @@ ble.stop_advertising() while ble.connected: - packet = Packet.from_stream(uart_server) + packet = Packet.from_stream(uart_service) if isinstance(packet, ColorPacket): print(packet.color) pixels.fill(packet.color) From cceaf0de1ee4ac7e93c5ee7611a81f0eaa018aea Mon Sep 17 00:00:00 2001 From: Nina Zakharenko Date: Sat, 13 Jun 2020 22:59:12 -0700 Subject: [PATCH 2/2] Check if UARTService is in waiting before reading Stream --- examples/ble_bluefruit_color_picker.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/ble_bluefruit_color_picker.py b/examples/ble_bluefruit_color_picker.py index dbde5d8..2b197af 100755 --- a/examples/ble_bluefruit_color_picker.py +++ b/examples/ble_bluefruit_color_picker.py @@ -22,7 +22,8 @@ ble.stop_advertising() while ble.connected: - packet = Packet.from_stream(uart_service) - if isinstance(packet, ColorPacket): - print(packet.color) - pixels.fill(packet.color) + if uart_service.in_waiting: + packet = Packet.from_stream(uart_service) + if isinstance(packet, ColorPacket): + print(packet.color) + pixels.fill(packet.color)