Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HID Utilities with kHIDUsage_GD_Joystick usage



Hi all. I'm new to the list and while I searched the archives and didn't find any helpful examples, I'm open to the possibility that I missed something. If so, I apologize.

I've been attempting to figure out how to use the HID Utilities library to perform a simple callback on input. It seemed simple enough so I wrote this code:

static void handleInput(void *target, int result, void *refcon, void *sender)
{
IOHIDEventStruct event;

pRecDevice dev = (pRecDevice)refcon;

while (HIDGetEvent(dev, &event))
{
printf("Event: {t: %#2.2x, c: %u, v: %#8.8lx}\n",
event.type, unsigned(event.elementCookie),
(event.longValueSize > 4 ? *(UInt32*)event.longValue :
event.value));
}
}


int main()
{
	UInt32 usagePage = kHIDPage_GenericDesktop;
	UInt32 usage = kHIDUsage_GD_Joystick;
	
	if (!HIDBuildDeviceList(usagePage, usage))
	{
		puts("Failed to build list.");
		return 1;
	}

	printf("Found %lu devices.\n", HIDCountDevices());

	for (pRecDevice d = HIDGetFirstDevice(); d; d = HIDGetNextDevice(d))
	{
		if (HIDQueueDevice(d) != kIOReturnSuccess)
		{
			puts("HIDQueueDevice() failed.");
			continue;
		}
		if (HIDSetQueueCallback(d, handleInput) != kIOReturnSuccess)
			puts("Failed to install the callback.");
	}
	
	CFRunLoopRunInMode(kCFRunLoopDefaultMode, 3.0, false);
	
	HIDReleaseDeviceList();
	return 0;
}

This didn't work at all. It seemed that the callback was never being called when I pressed the buttons even thought the printf statement reported that it had found a device. (The HID_Manager_Test sample code showed that it was the correct joystick--after I changed kHIDUsage_GD_GamePad to kHIDUsage_GD_Joystick.)

I changed the usagePage and usage in the above code to 0 and re-ran the code. After doing that the callback is called when I move the mouse or type on the keyboard.

Am I doing something hideously wrong here?

Thanks,

- Steve

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.