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

Raspberry Pi 4 - Success in Finding Device, Failing to Find Controller #54

Open SammyHerring opened 3 years ago

SammyHerring commented 3 years ago

Hi,

Not sure if there was a support forum avaliable. But perhaps, this is an issue that is related to the firmware or compatability.

I'm running a Raspberry Pi 4 on the latest version of Rasbian, trying to connect a Xbox Elite 2 Controller.

While a device may be found, it will not be detected as a controller by approxeng.input.

When calling with print_devices, you can see the device below. However, print_controllers will not find it.

DEBUG: list controllers found { 'axes': { 'ABS_HAT0X': {'code': 16, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_HAT0Y': {'code': 17, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_RX': {'code': 3, 'flat': 128, 'fuzz': 16, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_RY': {'code': 4, 'flat': 128, 'fuzz': 16, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_RZ': {'code': 5, 'flat': 0, 'fuzz': 0, 'max': 1023, 'min': 0, 'res': 0}, 'ABS_X': {'code': 0, 'flat': 128, 'fuzz': 0, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_Y': {'code': 1, 'flat': 128, 'fuzz': 0, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_Z': {'code': 2, 'flat': 0, 'fuzz': 0, 'max': 1023, 'min': 0, 'res': 0}}, 'bus': 3, 'buttons': { 304: ['BTN_A', 'BTN_GAMEPAD', 'BTN_SOUTH'], 305: ['BTN_B', 'BTN_EAST'], 307: ['BTN_NORTH', 'BTN_X'], 308: ['BTN_WEST', 'BTN_Y'], 310: 'BTN_TL', 311: 'BTN_TR', 314: 'BTN_SELECT', 315: 'BTN_START', 316: 'BTN_MODE', 317: 'BTN_THUMBL', 318: 'BTN_THUMBR'}, 'fn': '/dev/input/event0', 'name': 'Generic X-Box pad', 'path': '/dev/input/event0', 'phys': 'usb-0000:01:00.0-1.4/input0', 'product': 2816, 'rel_axes': None, 'uniq': '', 'unique_name': 'usb-0000:01:00.0-1.4', 'vendor': 1118, 'version': 1032} None

I have also tried a second different controller (Google Stadia), in case it was controller related.

DEBUG: list controllers found { 'axes': { 'ABS_BRAKE': {'code': 10, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0}, 'ABS_GAS': {'code': 9, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0}, 'ABS_HAT0X': {'code': 16, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_HAT0Y': {'code': 17, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_RZ': {'code': 5, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_X': {'code': 0, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_Y': {'code': 1, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_Z': {'code': 2, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}}, 'bus': 3, 'buttons': { 114: 'KEY_VOLUMEDOWN', 115: 'KEY_VOLUMEUP', 164: 'KEY_PLAYPAUSE', 304: ['BTN_A', 'BTN_GAMEPAD', 'BTN_SOUTH'], 305: ['BTN_B', 'BTN_EAST'], 307: ['BTN_NORTH', 'BTN_X'], 308: ['BTN_WEST', 'BTN_Y'], 310: 'BTN_TL', 311: 'BTN_TR', 314: 'BTN_SELECT', 315: 'BTN_START', 316: 'BTN_MODE', 317: 'BTN_THUMBL', 318: 'BTN_THUMBR', 704: ['BTN_TRIGGER_HAPPY', 'BTN_TRIGGER_HAPPY1'], 705: 'BTN_TRIGGER_HAPPY2', 706: 'BTN_TRIGGER_HAPPY3', 707: 'BTN_TRIGGER_HAPPY4'}, 'fn': '/dev/input/event0', 'name': 'Google LLC Stadia Controller rev. A', 'path': '/dev/input/event0', 'phys': 'usb-0000:01:00.0-1.4/input1', 'product': 37888, 'rel_axes': None, 'uniq': '9A050YCAC2KGMV', 'unique_name': '9A050YCAC2KGMV', 'vendor': 6353, 'version': 273} None

The error being raised when trying to use ControllerResource without any requirements, or with one using a custom profile is

Traceback (most recent call last): File "main.py", line 102, in <module> with ControllerResource(ControllerRequirement(require_class=WirelessXBoxOnePad)) as joystick: File "/usr/local/lib/python3.7/dist-packages/approxeng/input/selectbinder.py", line 37, in __init__ self.discoveries = find_matching_controllers(*requirements, **kwargs) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 178, in find_matching_controllers raise exception File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 174, in find_matching_controllers return list(pop_controller(r, all_controllers) for r in requirements) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 174, in <genexpr> return list(pop_controller(r, all_controllers) for r in requirements) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 169, in pop_controller raise ControllerNotFoundError() approxeng.input.controllers.ControllerNotFoundError

I have tried a number of combinations of Python scripts - but the one I have been trying to get an output from resembles:

`# Get a joystick with ControllerResource() as joystick:

Loop until we're disconnected

while joystick.connected:
    # This is an instance of approxeng.input.ButtonPresses
    left_y = joystick['ly']
    if left_y != 0:
        print('left x is %s' % left_y)
    if left_y == 1:
        print('left x is %s' % left_y)
    elif left_y == -1:
        print('left x is %s' % left_y)
    else:
        print('left x is %s' % left_y)
    presses = joystick.check_presses()
    if presses['square']:
        print('SQUARE pressed since last check')
    # We can also use attributes directly, and get at the presses object from the controller:
    if joystick.presses.circle:
        print('CIRCLE pressed since last check')
    # Or we can use the 'x in y' syntax:
    if 'triangle' in presses:
        print('TRIANGLE pressed since last check')

    # If we had any presses, print the list of pressed buttons by standard name
    if joystick.has_presses:
        print(joystick.presses)`

I'm new to this library so I may be making an error my side,

But I would appreciate any suggestions,

Thanks,

tomoinn commented 3 years ago

Hi Sammy,

The library won't detect a controller unless it knows about that type - this means you have to have either use one of the built-in controller models, or profile your controller first using the profiling tool. Once you've done that it should just work. Not sure what you're trying to do with that script btw - you can just access the axes values with e.g. joystick.ly, no need to copy it to another value and it'll only hit -1 and 1 at the extreme ends. Also you're printing 'left x is'... but with the value for left Y axis...