Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gamepad and joystick support on Mac OS X in user space

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:

  • Colin Munro's 360 driver
  • HID API Documents
  • DDHID Project
like image 566
vgrimmer Avatar asked Oct 10 '12 22:10

vgrimmer


People also ask

Can you control a Mac with a controller?

If your controller has a USB cable and port, then simply plug it into your Mac and it should recognize the controller as an external device. If your controller has Bluetooth support, then you'll need to pair it with your Mac: Make sure your controller is turned off.


1 Answers

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.

like image 104
vgrimmer Avatar answered Oct 21 '22 04:10

vgrimmer