  | |  | HID manager - is it worth it? | HID manager - is it worth it? 2004-12-11 - By George Warner
Back On Thu, 9 Dec 2004 15:42:19 -0500, Tim Conkling <tconkling@(protected)> wrote: > I have zero experience with the HID manager and I'm interested in > hearing game developers' experiences and opinions on using it.
Everything you need for input is in the HID Utilities sample source code at: <http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/HID_ Manager/HID_Utilities_Source.htm>.
1) Download the HID Utilities sample code.
2) Double-click the HID Utilities slib.pbproj file to open it in Project Builder (or xcode).
3) Click build. This will create a build folder that will contain libHIDUtilities.a once it's finished building.
4) Copy and add libHIDUtilities.a to your project.
5) Add "#include "HID_Utilities_External.h"" and "#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>" to your game device code file(s).
The "interesting" API's are:
HIDBuildDeviceList - This creates a list of all the HID devices. HIDReleaseDeviceList - call this when you're done with the list. HIDGetFirst/NextDevice - used to iterate the devices HIDGetFirst/NextDeviceElement - used to iterate elements of a device. HIDGetElementNameFromVendorProduct[Cookie|Usage] - Get text name of an element.
HIDQueueDevice - Add all device elements to event queue HIDDequeueDevice - remove device from event queue HIDQueueElement - Add element to event queue HIDDequeueElement - remove element from event queue HIDGetEvent - poll queue for events
6) Build a list of devices by doing:
HIDBuildDeviceList( NULL, NULL ); if (! HIDHaveDeviceList() ) return NULL; num_devices = HIDCountDevices();
7) Loop through the devices, looking for the one(s) you're interested in. You find it by matching its usage and usagePage. For example, for a game pad, you'd look for a usagePage of kHIDPage_GenericDesktop and a usage of kHIDUsage_GD_GamePad. (All this stuff is found in IOHIDUsageTables.h)
pRecDevice deviceCandidate = NULL, *stored_device[100]; int i, foundDevices = 0;
deviceCandidate = HIDGetFirstDevice();
i = 0; while ( i < num_devices ) { if ( deviceCandidate ) { //here I filter out keyboards, mice and totally unrelated devices if ( (deviceCandidate->usage == kHIDUsage_GD_Keyboard) || (deviceCandidate->usagePage != kHIDPage_GenericDesktop) || (deviceCandidate->usage == kHIDUsage_GD_Mouse) ) { if ( HIDIsValidDevice( deviceCandidate ) ) { //skip this one and just go on to the next one deviceCandidate = HIDGetNextDevice( deviceCandidate ); } else { //handle error } } else { if ( HIDIsValidDevice( deviceCandidate ) ) { //store the device in a list of devices we're interested in stored_device[foundDevices] = deviceCandidate; deviceCandidate = HIDGetNextDevice( deviceCandidate ); foundDevices++; } else { //handle error } } } i++; }
8) Now that you've got the device, go through its elements and find the axis or button you're interested in:
if ( HIDIsValidDevice( device ) ) { elRec = HIDGetFirstDeviceElement( js_devices[id].device, kHIDElementTypeInput ); if ( elRec ) { switch (elRec->usagePage) { case kHIDPage_GenericDesktop: switch ( elRec->usage ) { case kHIDUsage_GD_X: x_axis = elRec; break; case kHIDUsage_GD_Y: y_axis = elRec; break; case kHIDUsage_GD_GamePad: pad = elRec; break; //etc } } //if the right element was not found, continue looping through the //rest of the elements by calling HIDGetNextDeviceElement() until you //find the right one or it returns NULL }
9) Now that you've got the actual element, you can query it's value:
if ( HIDIsValidElement( devicePtr, elementPtr ) ) { value = HIDGetElementValue(devicePtr, elementPtr); }
10) Or add it to a queue:
if ( HIDIsValidElement( devicePtr, elementPtr ) ) { HIDQueueElement (devicePtr, elementPtr); }
11) that you can check by:
while (HIDGetEvent(&tDevice, tHIDEvent)) { // process tHIDEvent }
You may incorporate the entire HID Utilities into your project as-is or cut & paste the pieces that you need.
-- Enjoy, George Warner, Schizophrenic Optimization Scientist Apple Developer Technical Support (DTS)
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ Do not post admin requests to the list. They will be ignored. Mac-games-dev mailing list (Mac-games-dev@(protected)) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-games-dev/junlu%405341.com
This email sent to junlu@(protected)
Earn $52 per hosting referral at Lunarpages.
|
|
 |