From 4639e2af9b0618c2433a6e47e99df84733bdcd0e Mon Sep 17 00:00:00 2001 From: gal20 <71563441+gal20@users.noreply.github.com> Date: Fri, 15 Jan 2021 12:22:20 +0200 Subject: [PATCH] Fix issues with auto-detecting on older joycond versions --- joycond-cemuhook.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/joycond-cemuhook.py b/joycond-cemuhook.py index dd2f4b7..2684a9c 100644 --- a/joycond-cemuhook.py +++ b/joycond-cemuhook.py @@ -566,8 +566,8 @@ def add_device(self, device, motion_device, motion_only=False): return i # All four slots have been allocated - print("Unable to use device [" + d.name + "]: Slots full") - self.blacklisted.append(d) + print("Unable to use device [" + device.name + "]: Slots full") + self.blacklisted.append(device) return MAX_PADS def add_devices(self, device, motion_devices, motion_only=False): @@ -598,6 +598,9 @@ def handle_devices(self): "Nintendo Switch Pro Controller", "Nintendo Switch Combined Joy-Cons"] + # Added for backwards compatibility with older versions of joycond + combined_devices = [d for d in evdev_devices if d.name == "Nintendo Switch Combined Joy-Cons"] + taken_slots = lambda: sum(d is not None for d in self.slots) # players 1-4, 0 for invalid devices @@ -645,8 +648,6 @@ def handle_devices(self): # Added for compatibility with older versions of joycond except StopIteration: - combined_devices = [d for d in evdev_devices if d.name == "Nintendo Switch Combined Joy-Cons"] - # Devices are not yet 'paired' if not combined_devices: continue @@ -655,7 +656,7 @@ def handle_devices(self): # This is the best guess we have to match combined device to it's individual Joy-Cons if len(combined_devices) > 1: context = pyudev.Context() - combined_devices.sort(key=lambda d: next(iter(context.list_devices(sys_name=basename(d.path)))).time_since_initialized) + combined_devices.sort(key=lambda d: next(iter(context.list_devices(sys_name=basename(d.path)))).time_since_initialized, reverse=True) device = combined_devices.pop(0)