From b9ed7362eb29078bb2aec8297344b2b0ea42dc21 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 30 Sep 2014 13:53:36 +0200 Subject: [PATCH] (Apple/OSX) Refactor hid_device_input_callback pt. 2 --- input/hid/apple_input_hid.c | 86 ++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/input/hid/apple_input_hid.c b/input/hid/apple_input_hid.c index 10f8a91c0e..63a0e9ebce 100644 --- a/input/hid/apple_input_hid.c +++ b/input/hid/apple_input_hid.c @@ -55,60 +55,60 @@ static void hid_device_input_callback(void* context, IOReturn result, /* Joystick handler. * TODO: Can GamePad work the same? */ - + if ( - (type == kIOHIDElementTypeInput_Misc) || - (type == kIOHIDElementTypeInput_Button) || - (type == kIOHIDElementTypeInput_Axis) - ) + (type == kIOHIDElementTypeInput_Misc) || + (type == kIOHIDElementTypeInput_Button) || + (type == kIOHIDElementTypeInput_Axis) + ) { - switch (page) - { - case kHIDPage_GenericDesktop: - switch (type) - { + switch (page) + { + case kHIDPage_GenericDesktop: + switch (type) + { case kIOHIDElementTypeInput_Misc: - { - static const uint32_t axis_use_ids[4] = { 48, 49, 50, 53 }; - int i; - - for (i = 0; i < 4; i ++) - { - if (use == axis_use_ids[i]) - { + { + static const uint32_t axis_use_ids[4] = { 48, 49, 50, 53 }; + int i; + + for (i = 0; i < 4; i ++) + { + if (use == axis_use_ids[i]) + { CFIndex min, max, state; float val; - + min = IOHIDElementGetPhysicalMin(element); max = IOHIDElementGetPhysicalMax(element) - min; state = IOHIDValueGetIntegerValue(value) - min; - + val = (float)state / (float)max; g_current_input_data.pad_axis[connection->slot][i] = - ((val * 2.0f) - 1.0f) * 32767.0f; - } - } - break; - } - break; - case kHIDPage_Button: - switch (type) - { - case kIOHIDElementTypeInput_Button: - { - CFIndex state = IOHIDValueGetIntegerValue(value); - - if (state) - g_current_input_data.pad_buttons[connection->slot] |= (1 << (use - 1)); - else - g_current_input_data.pad_buttons[connection->slot] &= ~(1 << (use - 1)); - } - break; - } - break; - } + ((val * 2.0f) - 1.0f) * 32767.0f; + } + } + break; + } + break; + } break; - } + case kHIDPage_Button: + switch (type) + { + case kIOHIDElementTypeInput_Button: + { + CFIndex state = IOHIDValueGetIntegerValue(value); + + if (state) + g_current_input_data.pad_buttons[connection->slot] |= (1 << (use - 1)); + else + g_current_input_data.pad_buttons[connection->slot] &= ~(1 << (use - 1)); + } + break; + } + break; + } } }