(Apple HID) Cleanups

This commit is contained in:
twinaphex 2014-10-05 18:25:32 +02:00
parent b7f18050f2
commit 06f84b6f25

View File

@ -79,17 +79,14 @@ static void hid_device_input_callback(void* context, IOReturn result,
for (i = 0; i < 4; i ++) for (i = 0; i < 4; i ++)
{ {
CFIndex min, max, state; CFIndex min = IOHIDElementGetPhysicalMin(element);
float val; CFIndex max = IOHIDElementGetPhysicalMax(element) - min;
CFIndex state = IOHIDValueGetIntegerValue(value) - min;
float val = (float)state / (float)max;
if (use != axis_use_ids[i]) if (use != axis_use_ids[i])
continue; continue;
min = IOHIDElementGetPhysicalMin(element);
max = IOHIDElementGetPhysicalMax(element) - min;
state = IOHIDValueGetIntegerValue(value) - min;
val = (float)state / (float)max;
apple->axes[connection->slot][i] = apple->axes[connection->slot][i] =
((val * 2.0f) - 1.0f) * 32767.0f; ((val * 2.0f) - 1.0f) * 32767.0f;
} }
@ -148,7 +145,8 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
struct pad_connection* connection = (struct pad_connection*)context; struct pad_connection* connection = (struct pad_connection*)context;
if (connection) if (connection)
pad_connection_packet(connection->slot, connection->data, reportLength + 1); pad_connection_packet(connection->slot,
connection->data, reportLength + 1);
} }
static void add_device(void* context, IOReturn result, static void add_device(void* context, IOReturn result,
@ -182,7 +180,8 @@ static void add_device(void* context, IOReturn result,
productID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey)); productID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey));
CFNumberGetValue(productID, kCFNumberIntType, &connection->p_id); CFNumberGetValue(productID, kCFNumberIntType, &connection->p_id);
connection->slot = pad_connection_connect(device_name, connection, &hid_pad_connection_send_control); connection->slot = pad_connection_connect(device_name,
connection, &hid_pad_connection_send_control);
if (pad_connection_has_interface(connection->slot)) if (pad_connection_has_interface(connection->slot))
IOHIDDeviceRegisterInputReportCallback(device, IOHIDDeviceRegisterInputReportCallback(device,
@ -287,10 +286,11 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey)
if (!apple || joykey == NO_BTN) if (!apple || joykey == NO_BTN)
return false; return false;
// Check hat. /* Check hat. */
if (GET_HAT_DIR(joykey)) if (GET_HAT_DIR(joykey))
return false; return false;
// Check the button
/* Check the button. */
if ((port < MAX_PLAYERS) && (joykey < 32)) if ((port < MAX_PLAYERS) && (joykey < 32))
return ((apple->buttons[port] & (1 << joykey)) != 0) || return ((apple->buttons[port] & (1 << joykey)) != 0) ||
((buttons & (1 << joykey)) != 0); ((buttons & (1 << joykey)) != 0);