Re: Using Gamepads..?
Aya Koshigaya <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, mhh... I still don't realy get it :( A few years ago when I was still developing for Windows, I used DirectInput. There any gamepad device was handled as the same, I didn't had to write some special code for every different device. And I didn't had to care about how the device is connected (Bluetooth, USB..).. I just got a list of devices and their buttons and axis-sticks.. Isn't there something like this for MacOS..? Aya~ On 05.03.2010, at 18:41, Mr. George Warner wrote: > On Mar 5, 2010, at 3:09 AM, Aya Koshigaya wrote: > >> Thanks a lot for the source! :) >> >>> I don't know where you get 1K lines of code… I can do all my HID communications in less that a half page of code. >> >> You example has more then a few thousand lines of code - even without the HID Utilities it's still about 1000 lines :) >> Sure a lot of printf etc, but... still .. > > Boiling it down to the essential (HID) stuff: > > In applicationDidFinishLaunching: > > hidManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); > IOHIDManagerSetDeviceMatching(hidManagerRef, NULL); > IOHIDManagerRegisterDeviceMatchingCallback(hidManagerRef, Handle_DeviceMatchingCallback, nil); > IOHIDManagerRegisterDeviceRemovalCallback(hidManagerRef, Handle_DeviceRemovalCallback, nil); > IOHIDManagerScheduleWithRunLoop(hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); > IOReturn ioReturn = IOHIDManagerOpen(hidManagerRef, kIOHIDOptionsTypeNone); > > In Handle_DeviceMatchingCallback: > > I check the vendor & product ID using: > > long vendorID = IOHIDDevice_GetVendorID(inIOHIDDeviceRef); > long productID = IOHIDDevice_GetProductID(inIOHIDDeviceRef); > > (note: if you know the exact device you're interested in you can pass a non-NULL dictionary to IOHIDManagerSetDeviceMatching above.) > > and if it's the device I'm interested in I: > > IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, report, reportSize, Handle_IOHIDDeviceIOHIDReportCallback, nil); > > Then in Handle_IOHIDDeviceIOHIDReportCallback I can see my incoming reports. > > All the rest of that code is ether PS3 specific (like the bluetooth stuff) or has nothing to do with HID. > > That's about nine lines of code… ;-) > > All those APIs are documented in my technote at: <http://developer.apple.com/mac/library/technotes/tn2007/tn2187.html>. > > -- > Enjoy, > George Warner, (408)974-0668 > Schizophrenic Optimization Scientist > Apple Developer Technical Support (DTS) > <[email protected]> > > >