Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs introduced in #29 #34

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions joycond-cemuhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down