However, I ran into a problem, and can't find an easy solution to it.
From examination, it seems to me, that the only way I can identify distinct control updates (button presses and stick movement) is via an integer identifier, I get back from the HIDElementGetCookie(element) function. But this identifier is completely vendor specific as far as I know.
For example, on my simple logitech Gamepad, the Cookie 18 describes the X-Axis of the left analog stick, whereas on the PS3 controller the same Cookie value describes the upper-right shoulder button.
Is there any technique or reliable other method, how I can identify specific elements of a controller?
To add some code to my question, here is the HID callback function, that handles the control update:
void gamepadAction(void* inContext, IOReturn inResult,
void* inSender, IOHIDValueRef value) {
IOHIDElementRef element = IOHIDValueGetElement(value);
Boolean isElement = CFGetTypeID(element) == IOHIDElementGetTypeID();
if (!isElement)
return;
IOHIDElementCookie cookie = IOHIDElementGetCookie(element);
IOHIDElementType type = IOHIDElementGetType(element);
if (18 != cookie && 19 != cookie && 21 != cookie){
NSLog(@"Gamepad talked rubbish at %d of type %d", cookie, type);
return;
}
IOHIDElementCollectionType ctype = IOHIDElementGetCollectionType(element);
CFStringRef name = IOHIDElementGetName(element);
long elementValue = IOHIDValueGetIntegerValue(value);
NSLog(@"Gamepad talked: %d / %d - %@ [%i] = %ld", type, ctype, name,
cookie, elementValue);
if (18 == cookie || 19 == cookie || 21 == cookie){
MyGameController* obj = (__bridge MyGameController*) inContext;
float axisScale = 128;
float axisvalue = ((float)(elementValue-axisScale)/axisScale);
if (elementValue <= axisScale +1 &&
elementValue >= axisScale -1)
axisvalue = 0.0;
if (18 == cookie)
[obj setLatitude:axisvalue];
else if (21 == cookie)
[obj setCenterDistance:axisvalue];
else if (19 == cookie)
[obj setLongitude:axisvalue];
}
}






