Question

I have been searching through how to do gamepad and joystick support on Mac for some days and all resources that I found seems to suggest a pre-installed driver along with using Apple's HID API, which works.

The drawback about this approach is that each joystick and gamepad will require another kernel extension to be loaded, so it can be recognized by HID manager, or at least a code less Info.plist saying it conforms to the earlier installed driver. For instance, when I have an 360 Xbox driver KEXT in house, the Xbox controller from Microsoft will work, but not the Logitech one (I tried F710).

As Apple suggests the application that uses a gamepad or joystick should be able to do themselves at user space without introducing any KEXT stuff. Is there a way to do it?

The thing I had in mind was something like using IORegistry or IOUSB API to get the device when they get plugged in (USB Prober shows it at least). Then somehow get the description of the device, then use that description to register the device as a HID one. Then the whole HID manager can be used.

Am I on the right track? Or is there any other way to do this?

Since IOKit API actually provided keywords like kHIDUsage_GD_Joystick, and there's an ForceFeedback.h library, I suppose Apple designed their HID API with joystick and force feedback in mind. That's the slim hope I had that this might work.

Some reference documentation and open source project:

Était-ce utile?

La solution

After revisiting this, I found out the solution to be operating directly on the file descriptors of the device. libusb is an excellent library which greatly simplify your life on this and they have Mac supported.

xboxdrv link is a great example on how to operate on file socket using libusb.

In pseudo code, it should look like this:

  1. enumerate device
  2. detect kernel driver and detach it if possible
  3. open device
  4. file off a initial transfer
  5. wait on the callback function to handle msg and error properly
  6. start run loop or select on fd to call libusb_event_handle

Check libusb for more info link.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top