diff --git a/adafruit_usb_host_mouse.py b/adafruit_usb_host_mouse.py index 236006a..33f1abe 100644 --- a/adafruit_usb_host_mouse.py +++ b/adafruit_usb_host_mouse.py @@ -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) @@ -129,6 +130,10 @@ def x(self): """ return self.tilegrid.x + @x.setter + def x(self, new_x): + self.tilegrid.x = new_x + @property def y(self): """ @@ -136,6 +141,10 @@ def y(self): """ 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 @@ -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):