(Apple HID) Get vendor ID/product ID too

This commit is contained in:
twinaphex 2014-09-28 15:32:17 +02:00
parent d7fe629afa
commit a0f24d0bb2
2 changed files with 23 additions and 10 deletions

View File

@ -73,6 +73,7 @@ int32_t apple_joypad_connect(const char* name, void *data)
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", &apple_pad_wii },
{ "Nintendo RVL-CNT-01-UC", &apple_pad_wii },
{ "PLAYSTATION(R)3 Controller", &apple_pad_ps3 },
{ 0, 0}
};
@ -90,12 +91,12 @@ int32_t apple_joypad_connect(const char* name, void *data)
int32_t apple_joypad_connect_gcapi(void)
{
int32_t slot;
slot = find_empty_slot();
int32_t slot = find_empty_slot();
if (slot >= 0 && slot < MAX_PLAYERS)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[slot];
s->used = true;
s->is_gcapi = true;
}
@ -116,7 +117,8 @@ void apple_joypad_disconnect(uint32_t slot)
}
}
void apple_joypad_packet(uint32_t slot, uint8_t* data, uint32_t length)
void apple_joypad_packet(uint32_t slot,
uint8_t* data, uint32_t length)
{
if (slot < MAX_PLAYERS && slots[slot].used)
{

View File

@ -20,6 +20,8 @@
struct apple_pad_connection
{
int v_id;
int p_id;
uint32_t slot;
IOHIDDeviceRef device_handle;
uint8_t data[2048];
@ -128,6 +130,7 @@ static void hid_manager_device_attached(void* context, IOReturn result,
{
char device_name[PATH_MAX];
CFStringRef device_name_ref;
CFNumberRef vendorID, productID;
struct apple_pad_connection* connection = (struct apple_pad_connection*)
calloc(1, sizeof(*connection));
@ -141,9 +144,17 @@ static void hid_manager_device_attached(void* context, IOReturn result,
kCFRunLoopCommonModes);
IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection);
#ifndef IOS
device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
CFStringGetCString(device_name_ref, device_name,
sizeof(device_name), kCFStringEncodingUTF8);
#endif
vendorID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey));
CFNumberGetValue(vendorID, kCFNumberIntType, &connection->v_id);
productID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey));
CFNumberGetValue(productID, kCFNumberIntType, &connection->p_id);
connection->slot = apple_joypad_connect(device_name, connection);
@ -218,14 +229,14 @@ static bool hid_init_manager(void)
static int hid_exit(void)
{
if (g_hid_manager)
{
IOHIDManagerClose(g_hid_manager, kIOHIDOptionsTypeNone);
IOHIDManagerUnscheduleFromRunLoop(g_hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
if (!g_hid_manager)
return -1;
CFRelease(g_hid_manager);
}
IOHIDManagerClose(g_hid_manager, kIOHIDOptionsTypeNone);
IOHIDManagerUnscheduleFromRunLoop(g_hid_manager,
CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFRelease(g_hid_manager);
g_hid_manager = NULL;