mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-26 21:36:26 +00:00
(IOHIDManager) Make axes code independent from CocoaTouch
This commit is contained in:
parent
3e81b4deef
commit
2fa91ba26c
@ -211,8 +211,13 @@ int32_t cocoa_input_find_any_axis(uint32_t port)
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
int16_t value = apple->axes[port][i];
|
||||
int16_t value = apple->joypad ? apple->joypad->axis(port, i) : 0;
|
||||
|
||||
if (abs(value) > 0x4000)
|
||||
return (value < 0) ? -(i + 1) : i + 1;
|
||||
|
||||
value = apple->sec_joypad ? apple->sec_joypad->axis(port, i) : value;
|
||||
|
||||
if (abs(value) > 0x4000)
|
||||
return (value < 0) ? -(i + 1) : i + 1;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ typedef struct
|
||||
uint32_t key_state[MAX_KEYS];
|
||||
|
||||
uint32_t buttons[MAX_USERS];
|
||||
int16_t axes[MAX_USERS][6];
|
||||
int8_t hats[NUM_HATS][2];
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
@ -33,6 +33,7 @@ struct iohidmanager_hid_adapter
|
||||
uint32_t slot;
|
||||
IOHIDDeviceRef handle;
|
||||
char name[PATH_MAX_LENGTH];
|
||||
int16_t axes[MAX_USERS][6];
|
||||
uint8_t data[2048];
|
||||
};
|
||||
|
||||
@ -98,25 +99,15 @@ static bool iohidmanager_hid_joypad_rumble(void *data, unsigned pad,
|
||||
|
||||
static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
|
||||
{
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
driver_t *driver = driver_get_ptr();
|
||||
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
|
||||
#endif
|
||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
|
||||
int16_t val = 0;
|
||||
|
||||
if (joyaxis == AXIS_NONE)
|
||||
return 0;
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
if (!apple)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (AXIS_NEG_GET(joyaxis) < 6)
|
||||
{
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
val += apple->axes[port][AXIS_NEG_GET(joyaxis)];
|
||||
#endif
|
||||
val += adapter->axes[port][AXIS_NEG_GET(joyaxis)];
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_NEG_GET(joyaxis));
|
||||
|
||||
if (val >= 0)
|
||||
@ -124,9 +115,7 @@ static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t
|
||||
}
|
||||
else if(AXIS_POS_GET(joyaxis) < 6)
|
||||
{
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
val += apple->axes[port][AXIS_POS_GET(joyaxis)];
|
||||
#endif
|
||||
val += adapter->axes[port][AXIS_POS_GET(joyaxis)];
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_POS_GET(joyaxis));
|
||||
|
||||
if (val <= 0)
|
||||
@ -208,20 +197,16 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
|
||||
|
||||
for (i = 0; i < 6; i ++)
|
||||
{
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
CFIndex min = IOHIDElementGetPhysicalMin(element);
|
||||
CFIndex state = IOHIDValueGetIntegerValue(value) - min;
|
||||
CFIndex max = IOHIDElementGetPhysicalMax(element) - min;
|
||||
float val = (float)state / (float)max;
|
||||
#endif
|
||||
|
||||
if (use != axis_use_ids[i])
|
||||
continue;
|
||||
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
apple->axes[adapter->slot][i] =
|
||||
adapter->axes[adapter->slot][i] =
|
||||
((val * 2.0f) - 1.0f) * 32767.0f;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -265,7 +250,7 @@ static void iohidmanager_hid_device_remove(void *data, IOReturn result, void* se
|
||||
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
apple->buttons[adapter->slot] = 0;
|
||||
memset(apple->axes[adapter->slot], 0, sizeof(apple->axes));
|
||||
memset(adapter->axes[adapter->slot], 0, sizeof(adapter->axes));
|
||||
#endif
|
||||
|
||||
pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot);
|
||||
|
Loading…
x
Reference in New Issue
Block a user