Non-blocking mode for LWP3Device #462
Labels
enhancement
New feature or request
platform: Powered Up
Issues related to LEGO Powered Up
software: pybricks-micropython
Issues with Pybricks MicroPython firmware (or EV3 runtime)
topic: bluetooth
Issues involving bluetooth
Is your feature request related to a problem? Please describe.
pybricks/pybricks-micropython#68 added a new
LWP3Device
class for communicating with hubs running the LEGO Wireless Protocol v3. Due to current limitations of the Pybricks Bluetooth drivers, it only operates in a blocking mode. When writing, a BLE Write With Response is performed and the method blocks until the response is received from the other hub. When reading, the method blocks until new data has been received (unless new data was already received since the last read).Programs cannot perform some parallel tasks while these methods are blocking.
Describe the solution you'd like
The
LWP3Device
constructor should have ablocking=True
argument. When set toFalse
, the behavior of the read and write methods changes to follow the Python non-blocking pattern. The write method will use Write Without Response. If the Bluetooth chip is busy and the message cannot be sent right away, the method returnsNone
. When reading, if no new messages have been received since the last read, the method returnsNone
.Describe alternatives you've considered
?
Additional context
The main blocker here is properly implementing Write Without Response in the Bluetooth drivers. For example, #417 indicates that there are some issues with the current implementation.
The text was updated successfully, but these errors were encountered: