mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 06:40:18 +00:00
(pad_connection) Add pad_connection_init
This commit is contained in:
parent
7b5407379c
commit
907b83065b
@ -132,16 +132,12 @@ void btpad_packet_handler(uint8_t packet_type,
|
||||
{
|
||||
struct pad_connection* connection =
|
||||
(struct pad_connection*)&g_connections[i];
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
|
||||
if (connection && connection->state == BTPAD_CONNECTED
|
||||
&& (connection->channels[0] == channel ||
|
||||
connection->channels[1] == channel))
|
||||
{
|
||||
pad_connection_packet(connection->slot, packet, size);
|
||||
apple->buttons[connection->slot] = pad_connection_get_buttons(connection->slot);
|
||||
for (i = 0; i < 4; i++)
|
||||
apple->axes[connection->slot][i] = pad_connection_get_axis(connection->slot, i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -146,17 +146,18 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
|
||||
CFIndex reportLength)
|
||||
{
|
||||
struct pad_connection* connection = (struct pad_connection*)context;
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
|
||||
if (connection && apple)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (connection)
|
||||
pad_connection_packet(connection->slot, connection->data, reportLength + 1);
|
||||
apple->buttons[connection->slot] = pad_connection_get_buttons(connection->slot);
|
||||
for (i = 0; i < 4; i++)
|
||||
apple->axes[connection->slot][i] = pad_connection_get_axis(connection->slot, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void apple_hid_receive_control(unsigned index)
|
||||
{
|
||||
int i;
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
apple->buttons[index] = pad_connection_get_buttons(index);
|
||||
for (i = 0; i < 4; i++)
|
||||
apple->axes[index][i] = pad_connection_get_axis(index, i);
|
||||
}
|
||||
|
||||
static void add_device(void* context, IOReturn result,
|
||||
@ -257,6 +258,8 @@ static bool apple_joypad_init(void)
|
||||
kCFRunLoopCommonModes);
|
||||
|
||||
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
|
||||
|
||||
pad_connection_init(&apple_hid_receive_control);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -22,9 +22,20 @@
|
||||
#include "../apple/iOS/bluetooth/btdynamic.c"
|
||||
#include "../apple/iOS/bluetooth/btpad.c"
|
||||
#include "../apple/iOS/bluetooth/btpad_queue.c"
|
||||
#include "joypad_connection.h"
|
||||
|
||||
static void apple_joypad_ios_receive_control(unsigned index)
|
||||
{
|
||||
int i;
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
||||
apple->buttons[index] = pad_connection_get_buttons(index);
|
||||
for (i = 0; i < 4; i++)
|
||||
apple->axes[index][i] = pad_connection_get_axis(index, i);
|
||||
}
|
||||
|
||||
static bool apple_joypad_init(void)
|
||||
{
|
||||
pad_connection_init(&apple_joypad_ios_receive_control);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ typedef struct
|
||||
{
|
||||
bool used;
|
||||
struct pad_connection_interface *iface;
|
||||
receive_control_t receive_control;
|
||||
void* data;
|
||||
|
||||
bool is_gcapi;
|
||||
@ -36,12 +37,21 @@ static int find_vacant_pad(void)
|
||||
if (slots[i].used)
|
||||
continue;
|
||||
|
||||
memset(&slots[i], 0, sizeof(slots[0]));
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void pad_connection_init(receive_control_t receive_control)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
memset(&slots[i], 0, sizeof(slots[0]));
|
||||
slots[i].receive_control = receive_control;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr)
|
||||
{
|
||||
int pad = find_vacant_pad();
|
||||
@ -117,8 +127,13 @@ void pad_connection_packet(uint32_t pad,
|
||||
{
|
||||
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
|
||||
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
if (s->iface && s->data && s->iface->packet_handler)
|
||||
s->iface->packet_handler(s->data, data, length);
|
||||
if (s->receive_control)
|
||||
s->receive_control(pad);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,6 +172,8 @@ void pad_connection_destroy(void)
|
||||
if (slots[i].used && slots[i].iface
|
||||
&& slots[i].iface->set_rumble)
|
||||
{
|
||||
slots[i].used = false;
|
||||
slots[i].iface = NULL;
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
|
||||
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size);
|
||||
typedef void (*receive_control_t)(unsigned index);
|
||||
|
||||
typedef struct pad_connection_interface
|
||||
{
|
||||
@ -40,6 +41,10 @@ int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr)
|
||||
|
||||
int32_t apple_joypad_connect_gcapi(void);
|
||||
|
||||
void pad_connection_init(receive_control_t receive_control);
|
||||
|
||||
void pad_connection_destroy(void);
|
||||
|
||||
void pad_connection_disconnect(uint32_t slot);
|
||||
|
||||
void pad_connection_packet(uint32_t slot, uint8_t* data, uint32_t length);
|
||||
|
Loading…
x
Reference in New Issue
Block a user