Set a function pointer inside each pad_connection device for

send_control
This commit is contained in:
Twinaphex 2014-10-04 22:05:38 +02:00
parent c90c2c5829
commit 8c269f119d
8 changed files with 26 additions and 18 deletions

View File

@ -50,7 +50,8 @@ static bool inquiry_off;
static bool inquiry_running;
static struct pad_connection g_connections[MAX_PLAYERS];
void pad_connection_send_control(void *data, uint8_t* data_buf, size_t size)
static void btpad_connection_send_control(void *data,
uint8_t* data_buf, size_t size)
{
struct pad_connection *connection = (struct pad_connection*)data;
@ -326,7 +327,7 @@ void btpad_packet_handler(uint8_t packet_type,
RARCH_LOG("BTpad: Got %.200s\n", (char*)&packet[9]);
connection->slot = pad_connection_connect(
(char*)packet + 9, connection);
(char*)packet + 9, connection, btpad_connection_send_control);
connection->state = BTPAD_CONNECTED;
}
break;

View File

@ -31,7 +31,7 @@ struct pad_connection
static IOHIDManagerRef g_hid_manager;
void pad_connection_send_control(void *data, uint8_t* data_buf, size_t size)
static void hid_pad_connection_send_control(void *data, uint8_t* data_buf, size_t size)
{
struct pad_connection* connection = (struct pad_connection*)data;
@ -190,7 +190,7 @@ static void add_device(void* context, IOReturn result,
productID = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey));
CFNumberGetValue(productID, kCFNumberIntType, &connection->p_id);
connection->slot = pad_connection_connect(device_name, connection);
connection->slot = pad_connection_connect(device_name, connection, hid_pad_connection_send_control);
if (pad_connection_has_interface(connection->slot))
IOHIDDeviceRegisterInputReportCallback(device,

View File

@ -23,6 +23,7 @@
struct hidpad_ps3_data
{
struct pad_connection* connection;
send_control_t send_control;
uint8_t data[512];
uint32_t slot;
bool have_led;
@ -49,11 +50,10 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
report_buffer[4] = device->motors[1] >> 8;
report_buffer[6] = device->motors[0] >> 8;
pad_connection_send_control(
device->connection, report_buffer, sizeof(report_buffer));
device->send_control(device->connection, report_buffer, sizeof(report_buffer));
}
static void* hidpad_ps3_connect(void *connect_data, uint32_t slot)
static void* hidpad_ps3_connect(void *connect_data, uint32_t slot, send_control_t ptr)
{
struct pad_connection* connection = (struct pad_connection*)connect_data;
struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)
@ -64,11 +64,12 @@ static void* hidpad_ps3_connect(void *connect_data, uint32_t slot)
device->connection = connection;
device->slot = slot;
device->send_control = ptr;
#ifdef IOS
/* Magic packet to start reports. */
static uint8_t data[] = {0x53, 0xF4, 0x42, 0x03, 0x00, 0x00};
pad_connection_send_control(device->connection, data, 6);
device->send_control(device->connection, data, 6);
#endif
/* Without this, the digital buttons won't be reported. */

View File

@ -23,6 +23,7 @@
struct hidpad_ps4_data
{
struct pad_connection* connection;
send_control_t send_control;
uint8_t data[512];
uint32_t slot;
bool have_led;
@ -43,11 +44,10 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device)
report_buffer[11] = rgb[(device->slot % 4)][2];
#endif
pad_connection_send_control(
device->connection, report_buffer, sizeof(report_buffer));
device->send_control(device->connection, report_buffer, sizeof(report_buffer));
}
static void* hidpad_ps4_connect(void *connect_data, uint32_t slot)
static void* hidpad_ps4_connect(void *connect_data, uint32_t slot, send_control_t ptr)
{
uint8_t data[0x25];
struct pad_connection* connection = (struct pad_connection*)connect_data;
@ -59,10 +59,11 @@ static void* hidpad_ps4_connect(void *connect_data, uint32_t slot)
device->connection = connection;
device->slot = slot;
device->send_control = ptr;
/* TODO - unsure of this */
/* This is needed to get full input packet over bluetooth. */
pad_connection_send_control(device->connection, data, 0x2);
device->send_control(device->connection, data, 0x2);
/* Without this, the digital buttons won't be reported. */
hidpad_ps4_send_control(device);

View File

@ -46,7 +46,7 @@ static int wiimote_send(struct wiimote_t* wm,
printf("\n");
#endif
pad_connection_send_control(wm->connection, buf, len + 2);
wm->send_control(wm->connection, buf, len + 2);
return 1;
}
@ -457,7 +457,8 @@ static int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data,
#endif
static void* hidpad_wii_connect(void *data, uint32_t slot)
static void* hidpad_wii_connect(void *data, uint32_t slot,
send_control_t ptr)
{
struct pad_connection *connection = (struct pad_connection*)data;
struct wiimote_t *device = (struct wiimote_t*)
@ -470,6 +471,7 @@ static void* hidpad_wii_connect(void *data, uint32_t slot)
device->unid = slot;
device->state = WIIMOTE_STATE_CONNECTED;
device->exp.type = EXP_NONE;
device->send_control = ptr;
wiimote_handshake(device, -1, NULL, -1);

View File

@ -42,7 +42,7 @@ static int find_vacant_pad(void)
return -1;
}
int32_t pad_connection_connect(const char* name, void *data)
int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr)
{
int pad = find_vacant_pad();
@ -72,7 +72,7 @@ int32_t pad_connection_connect(const char* name, void *data)
if (strstr(name, pad_map[i].name))
{
s->iface = pad_map[i].iface;
s->data = s->iface->connect(data, pad);
s->data = s->iface->connect(data, pad, ptr);
}
}

View File

@ -20,9 +20,11 @@
#include <stdint.h>
#include <stddef.h>
typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size);
typedef struct pad_connection_interface
{
void* (*connect)(void *data, uint32_t slot);
void* (*connect)(void *data, uint32_t slot, send_control_t ptr);
void (*disconnect)(void* device);
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
@ -34,7 +36,7 @@ typedef struct pad_connection_interface
extern pad_connection_interface_t pad_connection_wii;
extern pad_connection_interface_t pad_connection_ps3;
int32_t pad_connection_connect(const char* name, void *data);
int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr);
int32_t apple_joypad_connect_gcapi(void);

View File

@ -173,6 +173,7 @@ typedef struct wiimote_t
int unid;
struct pad_connection* connection;
send_control_t send_control;
/* Various state flags. */
int state;