(IOHIDManager) Cleanups
This commit is contained in:
parent
86bfd8f4fc
commit
94254e4c79
|
@ -110,7 +110,8 @@ static void iohidmanager_append_record(apple_input_rec_t *rec, apple_input_rec_t
|
|||
static void iohidmanager_append_record_ordered(apple_input_rec_t **p_rec, apple_input_rec_t *b)
|
||||
{
|
||||
apple_input_rec_t *tmp = *p_rec;
|
||||
while(tmp && (tmp->id <= b->id)) {
|
||||
while (tmp && (tmp->id <= b->id))
|
||||
{
|
||||
p_rec = &tmp->next;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
@ -384,9 +385,10 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
|||
|
||||
if (pushed_button)
|
||||
{
|
||||
uint8_t bit = 0;
|
||||
|
||||
tmp = adapter->buttons;
|
||||
|
||||
uint8_t bit = 0;
|
||||
while (tmp && tmp->cookie != (IOHIDElementCookie)cookie)
|
||||
{
|
||||
bit++;
|
||||
|
@ -431,12 +433,14 @@ static void iohidmanager_hid_device_remove(void *data,
|
|||
adapter->hats = adapter->hats->next;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
while (adapter->axes != NULL)
|
||||
{
|
||||
tmp = adapter->axes;
|
||||
adapter->axes = adapter->axes->next;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
while (adapter->buttons != NULL)
|
||||
{
|
||||
tmp = adapter->buttons;
|
||||
|
@ -450,11 +454,11 @@ static void iohidmanager_hid_device_remove(void *data,
|
|||
static int32_t iohidmanager_hid_device_get_int_property(
|
||||
IOHIDDeviceRef device, CFStringRef key)
|
||||
{
|
||||
int32_t value;
|
||||
CFNumberRef ref = (CFNumberRef)IOHIDDeviceGetProperty(device, key);
|
||||
|
||||
if (ref && (CFGetTypeID(ref) == CFNumberGetTypeID()))
|
||||
{
|
||||
int32_t value = 0;
|
||||
CFNumberGetValue((CFNumberRef)ref, kCFNumberIntType, &value);
|
||||
return value;
|
||||
}
|
||||
|
@ -581,17 +585,18 @@ static void iohidmanager_hid_device_add(IOHIDDeviceRef device, iohidmanager_hid_
|
|||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
IOHIDElementType type;
|
||||
uint32_t page, use, cookie;
|
||||
int detected_button = 0;
|
||||
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
|
||||
|
||||
if (!element)
|
||||
continue;
|
||||
|
||||
IOHIDElementType type = IOHIDElementGetType(element);
|
||||
uint32_t page = (uint32_t)IOHIDElementGetUsagePage(element);
|
||||
uint32_t use = (uint32_t)IOHIDElementGetUsage(element);
|
||||
uint32_t cookie = (uint32_t)IOHIDElementGetCookie(element);
|
||||
|
||||
int detected_button = 0;
|
||||
type = IOHIDElementGetType(element);
|
||||
page = (uint32_t)IOHIDElementGetUsagePage(element);
|
||||
use = (uint32_t)IOHIDElementGetUsage(element);
|
||||
cookie = (uint32_t)IOHIDElementGetCookie(element);
|
||||
|
||||
switch (page)
|
||||
{
|
||||
|
@ -833,14 +838,6 @@ static int iohidmanager_hid_manager_free(iohidmanager_hid_t *hid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int iohidmanager_hid_manager_set_device_matching(
|
||||
iohidmanager_hid_t *hid)
|
||||
{
|
||||
CFSetRef set = IOHIDManagerCopyDevices(hid->ptr);
|
||||
CFIndex num_devices = CFSetGetCount(set);
|
||||
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
|
||||
CFSetGetValues(set, (const void **) device_array);
|
||||
|
||||
/* re order device by location id */
|
||||
typedef struct hid_list
|
||||
{
|
||||
|
@ -849,32 +846,43 @@ static int iohidmanager_hid_manager_set_device_matching(
|
|||
struct hid_list *next;
|
||||
} hid_list_t;
|
||||
|
||||
static int iohidmanager_hid_manager_set_device_matching(
|
||||
iohidmanager_hid_t *hid)
|
||||
{
|
||||
unsigned i;
|
||||
hid_list_t* devList = NULL;
|
||||
for (long i=0; i<num_devices;i++)
|
||||
CFSetRef set = IOHIDManagerCopyDevices(hid->ptr);
|
||||
CFIndex num_devices = CFSetGetCount(set);
|
||||
IOHIDDeviceRef *device_array = (IOHIDDeviceRef*)calloc(num_devices, sizeof(IOHIDDeviceRef));
|
||||
|
||||
CFSetGetValues(set, (const void **) device_array);
|
||||
|
||||
for (i = 0; i < num_devices; i++)
|
||||
{
|
||||
IOHIDDeviceRef dev = device_array[i];
|
||||
|
||||
/* filter gamepad/joystick devices */
|
||||
if ( IOHIDDeviceConformsTo(dev, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick)
|
||||
|| IOHIDDeviceConformsTo(dev, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)
|
||||
)
|
||||
{
|
||||
if ( devList == NULL )
|
||||
if (!devList)
|
||||
{
|
||||
devList = (hid_list_t *)malloc(sizeof(hid_list_t));
|
||||
devList->device = dev;
|
||||
devList->lid = iohidmanager_hid_device_get_location_id(dev);
|
||||
//printf("%d\n",devList->lid);
|
||||
devList->next = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_list_t *ptr = NULL;
|
||||
hid_list_t *new = (hid_list_t *)malloc(sizeof(hid_list_t));
|
||||
new->device = dev;
|
||||
new->lid = iohidmanager_hid_device_get_location_id(dev);
|
||||
//printf("%d\n",new->lid);
|
||||
new->next = NULL;
|
||||
|
||||
hid_list_t * ptr = devList;
|
||||
ptr = devList;
|
||||
|
||||
if ( new->lid < ptr->lid )
|
||||
{
|
||||
new->next = ptr;
|
||||
|
@ -882,10 +890,9 @@ static int iohidmanager_hid_manager_set_device_matching(
|
|||
}
|
||||
else
|
||||
{
|
||||
while ( ( ptr->lid < new->lid ) && (ptr->next != NULL) )
|
||||
{
|
||||
while ((ptr->lid < new->lid ) && ptr->next)
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
new->next = ptr->next;
|
||||
ptr->next = new;
|
||||
}
|
||||
|
@ -893,16 +900,18 @@ static int iohidmanager_hid_manager_set_device_matching(
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* register devices */
|
||||
hid_list_t * ptr = devList;
|
||||
while (ptr != NULL)
|
||||
while (ptr)
|
||||
{
|
||||
iohidmanager_hid_device_add(ptr->device, hid);
|
||||
//printf("%d\n",ptr->lid);
|
||||
ptr = ptr->next;
|
||||
free(devList);
|
||||
devList = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
free(device_array);
|
||||
|
||||
return 0;
|
||||
|
@ -914,7 +923,8 @@ static void *iohidmanager_hid_init(void)
|
|||
calloc(1, sizeof(*hid_apple));
|
||||
|
||||
if (!hid_apple)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
hid_apple->slots = pad_connection_init(MAX_USERS);
|
||||
|
||||
if (!hid_apple->slots)
|
||||
|
|
Loading…
Reference in New Issue