Skip to content

Commit 1744cd2

Browse files
authored
Merge pull request #6 from FoamyGuy/sensitivity
add sensitivity property
2 parents 2512503 + dd20cff commit 1744cd2

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

adafruit_usb_host_mouse.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,50 @@ class BootMouse:
127127
:param endpoint_address: The address of the mouse endpoint
128128
:param tilegrid: The TileGrid that holds the visible mouse cursor
129129
:param was_attached: Whether the usb device was attached to the kernel
130+
:param scale: The scale of the group that the Mouse TileGrid will be put into.
131+
Needed in order to properly clamp the mouse to the display bounds
130132
"""
131133

132134
def __init__(self, device, endpoint_address, tilegrid, was_attached, scale=1): # noqa: PLR0913, too many args
133135
self.device = device
136+
134137
self.tilegrid = tilegrid
138+
"""TileGrid containing the Mouse cursor graphic."""
139+
135140
self.endpoint = endpoint_address
136141
self.buffer = array.array("b", [0] * 4)
137142
self.was_attached = was_attached
143+
138144
self.scale = scale
145+
"""The scale of the group that the Mouse TileGrid will be put into.
146+
Needed in order to properly clamp the mouse to the display bounds."""
147+
148+
self.sensitivity = 1
149+
"""The sensitivity of the mouse cursor. Larger values will make
150+
the mouse cursor move slower relative to physical mouse movement. Default is 1."""
139151

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

142154
@property
143-
def x(self):
155+
def x(self) -> int:
144156
"""
145157
The x coordinate of the mouse cursor
146158
"""
147159
return self.tilegrid.x
148160

149161
@x.setter
150-
def x(self, new_x):
162+
def x(self, new_x: int) -> None:
151163
self.tilegrid.x = new_x
152164

153165
@property
154-
def y(self):
166+
def y(self) -> int:
155167
"""
156168
The y coordinate of the mouse cursor
157169
"""
158170
return self.tilegrid.y
159171

160172
@y.setter
161-
def y(self, new_y):
173+
def y(self, new_y: int) -> None:
162174
self.tilegrid.y = new_y
163175

164176
def release(self):
@@ -191,10 +203,18 @@ def update(self):
191203
# update the mouse tilegrid x and y coordinates
192204
# based on the delta values read from the mouse
193205
self.tilegrid.x = max(
194-
0, min((self.display_size[0] // self.scale) - 1, self.tilegrid.x + self.buffer[1])
206+
0,
207+
min(
208+
(self.display_size[0] // self.scale) - 1,
209+
self.tilegrid.x + int(round((self.buffer[1] / self.sensitivity), 0)),
210+
),
195211
)
196212
self.tilegrid.y = max(
197-
0, min((self.display_size[1] // self.scale) - 1, self.tilegrid.y + self.buffer[2])
213+
0,
214+
min(
215+
(self.display_size[1] // self.scale) - 1,
216+
self.tilegrid.y + int(round((self.buffer[2] / self.sensitivity), 0)),
217+
),
198218
)
199219

200220
pressed_btns = []

0 commit comments

Comments
 (0)