Skip to content

Udpates #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions adafruit_usb_host_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ class BootMouse:
:param was_attached: Whether the usb device was attached to the kernel
"""

def __init__(self, device, endpoint_address, tilegrid, was_attached):
def __init__(self, device, endpoint_address, tilegrid, was_attached, scale=1): # noqa: PLR0913, too many args
self.device = device
self.tilegrid = tilegrid
self.endpoint = endpoint_address
self.buffer = array.array("b", [0] * 8)
self.buffer = array.array("b", [0] * 4)
self.was_attached = was_attached
self.scale = scale

self.display_size = (supervisor.runtime.display.width, supervisor.runtime.display.height)

Expand All @@ -129,13 +130,21 @@ def x(self):
"""
return self.tilegrid.x

@x.setter
def x(self, new_x):
self.tilegrid.x = new_x

@property
def y(self):
"""
The y coordinate of the mouse cursor
"""
return self.tilegrid.y

@y.setter
def y(self, new_y):
self.tilegrid.y = new_y

def release(self):
"""
Release the mouse cursor and re-attach it to the kernel
Expand All @@ -160,11 +169,17 @@ def update(self):
except usb.core.USBTimeoutError:
# skip the rest if there is no data
return None
except usb.core.USBError:
return None

# update the mouse tilegrid x and y coordinates
# based on the delta values read from the mouse
self.tilegrid.x = max(0, min((self.display_size[0]) - 1, self.tilegrid.x + self.buffer[1]))
self.tilegrid.y = max(0, min((self.display_size[1]) - 1, self.tilegrid.y + self.buffer[2]))
self.tilegrid.x = max(
0, min((self.display_size[0] // self.scale) - 1, self.tilegrid.x + self.buffer[1])
)
self.tilegrid.y = max(
0, min((self.display_size[1] // self.scale) - 1, self.tilegrid.y + self.buffer[2])
)

pressed_btns = []
for i, button in enumerate(BUTTONS):
Expand Down