From 105a2c7e197ddebfbbe5310c6c71279480ed605d Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 24 Jan 2026 16:02:53 -0600 Subject: [PATCH] pybricks.connections.pybricks: Clear halt on endpoints instead of resetting device. Change how we ensure the USB endpoints are in a good state when connecting to a device. Instead of resetting the device, which is not supported on all platforms, we now clear the halt condition on both endpoints. We were doing the reset to ensure that the even/odd data toggle state was correct. The reset, if supported, would completely reset the connection and re-enumerate the device, which is more that we need. On Windows, resetting is not supported and libusb would poke all endpoints like this as a best-effort approximation of a reset. So now, the code reflects what is actually important and will be helpful if we switch to something other than pyusb in the future. --- pybricksdev/connections/pybricks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pybricksdev/connections/pybricks.py b/pybricksdev/connections/pybricks.py index 8b76c1d..634b25e 100644 --- a/pybricksdev/connections/pybricks.py +++ b/pybricksdev/connections/pybricks.py @@ -946,8 +946,6 @@ def __init__(self, device: USBDevice): self._response_queue = asyncio.Queue[bytes]() async def _client_connect(self) -> bool: - # Reset is essential to ensure endpoints are in a good state. - self._device.reset() self._device.set_configuration() # Save input and output endpoints @@ -964,6 +962,12 @@ async def _client_connect(self) -> bool: == ENDPOINT_OUT, ) + # Clearing halt (even if not stalled) resets the even/odd state on the + # endpoints in case it was left in an invalid state by a previous + # connection. + self._ep_in.clear_halt() + self._ep_out.clear_halt() + # There is 1 byte overhead for PybricksUsbMessageType self._max_write_size = self._ep_out.wMaxPacketSize - 1