I need to set up the Logitech gamepad F310 for my responses. I found this as a potential solution, but unfortunately I am working on macOS Sierra, and XInput is reported not to be compatible with macs.
Does anyone have any hint/solution I could use to go around this issue?
You could try a Python binding for one of the cross-platform HID APIs. I did that on Linux a couple of months ago for one of these arcade joysticks and an old Gravis Gamepad Pro. It should work for any USB joystick, they are all HID devices.
The documentation was lacking for that Python HID binding so I read the underling C API which it called and also experiment with some of the Python calls to learn how it worked. Reading from one of those joysticks blocked until there was input and for the other reading always returned immediately. For the one which blocked I created a python thread which blocked on input and wrote to a thread-safe structure which the main Python thread checked. I think for the other joystick I just polled it on each pass through the main 60Hz drawing loop, the input is buffered so you don’t lose anything even if the button press duration could be less than 1/60th of a second or whatever is you animation loop period.
That was for an in-house project at Aeon Imaging and I left that code there so I don’t have anything to share here. It all worked perfectly in the end but was not especially quick and easy to write. Threading in Python is easy but still more work than not.
PyGame and Pyglet both support joysticks but their joystick stuff is integrated with the event systems for those APIs. That did not work for my application but might be fine for what you are doing and should be much easier code to than is that HID API binding. Also, PyGame was broken on my Ubuntu install, they seem to be having maintenance issues so Pyglet might be the better choice there.
It looks like the Psychopy distribution includes on of those HID bindings, which I just noticed now, Jon has a note about that here.
So, I’m trying to run Jon’s script on one of his old posts. Setting some obvious typos aside (see the correct script below), it gives me an error because
NameError: name joystickVendorID is not defined
from ioLabs import hid
from psychopy import visual, event
win = visual.Window([800,800])
msg = visual.TextStim(win, text='nothing yet')
msg.setAutoDraw(True)
def gotNewData(newData):
msg.setText(repr(newData))
#you need to work out what your device is
devs = hid.find_hid_devices()
for thisDev in devs:
print thisDev.vendor, thisDev.product
if thisDev.vendor == joystickVendorID:
joy = thisDev
#now set calllback
joy.set_interrupt_report_callback(gotNewData)
while len(event.getKeys())==0: #press a key to quit
win.flip()
I can’t find any reference to this name anywhere. Does anybody have any idea of how to solve this?
In the loop, you are actually printing out all of the values of thisDev.vendor. Just replace the undefined placeholder joystickVendorID variable with the literal text string of the vendor ID you are after.
I had some challenges setting up a gamepad on mac for similar reasons, but I came up with a workaround. The bottom line is that if it’s a generic USB input device, PsychoPy’s Joystick system should be able to handle it, but it’s not pretty. See here: Joystick/refresh rate catch-22
If you click through the link in my first response, you’ll see that what I ended up having to do was manually refresh the pyglet joystick object on every screen refresh in order to be able to read its input in a pyglet window. If you use pygame, it’s a little better, but pygame isn’t really supported anymore and it will break a lot of other stuff. The Psychopy joystick object doesn’t entirely work, but you can bypass it.