Skip to content

Commit 1b3bee5

Browse files
authored
Merge pull request #9 from relic-se/usb-errors
Improve return value of `BootMouse.update`
2 parents 1744cd2 + e201622 commit 1b3bee5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Usage Example
134134
out_str = f"{mouse.x},{mouse.y}"
135135
136136
# add pressed buttons to out str
137-
if pressed_btns is not None:
137+
if pressed_btns is not None and len(pressed_btns) > 0:
138138
out_str += f" {" ".join(pressed_btns)}"
139139
140140
# update the text label with the new coordinates

adafruit_usb_host_mouse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ def update(self):
186186
Read data from the USB mouse and update the location of the visible cursor
187187
and check if any buttons are pressed.
188188
189-
:return: a List containing one or more of the strings "left", "right", "middle"
190-
indicating which buttons are pressed.
189+
:return: a tuple containing one or more of the strings "left", "right", "middle"
190+
indicating which buttons are pressed. If no buttons are pressed, the tuple will be empty.
191+
If a error occurred while trying to read from the usb device, `None` will be returned.
191192
"""
192193
try:
193194
# attempt to read data from the mouse
@@ -226,5 +227,4 @@ def update(self):
226227
# it is being clicked.
227228
pressed_btns.append(button)
228229

229-
if len(pressed_btns) > 0:
230-
return pressed_btns
230+
return tuple(pressed_btns)

examples/usb_host_mouse_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
out_str = f"{mouse.x},{mouse.y}"
4747

4848
# add pressed buttons to out str
49-
if pressed_btns is not None:
49+
if pressed_btns is not None and len(pressed_btns) > 0:
5050
out_str += f" {" ".join(pressed_btns)}"
5151

5252
# update the text label with the new coordinates

0 commit comments

Comments
 (0)