Skip to content

Commit 5e232c3

Browse files
committed
return list of interface in was_attached
1 parent 916116c commit 5e232c3

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

adafruit_usb_host_mouse/__init__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,12 @@ def find_and_init_boot_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
9292
except usb.core.USBError as e:
9393
print_exception(e, e, None)
9494

95-
mouse_was_attached = None
95+
mouse_was_attached = []
9696
if mouse_device is not None:
9797
# detach the kernel driver if needed
9898
if mouse_device.is_kernel_driver_active(mouse_interface_index):
99-
mouse_was_attached = True
99+
mouse_was_attached = [[mouse_interface_index]]
100100
mouse_device.detach_kernel_driver(mouse_interface_index)
101-
else:
102-
mouse_was_attached = False
103101

104102
# set configuration on the mouse so we can use it
105103
mouse_device.set_configuration()
@@ -177,15 +175,19 @@ def find_and_init_report_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
177175
except usb.core.USBError as e:
178176
print_exception(e, e, None)
179177

180-
mouse_was_attached = False
178+
mouse_was_attached = []
179+
_attach_list = []
181180
if mouse_device is not None:
182181
# detach the kernel driver if needed
183182
# Typically HID devices have interfaces 0,1,2
184183
for intf in range(3):
185184
if mouse_device.is_kernel_driver_active(intf):
186-
mouse_was_attached = True
185+
_attach_list.append(intf)
187186
mouse_device.detach_kernel_driver(intf)
188187

188+
if len(_attach_list) > 0:
189+
mouse_was_attached = [_attach_list]
190+
189191
# set configuration on the mouse so we can use it
190192
mouse_device.set_configuration()
191193

@@ -299,8 +301,12 @@ def release(self):
299301
Release the mouse cursor and re-attach it to the kernel
300302
if it was attached previously.
301303
"""
302-
if self.was_attached and not self.device.is_kernel_driver_active(0):
303-
self.device.attach_kernel_driver(0)
304+
# was_attached is an empty list if no interfaces were detached from the kernel
305+
if self.was_attached:
306+
# the first element of the was_attached list is a list of detached interfaces
307+
for intf in self.was_attached[0]:
308+
if not self.device.is_kernel_driver_active(intf):
309+
self.device.attach_kernel_driver(intf)
304310

305311
def update(self):
306312
"""

0 commit comments

Comments
 (0)