Skip to content

Commit 443647c

Browse files
committed
Check first 3 interface for report mice, fix crash on missing resume file
1 parent 67fadb5 commit 443647c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Metro/Metro_RP2350_Match3/match3_game/code.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,20 +291,22 @@
291291
detached = []
292292

293293
# Typically HID devices have interfaces 0,1,2
294-
# Trying 0..mouse_iface is safe and sufficient
295-
for intf in range(mouse_interface_index + 1):
294+
for intf in range(3):
295+
print(f'interface: {intf} ',end="")
296296
try:
297297
if device.is_kernel_driver_active(intf):
298298
device.detach_kernel_driver(intf)
299299
detached.append(intf)
300300
print(f"Detached kernel driver from interface {intf}")
301+
else:
302+
print("not active")
301303
except usb.core.USBError as e:
302304
print(e)
303305

304306
detached_interfaces.append(detached)
305307

306308
# set the mouse configuration so it can be used
307-
device.set_configuration()
309+
#device.set_configuration()
308310

309311
except usb.core.USBError as e:
310312
# The mouse might have glitched and may not be detected but at least we don't crash
@@ -316,6 +318,9 @@
316318
if len(mice) >= 2:
317319
break
318320

321+
for device in mice:
322+
device.set_configuration()
323+
319324
def is_mouse1_left_clicked():
320325
"""
321326
Check if mouse 1 left click is pressed

Metro/Metro_RP2350_Match3/match3_game/match3_game_helpers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,13 @@ def handle_left_click(self, player_index, coords):
663663
and self.title_screen.resume_btn.contains(coords)
664664
):
665665

666-
# load the game from the given game state
667-
self.load_from_game_state(self.game_state)
668-
# hide the title screen
669-
self.title_screen.hidden = True
670-
# set the current state to open play
671-
self.cur_state = STATE_PLAYING_OPEN
666+
if self.game_state is not None:
667+
# load the game from the given game state
668+
self.load_from_game_state(self.game_state)
669+
# hide the title screen
670+
self.title_screen.hidden = True
671+
# set the current state to open play
672+
self.cur_state = STATE_PLAYING_OPEN
672673

673674
# if the new game button was clicked
674675
elif self.title_screen.new_game_btn.contains(coords):

0 commit comments

Comments
 (0)