From 8c269f119d7d8ddd6b72418e5a2a61aa6564992e Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 4 Oct 2014 22:05:38 +0200 Subject: [PATCH] Set a function pointer inside each pad_connection device for send_control --- apple/iOS/bluetooth/btpad.c | 5 +++-- input/apple_joypad_hid.c | 4 ++-- input/apple_joypad_ps3.c | 9 +++++---- input/apple_joypad_ps4.c | 9 +++++---- input/apple_joypad_wii.c | 6 ++++-- input/joypad_connection.c | 4 ++-- input/joypad_connection.h | 6 ++++-- input/wiimote.h | 1 + 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/apple/iOS/bluetooth/btpad.c b/apple/iOS/bluetooth/btpad.c index 8a962d5bed..2d0f2b4118 100644 --- a/apple/iOS/bluetooth/btpad.c +++ b/apple/iOS/bluetooth/btpad.c @@ -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; diff --git a/input/apple_joypad_hid.c b/input/apple_joypad_hid.c index 6276c49416..4d715f72b7 100644 --- a/input/apple_joypad_hid.c +++ b/input/apple_joypad_hid.c @@ -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, diff --git a/input/apple_joypad_ps3.c b/input/apple_joypad_ps3.c index 5152fac89e..e653303fca 100644 --- a/input/apple_joypad_ps3.c +++ b/input/apple_joypad_ps3.c @@ -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. */ diff --git a/input/apple_joypad_ps4.c b/input/apple_joypad_ps4.c index 400472bf8c..60dea3afaa 100644 --- a/input/apple_joypad_ps4.c +++ b/input/apple_joypad_ps4.c @@ -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); diff --git a/input/apple_joypad_wii.c b/input/apple_joypad_wii.c index 87da0ddd3e..54605f0b42 100644 --- a/input/apple_joypad_wii.c +++ b/input/apple_joypad_wii.c @@ -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); diff --git a/input/joypad_connection.c b/input/joypad_connection.c index b6f09141d6..ac2d449182 100644 --- a/input/joypad_connection.c +++ b/input/joypad_connection.c @@ -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); } } diff --git a/input/joypad_connection.h b/input/joypad_connection.h index 0beeb38f17..9aff5b1363 100644 --- a/input/joypad_connection.h +++ b/input/joypad_connection.h @@ -20,9 +20,11 @@ #include #include +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); diff --git a/input/wiimote.h b/input/wiimote.h index 824403b4b2..e831be0378 100644 --- a/input/wiimote.h +++ b/input/wiimote.h @@ -173,6 +173,7 @@ typedef struct wiimote_t int unid; struct pad_connection* connection; + send_control_t send_control; /* Various state flags. */ int state;