mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 19:21:03 +00:00
Revert "Refactor slots to be a part of input_hid_driver.c now"
This reverts commit 646ded9d1c96f02f1746e4e96572bb1aec60255d.
This commit is contained in:
parent
f089fff42f
commit
db35a28e50
@ -21,6 +21,9 @@
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
#endif
|
||||
#ifdef HAVE_MFI
|
||||
#include "mfi_hid.h"
|
||||
#endif
|
||||
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <dynamic/dylib.h>
|
||||
@ -32,7 +35,7 @@
|
||||
|
||||
typedef struct btstack_hid
|
||||
{
|
||||
void *empty;
|
||||
joypad_connection_t *slots;
|
||||
} btstack_hid_t;
|
||||
|
||||
enum btpad_state
|
||||
@ -514,7 +517,7 @@ void btpad_packet_handler(uint8_t packet_type,
|
||||
|
||||
if ( connection->channels[0] == channel
|
||||
|| connection->channels[1] == channel)
|
||||
pad_connection_packet(hid_driver_find_slot(connection->slot), connection->slot, packet, size);
|
||||
pad_connection_packet(&slots[connection->slot], connection->slot, packet, size);
|
||||
}
|
||||
break;
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -692,7 +695,7 @@ void btpad_packet_handler(uint8_t packet_type,
|
||||
|
||||
RARCH_LOG("[BTpad]: Got %.200s.\n", (char*)&packet[9]);
|
||||
|
||||
connection->slot = pad_connection_pad_init(hid_driver_find_slot(connection->slot),
|
||||
connection->slot = pad_connection_pad_init(&slots[connection->slot],
|
||||
(char*)packet + 9, 0, 0, connection, &btpad_connection_send_control);
|
||||
connection->state = BTPAD_CONNECTED;
|
||||
}
|
||||
@ -717,7 +720,7 @@ void btpad_packet_handler(uint8_t packet_type,
|
||||
{
|
||||
connection->handle = 0;
|
||||
|
||||
pad_connection_pad_deinit(hid_driver_find_slot(connection->slot), connection->slot);
|
||||
pad_connection_pad_deinit(&slots[connection->slot], connection->slot);
|
||||
btpad_close_connection(connection);
|
||||
}
|
||||
}
|
||||
@ -755,7 +758,7 @@ static uint64_t btstack_hid_joypad_get_buttons(void *data, unsigned port)
|
||||
{
|
||||
btstack_hid_t *hid = (btstack_hid_t*)data;
|
||||
if (hid)
|
||||
return pad_connection_get_buttons(hid_driver_find_slot(port), port);
|
||||
return pad_connection_get_buttons(&hid->slots[port], port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -782,7 +785,7 @@ static bool btstack_hid_joypad_rumble(void *data, unsigned pad,
|
||||
btstack_hid_t *hid = (btstack_hid_t*)data;
|
||||
if (!hid)
|
||||
return false;
|
||||
return pad_connection_rumble(hid_driver_find_slot(pad), pad, effect, strength);
|
||||
return pad_connection_rumble(&hid->slots[pad], pad, effect, strength);
|
||||
}
|
||||
|
||||
static int16_t btstack_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
|
||||
@ -795,14 +798,14 @@ static int16_t btstack_hid_joypad_axis(void *data, unsigned port, uint32_t joyax
|
||||
|
||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||
{
|
||||
val += pad_connection_get_axis(hid_driver_find_slot(port), port, AXIS_NEG_GET(joyaxis));
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_NEG_GET(joyaxis));
|
||||
|
||||
if (val >= 0)
|
||||
val = 0;
|
||||
}
|
||||
else if(AXIS_POS_GET(joyaxis) < 4)
|
||||
{
|
||||
val += pad_connection_get_axis(hid_driver_find_slot(port), port, AXIS_POS_GET(joyaxis));
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_POS_GET(joyaxis));
|
||||
|
||||
if (val <= 0)
|
||||
val = 0;
|
||||
@ -818,7 +821,7 @@ static void btstack_hid_free(void *data)
|
||||
if (!hid)
|
||||
return;
|
||||
|
||||
hid_driver_destroy_slots();
|
||||
pad_connection_destroy(hid->slots);
|
||||
|
||||
if (hid)
|
||||
free(hid);
|
||||
@ -831,7 +834,9 @@ static void *btstack_hid_init(void)
|
||||
if (!hid)
|
||||
goto error;
|
||||
|
||||
if (!hid_driver_init_slots(MAX_USERS))
|
||||
hid->slots = pad_connection_init(MAX_USERS);
|
||||
|
||||
if (!hid->slots)
|
||||
goto error;
|
||||
|
||||
return hid;
|
||||
|
@ -25,6 +25,7 @@
|
||||
typedef struct apple_hid
|
||||
{
|
||||
IOHIDManagerRef ptr;
|
||||
joypad_connection_t *slots;
|
||||
} iohidmanager_hid_t;
|
||||
|
||||
struct iohidmanager_hid_adapter
|
||||
@ -53,7 +54,7 @@ static uint64_t iohidmanager_hid_joypad_get_buttons(void *data, unsigned port)
|
||||
{
|
||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
|
||||
if (hid)
|
||||
return pad_connection_get_buttons(hid_driver_find_slot(port), port);
|
||||
return pad_connection_get_buttons(&hid->slots[port], port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -92,7 +93,7 @@ static bool iohidmanager_hid_joypad_rumble(void *data, unsigned pad,
|
||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
|
||||
if (!hid)
|
||||
return false;
|
||||
return pad_connection_rumble(hid_driver_find_slot(pad), pad, effect, strength);
|
||||
return pad_connection_rumble(&hid->slots[pad], pad, effect, strength);
|
||||
}
|
||||
|
||||
static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
|
||||
@ -116,7 +117,7 @@ static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
val += apple->axes[port][AXIS_NEG_GET(joyaxis)];
|
||||
#endif
|
||||
val += pad_connection_get_axis(hid_driver_find_slot(port), port, AXIS_NEG_GET(joyaxis));
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_NEG_GET(joyaxis));
|
||||
|
||||
if (val >= 0)
|
||||
val = 0;
|
||||
@ -126,7 +127,7 @@ static int16_t iohidmanager_hid_joypad_axis(void *data, unsigned port, uint32_t
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH)
|
||||
val += apple->axes[port][AXIS_POS_GET(joyaxis)];
|
||||
#endif
|
||||
val += pad_connection_get_axis(hid_driver_find_slot(port), port, AXIS_POS_GET(joyaxis));
|
||||
val += pad_connection_get_axis(&hid->slots[port], port, AXIS_POS_GET(joyaxis));
|
||||
|
||||
if (val <= 0)
|
||||
val = 0;
|
||||
@ -155,7 +156,7 @@ static void iohidmanager_hid_device_report(void *data,
|
||||
iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL;
|
||||
|
||||
if (adapter)
|
||||
pad_connection_packet(hid_driver_find_slot(adapter->slot), adapter->slot,
|
||||
pad_connection_packet(&hid->slots[adapter->slot], adapter->slot,
|
||||
adapter->data, reportLength + 1);
|
||||
}
|
||||
|
||||
@ -267,7 +268,7 @@ static void iohidmanager_hid_device_remove(void *data, IOReturn result, void* se
|
||||
memset(apple->axes[adapter->slot], 0, sizeof(apple->axes));
|
||||
#endif
|
||||
|
||||
pad_connection_pad_deinit(hid_driver_find_slot(adapter->slot), adapter->slot);
|
||||
pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot);
|
||||
free(adapter);
|
||||
}
|
||||
}
|
||||
@ -362,13 +363,13 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
||||
dev_vid = iohidmanager_hid_device_get_vendor_id (device);
|
||||
dev_pid = iohidmanager_hid_device_get_product_id (device);
|
||||
|
||||
adapter->slot = hid_driver_slot_new(
|
||||
adapter->slot = pad_connection_pad_init(hid->slots,
|
||||
adapter->name, dev_vid, dev_pid, adapter, &iohidmanager_hid_device_send_control);
|
||||
|
||||
if (adapter->slot == -1)
|
||||
return;
|
||||
|
||||
if (hid_driver_slot_has_interface(adapter->slot))
|
||||
if (pad_connection_has_interface(hid->slots, adapter->slot))
|
||||
IOHIDDeviceRegisterInputReportCallback(device,
|
||||
adapter->data + 1, sizeof(adapter->data) - 1,
|
||||
iohidmanager_hid_device_report, adapter);
|
||||
@ -468,7 +469,8 @@ static void *iohidmanager_hid_init(void)
|
||||
|
||||
if (!hid_apple)
|
||||
goto error;
|
||||
if (!hid_driver_init_slots(MAX_USERS);
|
||||
hid_apple->slots = pad_connection_init(MAX_USERS);
|
||||
if (!hid_apple->slots)
|
||||
goto error;
|
||||
if (iohidmanager_hid_manager_init(hid_apple) == -1)
|
||||
goto error;
|
||||
@ -478,7 +480,9 @@ static void *iohidmanager_hid_init(void)
|
||||
return hid_apple;
|
||||
|
||||
error:
|
||||
hid_driver_free_slots();
|
||||
if (hid_apple->slots)
|
||||
free(hid_apple->slots);
|
||||
hid_apple->slots = NULL;
|
||||
if (hid_apple)
|
||||
free(hid_apple);
|
||||
return NULL;
|
||||
@ -491,7 +495,7 @@ static void iohidmanager_hid_free(void *data)
|
||||
if (!hid_apple || !hid_apple->ptr)
|
||||
return;
|
||||
|
||||
hid_driver_destroy_slots();
|
||||
pad_connection_destroy(hid_apple->slots);
|
||||
iohidmanager_hid_manager_free(hid_apple);
|
||||
|
||||
if (hid_apple)
|
||||
|
@ -31,6 +31,7 @@
|
||||
typedef struct libusb_hid
|
||||
{
|
||||
libusb_context *ctx;
|
||||
joypad_connection_t *slots;
|
||||
sthread_t *poll_thread;
|
||||
int hp; /* libusb_hotplug_callback_handle is just int */
|
||||
int quit;
|
||||
@ -92,8 +93,8 @@ static void adapter_thread(void *data)
|
||||
|
||||
libusb_interrupt_transfer(adapter->handle, adapter->endpoint_in, &adapter->data[1], adapter->endpoint_in_max_size, &size, 1000);
|
||||
|
||||
if (adapter && hid && size)
|
||||
pad_connection_packet(hid_driver_find_slot(adapter->slot), adapter->slot,
|
||||
if (adapter && hid && hid->slots && size)
|
||||
pad_connection_packet(&hid->slots[adapter->slot], adapter->slot,
|
||||
adapter->data, size+1);
|
||||
}
|
||||
}
|
||||
@ -269,14 +270,14 @@ static int add_adapter(void *data, struct libusb_device *dev)
|
||||
goto error;
|
||||
}
|
||||
|
||||
adapter->slot = hid_driver_slot_new(
|
||||
adapter->slot = pad_connection_pad_init(hid->slots,
|
||||
device_name, desc.idVendor, desc.idProduct,
|
||||
adapter, &libusb_hid_device_send_control);
|
||||
|
||||
if (adapter->slot == -1)
|
||||
goto error;
|
||||
|
||||
if (!hid_driver_slot_has_interface(adapter->slot))
|
||||
if (!pad_connection_has_interface(hid->slots, adapter->slot))
|
||||
{
|
||||
RARCH_ERR(" Interface not found (%s).\n", adapter->name);
|
||||
goto error;
|
||||
@ -350,7 +351,7 @@ static int remove_adapter(void *data, struct libusb_device *dev)
|
||||
adapter->next->quitting = true;
|
||||
sthread_join(adapter->next->thread);
|
||||
|
||||
hid_driver_slot_free(adapter->slot);
|
||||
pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot);
|
||||
|
||||
slock_free(adapter->send_control_lock);
|
||||
fifo_free(adapter->send_control_buffer);
|
||||
@ -410,7 +411,7 @@ static uint64_t libusb_hid_joypad_get_buttons(void *data, unsigned port)
|
||||
{
|
||||
libusb_hid_t *hid = (libusb_hid_t*)data;
|
||||
if (hid)
|
||||
return pad_connection_get_buttons(hid_driver_find_slot(port), port);
|
||||
return pad_connection_get_buttons(&hid->slots[port], port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -437,7 +438,7 @@ static bool libusb_hid_joypad_rumble(void *data, unsigned pad,
|
||||
libusb_hid_t *hid = (libusb_hid_t*)data;
|
||||
if (!hid)
|
||||
return false;
|
||||
return pad_connection_rumble(hid_driver_find_slot(pad), pad, effect, strength);
|
||||
return pad_connection_rumble(&hid->slots[pad], pad, effect, strength);
|
||||
}
|
||||
|
||||
static int16_t libusb_hid_joypad_axis(void *data,
|
||||
@ -451,7 +452,7 @@ static int16_t libusb_hid_joypad_axis(void *data,
|
||||
|
||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||
{
|
||||
val = pad_connection_get_axis(hid_driver_find_slot(port),
|
||||
val = pad_connection_get_axis(&hid->slots[port],
|
||||
port, AXIS_NEG_GET(joyaxis));
|
||||
|
||||
if (val >= 0)
|
||||
@ -459,7 +460,7 @@ static int16_t libusb_hid_joypad_axis(void *data,
|
||||
}
|
||||
else if(AXIS_POS_GET(joyaxis) < 4)
|
||||
{
|
||||
val = pad_connection_get_axis(hid_driver_find_slot(port),
|
||||
val = pad_connection_get_axis(&hid->slots[port],
|
||||
port, AXIS_POS_GET(joyaxis));
|
||||
|
||||
if (val <= 0)
|
||||
@ -484,7 +485,7 @@ static void libusb_hid_free(void *data)
|
||||
sthread_join(hid->poll_thread);
|
||||
}
|
||||
|
||||
hid_driver_destroy_slots();
|
||||
pad_connection_destroy(hid->slots);
|
||||
|
||||
libusb_hotplug_deregister_callback(hid->ctx, hid->hp);
|
||||
|
||||
@ -523,7 +524,9 @@ static void *libusb_hid_init(void)
|
||||
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG))
|
||||
goto error;
|
||||
|
||||
if (!hid_driver_init_slots(MAX_USERS))
|
||||
hid->slots = pad_connection_init(MAX_USERS);
|
||||
|
||||
if (!hid->slots)
|
||||
goto error;
|
||||
|
||||
count = libusb_get_device_list(hid->ctx, &devices);
|
||||
|
26
input/drivers_hid/mfi_hid.h
Normal file
26
input/drivers_hid/mfi_hid.h
Normal file
@ -0,0 +1,26 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2013-2014 - Jason Fetters
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __APPLE_RARCH_GAMECONTROLLER_H__
|
||||
#define __APPLE_RARCH_GAMECONTROLLER_H__
|
||||
|
||||
#include "../../input/connect/joypad_connection.h"
|
||||
|
||||
joypad_connection_t *slots;
|
||||
|
||||
void apple_gamecontroller_init(void);
|
||||
void apple_gamecontroller_poll_all(void);
|
||||
|
||||
#endif
|
187
input/drivers_hid/mfi_hid.m
Normal file
187
input/drivers_hid/mfi_hid.m
Normal file
@ -0,0 +1,187 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2013-2014 - Jason Fetters
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boolean.h>
|
||||
|
||||
#include <AvailabilityMacros.h>
|
||||
#import <GameController/GameController.h>
|
||||
|
||||
#include "mfi_hid.h"
|
||||
#include "../../input/drivers/cocoa_input.h"
|
||||
|
||||
enum
|
||||
{
|
||||
GCCONTROLLER_PLAYER_INDEX_UNSET = -1,
|
||||
};
|
||||
|
||||
static bool apple_gamecontroller_available(void)
|
||||
{
|
||||
int major, minor;
|
||||
get_ios_version(&major, &minor);
|
||||
|
||||
if (major <= 6)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_poll(GCController *controller)
|
||||
{
|
||||
uint32_t slot, pause;
|
||||
uint32_t *buttons;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
|
||||
if (!apple || !controller)
|
||||
return;
|
||||
|
||||
slot = (uint32_t)controller.playerIndex;
|
||||
/* retain the start (pause) value */
|
||||
pause = apple->mfi_buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
|
||||
apple->mfi_buttons[slot] = 0;
|
||||
memset(apple->axes[slot], 0, sizeof(apple->axes[0]));
|
||||
|
||||
apple->mfi_buttons[slot] |= pause;
|
||||
|
||||
buttons = &apple->mfi_buttons[slot];
|
||||
|
||||
if (controller.extendedGamepad)
|
||||
{
|
||||
GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad;
|
||||
|
||||
*buttons |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
*buttons |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
*buttons |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
*buttons |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
*buttons |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
||||
*buttons |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
||||
*buttons |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
||||
*buttons |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
||||
*buttons |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
||||
*buttons |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
||||
*buttons |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
|
||||
*buttons |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
|
||||
apple->axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f;
|
||||
apple->axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f;
|
||||
apple->axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f;
|
||||
apple->axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f;
|
||||
apple->axes[slot][4] = gp.rightThumbstick.yAxis.value * 32767.0f;
|
||||
apple->axes[slot][5] = gp.rightThumbstick.yAxis.value * 32767.0f;
|
||||
|
||||
}
|
||||
else if (controller.gamepad)
|
||||
{
|
||||
GCGamepad *gp = (GCGamepad *)controller.gamepad;
|
||||
|
||||
*buttons |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
*buttons |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
*buttons |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
*buttons |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
*buttons |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
||||
*buttons |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
||||
*buttons |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
||||
*buttons |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
||||
*buttons |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
||||
*buttons |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
void apple_gamecontroller_poll_all(void)
|
||||
{
|
||||
if (!apple_gamecontroller_available())
|
||||
return;
|
||||
|
||||
for (GCController *controller in [GCController controllers])
|
||||
apple_gamecontroller_poll(controller);
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_register(GCGamepad *gamepad)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data;
|
||||
gamepad.valueChangedHandler = ^(GCGamepad *updateGamepad, GCControllerElement *element) {
|
||||
apple_gamecontroller_poll(updateGamepad.controller);
|
||||
};
|
||||
|
||||
gamepad.controller.controllerPausedHandler = ^(GCController *controller) {
|
||||
|
||||
uint32_t slot = (uint32_t)controller.playerIndex;
|
||||
|
||||
apple->mfi_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
apple->mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static int32_t apple_joypad_connect_gcapi(joypad_connection_t *joyconn)
|
||||
{
|
||||
int pad = pad_connection_find_vacant_pad(joyconn);
|
||||
|
||||
if (pad >= 0 && pad < MAX_USERS)
|
||||
{
|
||||
joypad_connection_t *s = (joypad_connection_t*)&joyconn[pad];
|
||||
|
||||
if (s)
|
||||
s->connected = true;
|
||||
}
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_connect(GCController *controller)
|
||||
{
|
||||
int32_t slot = apple_joypad_connect_gcapi(slots);
|
||||
|
||||
controller.playerIndex = (slot >= 0 && slot < MAX_USERS) ? slot : GCCONTROLLER_PLAYER_INDEX_UNSET;
|
||||
|
||||
if (controller.playerIndex == GCControllerPlayerIndexUnset)
|
||||
return;
|
||||
|
||||
apple_gamecontroller_register(controller.gamepad);
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_disconnect(GCController* controller)
|
||||
{
|
||||
unsigned pad = (uint32_t)controller.playerIndex;
|
||||
if (pad == GCCONTROLLER_PLAYER_INDEX_UNSET)
|
||||
return;
|
||||
|
||||
pad_connection_pad_deinit(&slots[pad], pad);
|
||||
}
|
||||
|
||||
void apple_gamecontroller_init(void)
|
||||
{
|
||||
if (!apple_gamecontroller_available())
|
||||
return;
|
||||
#ifdef __IPHONE_7_0
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
apple_gamecontroller_connect([note object]);
|
||||
}];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
apple_gamecontroller_disconnect([note object]);
|
||||
} ];
|
||||
#endif
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
|
||||
typedef struct wiiusb_hid
|
||||
{
|
||||
joypad_connection_t *slots;
|
||||
int hp; /* wiiusb_hotplug_callback_handle is just int */
|
||||
int quit;
|
||||
} wiiusb_hid_t;
|
||||
@ -91,8 +92,8 @@ static void adapter_thread(void *data)
|
||||
//RARCH_LOG("%03i %03i %03i %03i\n", adapter->data[0], adapter->data[1], adapter->data[2], adapter->data[3], adapter->data[4]);
|
||||
//memmove(&adapter->data[1], &adapter->data[0], 2048);
|
||||
|
||||
if (adapter && hid && && size)
|
||||
pad_connection_packet(hid_driver_find_slot(adapter->slot), adapter->slot,
|
||||
if (adapter && hid && hid->slots && size)
|
||||
pad_connection_packet(&hid->slots[adapter->slot], adapter->slot,
|
||||
adapter->data - 1, size+1);
|
||||
}
|
||||
}
|
||||
@ -197,7 +198,7 @@ static int remove_adapter(void *data, usb_device_entry *dev)
|
||||
adapter->next->quitting = true;
|
||||
sthread_join(adapter->next->thread);
|
||||
|
||||
hid_driver_slot_free(adapter->slot);
|
||||
pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot);
|
||||
|
||||
slock_free(adapter->send_control_lock);
|
||||
fifo_free(adapter->send_control_buffer);
|
||||
@ -299,14 +300,14 @@ static int add_adapter(void *data, usb_device_entry *dev)
|
||||
goto error;
|
||||
}
|
||||
|
||||
adapter->slot = hid_driver_slot_new(
|
||||
adapter->slot = pad_connection_pad_init(hid->slots,
|
||||
device_name, desc.idVendor, desc.idProduct,
|
||||
adapter, &wiiusb_hid_device_send_control);
|
||||
|
||||
if (adapter->slot == -1)
|
||||
goto error;
|
||||
|
||||
if (!hid_driver_slot_has_interface(adapter->slot))
|
||||
if (!pad_connection_has_interface(hid->slots, adapter->slot))
|
||||
{
|
||||
RARCH_ERR(" Interface not found (%s).\n", adapter->name);
|
||||
goto error;
|
||||
@ -394,7 +395,7 @@ static uint64_t wiiusb_hid_joypad_get_buttons(void *data, unsigned port)
|
||||
{
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
if (hid)
|
||||
return pad_connection_get_buttons(hid_driver_find_slot(port), port);
|
||||
return pad_connection_get_buttons(&hid->slots[port], port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -421,7 +422,7 @@ static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad,
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
if (!hid)
|
||||
return false;
|
||||
return pad_connection_rumble(hid_driver_find_slot(pad), pad, effect, strength);
|
||||
return pad_connection_rumble(&hid->slots[pad], pad, effect, strength);
|
||||
}
|
||||
|
||||
static int16_t wiiusb_hid_joypad_axis(void *data,
|
||||
@ -435,7 +436,7 @@ static int16_t wiiusb_hid_joypad_axis(void *data,
|
||||
|
||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||
{
|
||||
val = pad_connection_get_axis(hid_driver_find_slot(port),
|
||||
val = pad_connection_get_axis(&hid->slots[port],
|
||||
port, AXIS_NEG_GET(joyaxis));
|
||||
|
||||
if (val >= 0)
|
||||
@ -443,7 +444,7 @@ static int16_t wiiusb_hid_joypad_axis(void *data,
|
||||
}
|
||||
else if(AXIS_POS_GET(joyaxis) < 4)
|
||||
{
|
||||
val = pad_connection_get_axis(hid_driver_find_slot(port),
|
||||
val = pad_connection_get_axis(&hid->slots[port],
|
||||
port, AXIS_POS_GET(joyaxis));
|
||||
|
||||
if (val <= 0)
|
||||
@ -462,7 +463,7 @@ static void wiiusb_hid_free(void *data)
|
||||
RARCH_ERR("could not remove device %p\n",
|
||||
adapters.next->device);
|
||||
|
||||
hid_driver_destroy_slots();
|
||||
pad_connection_destroy(hid->slots);
|
||||
|
||||
// wiiusb_hotplug_deregister_callback(hid->ctx, hid->hp);
|
||||
|
||||
@ -483,7 +484,9 @@ static void *wiiusb_hid_init(void)
|
||||
if (!hid)
|
||||
goto error;
|
||||
|
||||
if (!hid_driver_init_slots(MAX_USERS))
|
||||
hid->slots = pad_connection_init(MAX_USERS);
|
||||
|
||||
if (!hid->slots)
|
||||
goto error;
|
||||
|
||||
dev_entries = (usb_device_entry *)calloc(MAX_USERS, sizeof(*dev_entries));
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "../drivers/cocoa_input.h"
|
||||
#include "../connect/joypad_connection.h"
|
||||
|
||||
joypad_connection_t *slots;
|
||||
|
||||
enum
|
||||
{
|
||||
GCCONTROLLER_PLAYER_INDEX_UNSET = -1,
|
||||
@ -134,9 +136,24 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
|
||||
};
|
||||
}
|
||||
|
||||
static int32_t apple_gamecontroller_joypad_connect_gcapi(joypad_connection_t *joyconn)
|
||||
{
|
||||
int pad = pad_connection_find_vacant_pad(joyconn);
|
||||
|
||||
if (pad >= 0 && pad < MAX_USERS)
|
||||
{
|
||||
joypad_connection_t *s = (joypad_connection_t*)&joyconn[pad];
|
||||
|
||||
if (s)
|
||||
s->connected = true;
|
||||
}
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_joypad_connect(GCController *controller)
|
||||
{
|
||||
int32_t slot = hid_driver_slot_connect();
|
||||
int32_t slot = apple_gamecontroller_joypad_connect_gcapi(slots);
|
||||
|
||||
controller.playerIndex = (slot >= 0 && slot < MAX_USERS) ? slot : GCCONTROLLER_PLAYER_INDEX_UNSET;
|
||||
|
||||
@ -152,7 +169,7 @@ static void apple_gamecontroller_joypad_disconnect(GCController* controller)
|
||||
if (pad == GCCONTROLLER_PLAYER_INDEX_UNSET)
|
||||
return;
|
||||
|
||||
hid_driver_slot_free(pad);
|
||||
pad_connection_pad_deinit(&slots[pad], pad);
|
||||
}
|
||||
|
||||
bool apple_gamecontroller_joypad_init(void *data)
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "../general.h"
|
||||
#include "../string_list_special.h"
|
||||
|
||||
static joypad_connection_t *slots;
|
||||
|
||||
static hid_driver_t *hid_drivers[] = {
|
||||
#if defined(__APPLE__) && defined(IOS)
|
||||
&btstack_hid,
|
||||
@ -71,68 +69,6 @@ const char *hid_driver_find_ident(int idx)
|
||||
return drv->ident;
|
||||
}
|
||||
|
||||
joypad_connection_t *hid_driver_find_slot(unsigned idx)
|
||||
{
|
||||
joypad_connection_t *conn = &slots[idx];
|
||||
|
||||
if (!conn)
|
||||
return NULL;
|
||||
return conn;
|
||||
}
|
||||
|
||||
void hid_driver_free_slots(void)
|
||||
{
|
||||
if (slots)
|
||||
free(slots);
|
||||
slots = NULL;
|
||||
}
|
||||
|
||||
void hid_driver_destroy_slots(void)
|
||||
{
|
||||
pad_connection_destroy(slots);
|
||||
}
|
||||
|
||||
bool hid_driver_slot_has_interface(unsigned idx)
|
||||
{
|
||||
return pad_connection_has_interface(slots, idx);
|
||||
}
|
||||
|
||||
int hid_driver_slot_new(const char *name, uint16_t vid, uint16_t pid,
|
||||
void *data, send_control_t ptr)
|
||||
{
|
||||
return pad_connection_pad_init(slots, name, vid, pid, data, ptr);
|
||||
}
|
||||
|
||||
void hid_driver_slot_free(unsigned idx)
|
||||
{
|
||||
pad_connection_pad_deinit(&slots[idx], idx);
|
||||
}
|
||||
|
||||
int hid_driver_slot_connect(void)
|
||||
{
|
||||
int pad = pad_connection_find_vacant_pad(slots);
|
||||
|
||||
if (pad >= 0 && pad < MAX_USERS)
|
||||
{
|
||||
joypad_connection_t *s = (joypad_connection_t*)&slots[pad];
|
||||
|
||||
if (s)
|
||||
s->connected = true;
|
||||
}
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
bool hid_driver_init_slots(unsigned max_users)
|
||||
{
|
||||
slots = pad_connection_init(max_users);
|
||||
|
||||
if (!slots)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_get_hid_driver_options:
|
||||
*
|
||||
|
@ -25,7 +25,6 @@ extern "C" {
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../libretro.h"
|
||||
#include "connect/joypad_connection.h"
|
||||
|
||||
typedef struct hid_driver hid_driver_t;
|
||||
|
||||
@ -86,23 +85,6 @@ const char* config_get_hid_driver_options(void);
|
||||
**/
|
||||
const hid_driver_t *input_hid_init_first(void);
|
||||
|
||||
joypad_connection_t *hid_driver_find_slot(unsigned idx);
|
||||
|
||||
int hid_driver_slot_new(const char *name, uint16_t vid,
|
||||
uint16_t pid, void *data, send_control_t ptr);
|
||||
|
||||
void hid_driver_slot_free(unsigned idx);
|
||||
|
||||
bool hid_driver_slot_has_interface(unsigned idx);
|
||||
|
||||
void hid_driver_destroy_slots(void);
|
||||
|
||||
bool hid_driver_init_slots(unsigned max_users);
|
||||
|
||||
void hid_driver_free_slots(void);
|
||||
|
||||
int hid_driver_slot_connect(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -28,6 +28,10 @@
|
||||
#include "../../menu/menu_setting.h"
|
||||
#include "../../retroarch.h"
|
||||
|
||||
#ifdef HAVE_MFI
|
||||
#include "../../input/drivers_hid/mfi_hid.h"
|
||||
#endif
|
||||
|
||||
#include "../../input/drivers_hid/btstack_hid.h"
|
||||
#include "../../frontend/frontend.h"
|
||||
#include "../../runloop_data.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user