Skip to content

Commit dae118e

Browse files
committed
Try and make pylint happy
1 parent 2230a12 commit dae118e

File tree

1 file changed

+28
-26
lines changed
  • Metro/Metro_RP2350_Match3/match3_game

1 file changed

+28
-26
lines changed

Metro/Metro_RP2350_Match3/match3_game/code.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
GameOverException,
3434
)
3535

36-
_MOUSE_SYNC = []
37-
3836
original_autoreload_val = supervisor.runtime.autoreload
3937
supervisor.runtime.autoreload = False
4038

@@ -103,7 +101,6 @@
103101
# so use it for save data
104102
save_to = "/sd/set_game_autosave.dat"
105103
except OSError as e:
106-
print(f'no SDcard {e}')
107104
# no SDcard
108105
pass
109106

@@ -247,26 +244,31 @@
247244
mouse_bufs = []
248245
# debouncers list for debouncing mouse left clicks
249246
mouse_debouncers = []
247+
mouse_sync = []
250248

251249
# scan for connected USB devices
252250
for device in usb.core.find(find_all=True):
253251
# check if current device is has a boot mouse endpoint
254-
mouse_interface_index, mouse_endpoint_address = (
255-
adafruit_usb_host_descriptors.find_boot_mouse_endpoint(device)
256-
)
257-
if mouse_interface_index is not None and mouse_endpoint_address is not None:
258-
# if it does have a boot mouse endpoint then add information to the
259-
# usb info lists
260-
mouse_interface_indexes.append(mouse_interface_index)
261-
mouse_endpoint_addresses.append(mouse_endpoint_address)
262-
263-
# add the mouse device instance to list
264-
mice.append(device)
265-
print(
266-
f"mouse interface: {mouse_interface_index} "
267-
+ f"endpoint_address: {hex(mouse_endpoint_address)}"
252+
try:
253+
mouse_interface_index, mouse_endpoint_address = (
254+
adafruit_usb_host_descriptors.find_boot_mouse_endpoint(device)
268255
)
269-
_MOUSE_SYNC.append(0)
256+
if mouse_interface_index is not None and mouse_endpoint_address is not None:
257+
# if it does have a boot mouse endpoint then add information to the
258+
# usb info lists
259+
mouse_interface_indexes.append(mouse_interface_index)
260+
mouse_endpoint_addresses.append(mouse_endpoint_address)
261+
262+
# add the mouse device instance to list
263+
mice.append(device)
264+
print(
265+
f"mouse interface: {mouse_interface_index} "
266+
+ f"endpoint_address: {hex(mouse_endpoint_address)}"
267+
)
268+
mouse_sync.append(0)
269+
except usb.core.USBError as e:
270+
# The mouse might have glitched and may not be detected but at least we don't crash
271+
print(e)
270272

271273
# detach kernel driver if needed
272274
kernel_driver_active_flags.append(device.is_kernel_driver_active(0))
@@ -336,28 +338,27 @@ def is_right_mouse_clicked(buf):
336338
winner = None
337339

338340

339-
def get_mouse_deltas(buffer, read_count, mouse_indx):
341+
def get_mouse_deltas(buffer, read_count, sync):
340342
"""
341343
Given a mouse packet buffer and a read count of number of bytes read,
342344
return the delta x and y values of the mouse.
343345
:param buffer: the buffer containing the packet data
344346
:param read_count: the number of bytes read from the mouse
345347
:return: tuple containing x and y delta values
346348
"""
347-
global _MOUSE_SYNC
348-
if read_count == 4 or (read_count == 8 and _MOUSE_SYNC[mouse_indx] > 50):
349+
if read_count == 4 or (read_count == 8 and sync > 50):
349350
delta_x = buffer[1]
350351
delta_y = buffer[2]
351352
elif read_count == 8:
352353
delta_x = buffer[2]
353354
delta_y = buffer[4]
354355
if delta_y != 0:
355-
_MOUSE_SYNC[mouse_indx] = -999
356-
elif delta_y == 0 and _MOUSE_SYNC[mouse_indx] > -1:
357-
_MOUSE_SYNC[mouse_indx] += 1
356+
sync = -999
357+
elif delta_y == 0 and sync > -1:
358+
sync += 1
358359
else:
359360
raise ValueError(f"Unsupported mouse packet size: {read_count}, must be 4 or 8")
360-
return delta_x, delta_y
361+
return delta_x, delta_y, sync
361362

362363

363364
def atexit_callback():
@@ -394,7 +395,8 @@ def atexit_callback():
394395
data_len = mouse.read(
395396
mouse_endpoint_addresses[i], mouse_bufs[i], timeout=20
396397
)
397-
mouse_deltas = get_mouse_deltas(mouse_bufs[i], data_len, i)
398+
mouse_deltas = get_mouse_deltas(mouse_bufs[i], data_len, mouse_sync[i])
399+
mouse_sync[i] = mouse_deltas[2]
398400
# if we got data, then update the mouse cursor on the display
399401
# using min and max to keep it within the bounds of the display
400402
mouse_tg.x = max(

0 commit comments

Comments
 (0)