mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(IOHIDManager) Add improvements - https://github.com/libretro/RetroArch/issues/4816#issuecomment-359145035
This commit is contained in:
parent
99500b6f10
commit
3fc2ddb8d2
@ -227,10 +227,8 @@ static void iohidmanager_hid_device_report(void *data,
|
||||
static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
||||
void* sender, IOHIDValueRef value)
|
||||
{
|
||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)
|
||||
hid_driver_get_data();
|
||||
struct iohidmanager_hid_adapter *adapter =
|
||||
(struct iohidmanager_hid_adapter*)data;
|
||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
|
||||
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data;
|
||||
IOHIDElementRef element = IOHIDValueGetElement(value);
|
||||
uint32_t type = (uint32_t)IOHIDElementGetType(element);
|
||||
uint32_t page = (uint32_t)IOHIDElementGetUsagePage(element);
|
||||
@ -246,6 +244,8 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
||||
/* Joystick handler.
|
||||
* TODO: Can GamePad work the same? */
|
||||
|
||||
int pushed_button = 0;
|
||||
|
||||
switch (page)
|
||||
{
|
||||
case kHIDPage_GenericDesktop:
|
||||
@ -326,6 +326,8 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
||||
while(tmp && tmp->cookie != (IOHIDElementCookie)cookie)
|
||||
tmp = tmp->next;
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
if(tmp->cookie == (IOHIDElementCookie)cookie)
|
||||
{
|
||||
CFIndex min = IOHIDElementGetPhysicalMin(element);
|
||||
@ -336,32 +338,45 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
||||
hid->axes[adapter->slot][tmp->id] =
|
||||
((val * 2.0f) - 1.0f) * 32767.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
pushed_button = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case kHIDPage_Consumer:
|
||||
case kHIDPage_Button:
|
||||
switch (type)
|
||||
{
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
case kIOHIDElementTypeInput_Button:
|
||||
pushed_button = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (pushed_button)
|
||||
{
|
||||
tmp = adapter->buttons;
|
||||
|
||||
uint8_t bit = 0;
|
||||
while(tmp && tmp->cookie != (IOHIDElementCookie)cookie)
|
||||
{
|
||||
bit++;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
if(tmp->cookie == (IOHIDElementCookie)cookie)
|
||||
if(tmp && tmp->cookie == (IOHIDElementCookie)cookie)
|
||||
{
|
||||
CFIndex state = IOHIDValueGetIntegerValue(value);
|
||||
|
||||
if (state)
|
||||
BIT64_SET(hid->buttons[adapter->slot], tmp->id);
|
||||
BIT64_SET(hid->buttons[adapter->slot], bit);
|
||||
else
|
||||
BIT64_CLEAR(hid->buttons[adapter->slot], tmp->id);
|
||||
BIT64_CLEAR(hid->buttons[adapter->slot], bit);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,6 +563,8 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
uint32_t use = (uint32_t)IOHIDElementGetUsage(element);
|
||||
uint32_t cookie = (uint32_t)IOHIDElementGetCookie(element);
|
||||
|
||||
int detected_button = 0;
|
||||
|
||||
switch (page)
|
||||
{
|
||||
case kHIDPage_GenericDesktop:
|
||||
@ -580,7 +597,7 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
static const uint32_t axis_use_ids[6] =
|
||||
{ 48, 49, 51, 52, 50, 53 };
|
||||
|
||||
while(axis_use_ids[i] != use)
|
||||
while (i < 6 && axis_use_ids[i] != use)
|
||||
i++;
|
||||
|
||||
if (i < 6)
|
||||
@ -608,27 +625,37 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
adapter->axes = axis;
|
||||
}
|
||||
}
|
||||
else
|
||||
detected_button = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case kHIDPage_Consumer:
|
||||
case kHIDPage_Button:
|
||||
switch (type)
|
||||
{
|
||||
case kIOHIDElementTypeCollection:
|
||||
case kIOHIDElementTypeFeature:
|
||||
case kIOHIDElementTypeInput_ScanCodes:
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
case kIOHIDElementTypeInput_Axis:
|
||||
case kIOHIDElementTypeOutput:
|
||||
/* TODO/FIXME */
|
||||
break;
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
case kIOHIDElementTypeInput_Button:
|
||||
detected_button = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (detected_button)
|
||||
{
|
||||
apple_input_rec_t *btn = (apple_input_rec_t *)malloc(sizeof(apple_input_rec_t));
|
||||
btn->id = (uint32_t)(use - 1);
|
||||
btn->id = (uint32_t)use;
|
||||
btn->cookie = (IOHIDElementCookie)cookie;
|
||||
btn->next = NULL;
|
||||
|
||||
@ -647,10 +674,6 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
adapter->buttons = btn;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* take care of buttons/axes with duplicate 'use' values */
|
||||
@ -667,14 +690,18 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
}
|
||||
|
||||
tmp = adapter->buttons;
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
while(tmp->next)
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
while(tmpButtons)
|
||||
{
|
||||
apple_input_rec_t *next = tmpButtons->next;
|
||||
|
||||
tmpButtons->id = tmp->id + 1;
|
||||
tmpButtons->id = tmp->id;
|
||||
tmpButtons->next = NULL;
|
||||
tmp->next = tmpButtons;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user