# Setting up gamepad logitech F310 on mac

**URL:** <https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622>\
**Category:** Coding\
**Created:** [December 14, 2017, 2:27pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622 "2017-12-14T14:27:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roberto\_Petrosino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/roberto_petrosino/32/5543_2.png) [@Roberto\_Petrosino](https://discourse.psychopy.org/u/Roberto_Petrosino)\
**Post date:** [December 14, 2017, 2:27pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/1 "2017-12-14T14:27:53Z")

</div>

Hello everyone,

I need to set up the Logitech gamepad F310 for my responses. I found [this](https://github.com/psychopy/psychopy/blob/master/psychopy/demos/coder/iohub/xinputgamepad.py) 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?

Thanks!!

---

<div class="post-metadata">

**Author:** ![AllenIngling](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/alleningling/32/1398_2.png) [@AllenIngling](https://discourse.psychopy.org/u/AllenIngling)\
**Post date:** [December 14, 2017, 6:18pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/2 "2017-12-14T18:18:02Z")

</div>

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](https://www.amazon.com/Easyget-Joystick-Cabinet-Fighting-Support/dp/B00XHM5JPE/ref=sr_1_6?ie=UTF8&qid=1513272904&sr=8-6&keywords=cabinet+joystick) arcade joysticks and an old [Gravis Gamepad Pro](https://www.amazon.com/Kensington-Gravis-Gamepad-Pro-USB/dp/B00000K4TQ). 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](https://groups.google.com/forum/#!topic/psychopy-users/NmubD6G-McQ).

best,

Allen

---

<div class="post-metadata">

**Author:** ![Roberto\_Petrosino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/roberto_petrosino/32/5543_2.png) [@Roberto\_Petrosino](https://discourse.psychopy.org/u/Roberto_Petrosino)\
**Post date:** [December 15, 2017, 1:05pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/3 "2017-12-15T13:05:55Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [December 16, 2017, 7:44am UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/4 "2017-12-16T07:44:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)\
**Post date:** [December 17, 2017, 2:43pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/5 "2017-12-17T14:43:56Z")

</div>

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](https://discourse.psychopy.org/t/joystick-refresh-rate-catch-22/958/11)

---

<div class="post-metadata">

**Author:** ![Roberto\_Petrosino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/roberto_petrosino/32/5543_2.png) [@Roberto\_Petrosino](https://discourse.psychopy.org/u/Roberto_Petrosino)\
**Post date:** [December 17, 2017, 3:56pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/6 "2017-12-17T15:56:10Z")

</div>

> [@jonathan.kominsky](#):
>
> PsychoPy’s Joystick system should be able to handle it, but it’s not pretty

What do you mean by “not pretty”?

---

<div class="post-metadata">

**Author:** ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)\
**Post date:** [December 17, 2017, 4:08pm UTC](https://discourse.psychopy.org/t/setting-up-gamepad-logitech-f310-on-mac/3622/7 "2017-12-17T16:08:08Z")

</div>

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.
