简体   繁体   中英

Receiving data from HID game controller in Python

I am trying to communicate with a game controller Human Interface Device (HID) with a Python script, but I'm having trouble receiving data from the controller. I am using pywinusb 0.3.2 and Python 3.3. The game controller is a Logitech Gamepad F310.Link Here to pywinusb.

I have been able to get python to recognize the HID, but I am stuck as on where to go from there. My code for recognizing the controller is:

import pywinusb.hid as hid

target = hid.HidDeviceFilter(vendor_id = target_vendor_id, product_id = target_product_id)
allitems = target.get_devices()
device = allitems[0]
print(device)

This code returns something like this: HID device (vID=0x00a, pID=0xa000, v=0x0000); Logitech; Logitech Dual Action, Path: \\(numbers and letters in a long sequence here)

I'm not sure if the approach here would work with a controller, or whether there is another library that is preferable to pywinusb. If I have to switch libraries, I would prefer to switch to one that is cross platform. The small amount of documentation in the examples section included was not enough for me to figure this out with.

My question is: How do I receive the data from the controller? Is there a command? I've worked with the Arduino a little bit and hooking it up to a Wii Nunchuk was a similar process. Will I have to be sending initialization sequences, similar to the Arduino? I need to know the x and y values of both sticks on the controller as well as whether the buttons are pressed.

My apologies if this is obvious or has already been answered. I have never worked with an HID in python before.

Take a look to how HID usages work (google around).

Use the show_hids.py example script to review if the device exposes standard usages.

If not, your only hope is to use raw reports handlers (check the example folders from the source, I recommend you to work with github's code).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM