src/joystick/darwin/SDL_sysjoystick.c
changeset 495 4503f9475cf2
parent 475 429fe382fe4f
child 594 a71ce390adeb
equal deleted inserted replaced
494:95aa4041e7f9 495:4503f9475cf2
   569 	mach_port_t masterPort = NULL;
   569 	mach_port_t masterPort = NULL;
   570 	io_iterator_t hidObjectIterator = NULL;
   570 	io_iterator_t hidObjectIterator = NULL;
   571 	CFMutableDictionaryRef hidMatchDictionary = NULL;
   571 	CFMutableDictionaryRef hidMatchDictionary = NULL;
   572 	recDevice *device, *lastDevice;
   572 	recDevice *device, *lastDevice;
   573 	io_object_t ioHIDDeviceObject = NULL;
   573 	io_object_t ioHIDDeviceObject = NULL;
   574 	UInt32 usagePage = kHIDPage_GenericDesktop;
       
   575 	UInt32 usage = kHIDUsage_GD_Joystick; /* We probably also should check for gamepads? */
       
   576 	
   574 	
   577 	SDL_numjoysticks = 0;
   575 	SDL_numjoysticks = 0;
   578 	
   576 	
   579 	if (NULL != gpDeviceList)
   577 	if (NULL != gpDeviceList)
   580 	{
   578 	{
   589 		return -1;
   587 		return -1;
   590 	}
   588 	}
   591 
   589 
   592 	/* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
   590 	/* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
   593 	hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey);
   591 	hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey);
   594 	if ((hidMatchDictionary != NULL) && (usagePage) && (usage))
   592 	if ((hidMatchDictionary != NULL))
   595 	{
   593 	{
   596 		/* Add key for device type (joystick, in this case) to refine the matching dictionary. */
   594 		/* Add key for device type (joystick, in this case) to refine the matching dictionary. */
       
   595 		
       
   596 		/* NOTE: we now perform this filtering later
       
   597 		UInt32 usagePage = kHIDPage_GenericDesktop;
       
   598 		UInt32 usage = kHIDUsage_GD_Joystick;
   597 		CFNumberRef refUsage = NULL, refUsagePage = NULL;
   599 		CFNumberRef refUsage = NULL, refUsagePage = NULL;
   598 
   600 
   599 		refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
   601 		refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
   600 		CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
   602 		CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
   601 		refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
   603 		refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
   602 		CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
   604 		CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
       
   605 		*/
   603 	}
   606 	}
   604 	else
   607 	else
   605 	{
   608 	{
   606 		SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
   609 		SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
   607 		return -1;
   610 		return -1;
   636 
   639 
   637 		/* dump device object, it is no longer needed */
   640 		/* dump device object, it is no longer needed */
   638 		result = IOObjectRelease (ioHIDDeviceObject);
   641 		result = IOObjectRelease (ioHIDDeviceObject);
   639 //		if (KERN_SUCCESS != result)
   642 //		if (KERN_SUCCESS != result)
   640 //			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
   643 //			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
       
   644 
       
   645 		/* Filter device list to non-keyboard/mouse stuff */ 
       
   646 		if ( device->usagePage == kHIDPage_GenericDesktop &&
       
   647 		     (device->usage == kHIDUsage_GD_Keyboard ||
       
   648 		      device->usage == kHIDUsage_GD_Mouse)) {
       
   649             
       
   650 			/* release memory for the device */
       
   651 			HIDDisposeDevice (&device);
       
   652 			DisposePtr((Ptr)device);
       
   653 			continue;
       
   654 		}
       
   655 		
   641 		/* Add device to the end of the list */
   656 		/* Add device to the end of the list */
   642 		if (lastDevice)
   657 		if (lastDevice)
   643 			lastDevice->pNext = device;
   658 			lastDevice->pNext = device;
   644 		else
   659 		else
   645 			gpDeviceList = device;
   660 			gpDeviceList = device;