Skip to content

Commit 39bca08

Browse files
committed
detach all interface belonging to HID config
1 parent 8fe13ca commit 39bca08

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

adafruit_usb_host_mouse/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,15 @@ def find_and_init_report_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
177177
except usb.core.USBError as e:
178178
print_exception(e, e, None)
179179

180-
mouse_was_attached = None
180+
mouse_was_attached = False
181181
if mouse_device is not None:
182182
# detach the kernel driver if needed
183-
if mouse_device.is_kernel_driver_active(mouse_interface_index):
184-
mouse_was_attached = True
185-
mouse_device.detach_kernel_driver(mouse_interface_index)
186-
else:
187-
mouse_was_attached = False
183+
# Typically HID devices have interfaces 0,1,2
184+
# Trying 0..mouse_iface is safe and sufficient
185+
for intf in range(mouse_interface_index + 1):
186+
if mouse_device.is_kernel_driver_active(intf):
187+
mouse_was_attached = True
188+
mouse_device.detach_kernel_driver(intf)
188189

189190
# set configuration on the mouse so we can use it
190191
mouse_device.set_configuration()

0 commit comments

Comments
 (0)