Skip to content

Commit 95cfdff

Browse files
committed
add interface index to BOOTMOUSE class
1 parent 9e84953 commit 95cfdff

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

adafruit_usb_host_mouse/__init__.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def find_and_init_boot_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
9595
mouse_was_attached = None
9696
if mouse_device is not None:
9797
# detach the kernel driver if needed
98-
if mouse_device.is_kernel_driver_active(0):
98+
if mouse_device.is_kernel_driver_active(mouse_interface_index):
9999
mouse_was_attached = True
100-
mouse_device.detach_kernel_driver(0)
100+
mouse_device.detach_kernel_driver(mouse_interface_index)
101101
else:
102102
mouse_was_attached = False
103103

@@ -117,7 +117,13 @@ def find_and_init_boot_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
117117
else:
118118
mouse_tg = None
119119

120-
return BootMouse(mouse_device, mouse_endpoint_address, mouse_was_attached, mouse_tg)
120+
return BootMouse(
121+
mouse_device,
122+
mouse_interface_index,
123+
mouse_endpoint_address,
124+
mouse_was_attached,
125+
mouse_tg
126+
)
121127

122128
# if no mouse found
123129
return None
@@ -174,9 +180,9 @@ def find_and_init_report_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
174180
mouse_was_attached = None
175181
if mouse_device is not None:
176182
# detach the kernel driver if needed
177-
if mouse_device.is_kernel_driver_active(0):
183+
if mouse_device.is_kernel_driver_active(mouse_interface_index):
178184
mouse_was_attached = True
179-
mouse_device.detach_kernel_driver(0)
185+
mouse_device.detach_kernel_driver(mouse_interface_index)
180186
else:
181187
mouse_was_attached = False
182188

@@ -196,7 +202,13 @@ def find_and_init_report_mouse(cursor_image=DEFAULT_CURSOR): # noqa: PLR0912
196202
else:
197203
mouse_tg = None
198204

199-
return ReportMouse(mouse_device, mouse_endpoint_address, mouse_was_attached, mouse_tg)
205+
return ReportMouse(
206+
mouse_device,
207+
mouse_interface_index,
208+
mouse_endpoint_address,
209+
mouse_was_attached,
210+
mouse_tg
211+
)
200212

201213
# if no mouse found
202214
return None
@@ -209,19 +221,30 @@ class BootMouse:
209221
were pressed.
210222
211223
:param device: The usb device instance for the mouse
224+
:param interface_index: The USB interface index of the mouse
212225
:param endpoint_address: The address of the mouse endpoint
213226
:param was_attached: Whether the usb device was attached to the kernel
214227
:param tilegrid: The TileGrid that holds the visible mouse cursor
215228
:param scale: The scale of the group that the Mouse TileGrid will be put into.
216229
Needed in order to properly clamp the mouse to the display bounds
217230
"""
218231

219-
def __init__(self, device, endpoint_address, was_attached, tilegrid=None, scale=1): # noqa: PLR0913, too many args
232+
def __init__(
233+
self,
234+
device,
235+
interface_index,
236+
endpoint_address,
237+
was_attached,
238+
tilegrid=None,
239+
scale=1
240+
): # noqa: PLR0913, too many args
241+
220242
self.device = device
221243

222244
self.tilegrid = tilegrid
223245
"""TileGrid containing the Mouse cursor graphic."""
224246

247+
self.interface = interface_index
225248
self.endpoint = endpoint_address
226249
self.buffer = array.array("b", [0] * 4)
227250
self.was_attached = was_attached
@@ -337,8 +360,24 @@ def update(self):
337360

338361

339362
class ReportMouse(BootMouse):
340-
def __init__(self, device, endpoint_address, was_attached, tilegrid=None, scale=1): # noqa: PLR0913, too many args
341-
super().__init__(device, endpoint_address, was_attached, tilegrid, scale)
363+
def __init__(
364+
self,
365+
device,
366+
interface_index,
367+
endpoint_address,
368+
was_attached,
369+
tilegrid=None,
370+
scale=1
371+
): # noqa: PLR0913, too many args
372+
373+
super().__init__(
374+
device,
375+
interface_index,
376+
endpoint_address,
377+
was_attached,
378+
tilegrid,
379+
scale
380+
)
342381

343382
def update(self):
344383
"""

0 commit comments

Comments
 (0)