ApproxEng / approxeng.input

Python classes to handle game controllers, including PS3, PS4, XBox One and Rock Candy
https://approxeng.github.io/approxeng.input
Apache License 2.0
55 stars 17 forks source link

Ignore nonexistent /sys/class/leds/*/device/uevent in find_device_hardware_id #39

Closed sainsaar closed 4 years ago

sainsaar commented 4 years ago

On a recent Raspberry Pi, "/sys/class/leds/default-on/device/uevent" does not exist. Instead of failing with an exception, ignore it and carry on.

tomoinn commented 4 years ago

This is a strange one - do you have the exception trace and a bit more info about what you were doing to trigger it? I'd like to check that silently ignoring this doesn't cause problems somewhere else.

sainsaar commented 4 years ago

Unfortunately I don't have access to the device at the moment, and I don't have the exact exception traceback saved anywhere.

I had a PlayStation 4 controller (DualShock 4) connected to a Raspberry Pi 4 Model B Rev 1.2 over bluetooth. The operating system was a recent Raspbian with kernel 5.4.51-v7l+. I paired the controller using bluetoothctl's commands "scan on", "pair ...", "connect ..." and "trust ...". Under /sys/class/leds the controller's leds were then all available and controllable. But there was also /sys/class/leds/default-on whose "device" directory had no "uevent". I suppose this represents a non-controllable LED...

Anyway, with my change, I could successfully control the controller's LED. My test code follows.

# The following three lines enable me to use a local copy of the approxeng.input library under lib/approxeng/input
#import os
#import sys
#sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib'))

import approxeng.input.controllers as ai_controllers
import approxeng.input.selectbinder as ai_selectbinder
import approxeng.input.dualshock4 as ai_dualshock4

def connect_ps4_controller():
    requirements = ai_controllers.ControllerRequirement(require_class=ai_dualshock4.DualShock4)
    return ai_selectbinder.ControllerResource(requirements)

with connect_ps4_controller() as ps:
    ps.set_leds(0.6, 1, 0.1)
tomoinn commented 4 years ago

Ah, yup. Hadn't looked at this code in a while - it's being triggered when the scan for all hardware happens, and as you say it's failing when it finds an LED that doesn't have a corresponding uevent. The code's looking for all LEDs and trying to match them up with controller instances, but when it hits this one it errors out. PR looks good, will merge.