Example #1
0
static void build_joystick_list(joy_hid_device_array_t *dev_array)
{
    int i;
    int num_devices = dev_array->num_internal_devices;        
    CFArrayRef devices = dev_array->internal_devices;
    joy_hid_device_t *d = dev_array->devices;
    for ( i = 0; i < num_devices ; i++ ) {
        IOHIDDeviceRef dev = ( IOHIDDeviceRef ) CFArrayGetValueAtIndex( devices, i );
        if(is_joystick(dev)) {
               
            long vendor_id = 0;
            IOHIDDevice_GetLongProperty( dev, CFSTR( kIOHIDVendorIDKey ), &vendor_id );
            long product_id = 0;
            IOHIDDevice_GetLongProperty( dev, CFSTR( kIOHIDProductIDKey ), &product_id );
            CFStringRef product_key;
            product_key = IOHIDDeviceGetProperty( dev, CFSTR( kIOHIDProductKey ) );
            char *product_name = "N/A";
            if(product_key) {
               char buffer[256];
               if(CFStringGetCString(product_key, buffer, 256, kCFStringEncodingUTF8)) {
                   product_name = strdup(buffer);
               }
            }

            d->internal_device = dev;
            d->vendor_id = (int)vendor_id;
            d->product_id = (int)product_id;
            d->serial = 0; /* will be filled in later */
            d->product_name = product_name;

            d++;
        }
    }
}
Example #2
0
static int count_joysticks(joy_hid_device_array_t *dev_array)
{
    int i;
    int num_devices = dev_array->num_internal_devices;
    int num_joys = 0;
    CFArrayRef devices = dev_array->internal_devices;
    for ( i = 0; i < num_devices ; i++ ) {
        IOHIDDeviceRef dev = ( IOHIDDeviceRef ) CFArrayGetValueAtIndex( devices, i );
        if(is_joystick(dev)) {
               num_joys++;
        }
    }
    
    dev_array->num_devices = num_joys;
    return num_joys;
}
Example #3
0
void JoystickOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) {

	if (p_res != kIOReturnSuccess || have_device(p_device)) {
		return;
	}

	joystick new_joystick;
	if (is_joystick(p_device)) {
		configure_joystick(p_device, &new_joystick);
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
		if (IOHIDDeviceGetService != NULL) {
#endif
			const io_service_t ioservice = IOHIDDeviceGetService(p_device);
			if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK) && new_joystick.config_force_feedback(ioservice)) {
				new_joystick.ffservice = ioservice;
			}
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
		}
#endif
		device_list.push_back(new_joystick);
	}
	IOHIDDeviceRegisterRemovalCallback(p_device, joystick_removed_callback, (void *)(intptr_t)new_joystick.id);
	IOHIDDeviceScheduleWithRunLoop(p_device, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE);
}