(Apple) OSX HID - some cleanups
This commit is contained in:
parent
c07aa7ec0a
commit
1e2f8651b9
|
@ -140,7 +140,7 @@ static void hid_device_input_callback(void* context, IOReturn result,
|
|||
}
|
||||
}
|
||||
|
||||
static void hid_device_removed(void* context, IOReturn result, void* sender)
|
||||
static void remove_device(void* context, IOReturn result, void* sender)
|
||||
{
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
struct apple_pad_connection* connection = (struct apple_pad_connection*)
|
||||
|
@ -170,10 +170,12 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
|
|||
{
|
||||
struct apple_pad_connection* connection = (struct apple_pad_connection*)
|
||||
context;
|
||||
|
||||
if (connection)
|
||||
apple_joypad_packet(connection->slot, connection->data, reportLength + 1);
|
||||
}
|
||||
|
||||
static void hid_manager_device_attached(void* context, IOReturn result,
|
||||
static void add_device(void* context, IOReturn result,
|
||||
void* sender, IOHIDDeviceRef device)
|
||||
{
|
||||
char device_name[PATH_MAX];
|
||||
|
@ -190,7 +192,7 @@ static void hid_manager_device_attached(void* context, IOReturn result,
|
|||
/* Move the device's run loop to this thread. */
|
||||
IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(),
|
||||
kCFRunLoopCommonModes);
|
||||
IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection);
|
||||
IOHIDDeviceRegisterRemovalCallback(device, remove_device, connection);
|
||||
|
||||
#ifndef IOS
|
||||
device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
|
||||
|
@ -246,18 +248,17 @@ static void append_matching_dictionary(CFMutableArrayRef array,
|
|||
CFRelease(matcher);
|
||||
}
|
||||
|
||||
static int32_t find_empty_slot(void)
|
||||
static int find_vacant_pad(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
if (!slots[i].used)
|
||||
{
|
||||
if (slots[i].used)
|
||||
continue;
|
||||
|
||||
memset(&slots[i], 0, sizeof(slots[0]));
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -265,12 +266,12 @@ int32_t apple_joypad_connect(const char* name, void *data)
|
|||
{
|
||||
struct apple_pad_connection* connection =
|
||||
(struct apple_pad_connection*)data;
|
||||
int32_t slot = find_empty_slot();
|
||||
int pad = find_vacant_pad();
|
||||
|
||||
if (slot >= 0 && slot < MAX_PLAYERS)
|
||||
if (pad >= 0 && pad < MAX_PLAYERS)
|
||||
{
|
||||
unsigned i;
|
||||
joypad_slot_t* s = (joypad_slot_t*)&slots[slot];
|
||||
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
|
||||
s->used = true;
|
||||
|
||||
static const struct
|
||||
|
@ -290,26 +291,26 @@ int32_t apple_joypad_connect(const char* name, void *data)
|
|||
if (strstr(name, pad_map[i].name))
|
||||
{
|
||||
s->iface = pad_map[i].iface;
|
||||
s->data = s->iface->connect(connection, slot);
|
||||
s->data = s->iface->connect(connection, pad);
|
||||
}
|
||||
}
|
||||
|
||||
return slot;
|
||||
return pad;
|
||||
}
|
||||
|
||||
int32_t apple_joypad_connect_gcapi(void)
|
||||
{
|
||||
int32_t slot = find_empty_slot();
|
||||
int pad = find_vacant_pad();
|
||||
|
||||
if (slot >= 0 && slot < MAX_PLAYERS)
|
||||
if (pad >= 0 && pad < MAX_PLAYERS)
|
||||
{
|
||||
joypad_slot_t *s = (joypad_slot_t*)&slots[slot];
|
||||
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
|
||||
|
||||
s->used = true;
|
||||
s->is_gcapi = true;
|
||||
}
|
||||
|
||||
return slot;
|
||||
return pad;
|
||||
}
|
||||
|
||||
void apple_joypad_disconnect(uint32_t slot)
|
||||
|
@ -349,14 +350,13 @@ static bool apple_joypad_init(void)
|
|||
{
|
||||
CFMutableArrayRef matcher;
|
||||
|
||||
g_hid_manager = IOHIDManagerCreate(
|
||||
kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
||||
|
||||
if (!g_hid_manager)
|
||||
if (!(g_hid_manager = IOHIDManagerCreate(
|
||||
kCFAllocatorDefault, kIOHIDOptionsTypeNone)))
|
||||
return false;
|
||||
|
||||
matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0,
|
||||
&kCFTypeArrayCallBacks);
|
||||
|
||||
append_matching_dictionary(matcher, kHIDPage_GenericDesktop,
|
||||
kHIDUsage_GD_Joystick);
|
||||
append_matching_dictionary(matcher, kHIDPage_GenericDesktop,
|
||||
|
@ -366,7 +366,7 @@ static bool apple_joypad_init(void)
|
|||
CFRelease(matcher);
|
||||
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(g_hid_manager,
|
||||
hid_manager_device_attached, 0);
|
||||
add_device, 0);
|
||||
IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetMain(),
|
||||
kCFRunLoopCommonModes);
|
||||
|
||||
|
@ -380,19 +380,8 @@ static bool apple_joypad_query_pad(unsigned pad)
|
|||
return pad < MAX_PLAYERS;
|
||||
}
|
||||
|
||||
static void apple_joypad_destroy(void)
|
||||
static void apple_joypad_hid_destroy(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_PLAYERS; i ++)
|
||||
{
|
||||
if (slots[i].used && slots[i].iface && slots[i].iface->set_rumble)
|
||||
{
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_hid_manager)
|
||||
return;
|
||||
|
||||
|
@ -405,6 +394,23 @@ static void apple_joypad_destroy(void)
|
|||
g_hid_manager = NULL;
|
||||
}
|
||||
|
||||
static void apple_joypad_destroy(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_PLAYERS; i ++)
|
||||
{
|
||||
if (slots[i].used && slots[i].iface
|
||||
&& slots[i].iface->set_rumble)
|
||||
{
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
apple_joypad_hid_destroy();
|
||||
}
|
||||
|
||||
static bool apple_joypad_button(unsigned port, uint16_t joykey)
|
||||
{
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
|
@ -460,7 +466,12 @@ static bool apple_joypad_rumble(unsigned pad,
|
|||
|
||||
static const char *apple_joypad_name(unsigned joypad)
|
||||
{
|
||||
/* TODO/FIXME - implement properly */
|
||||
if (pad >= MAX_PLAYERS)
|
||||
return NULL;
|
||||
|
||||
(void)joypad;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue