From ad6aebb2779ffe27237c76f4c8b40994e9ee3f2c Mon Sep 17 00:00:00 2001 From: meancoot Date: Thu, 3 Oct 2013 18:04:28 -0400 Subject: [PATCH] (Apple) Add rumble support for DualShock 3 controllers. --- apple/common/apple_input.c | 10 ++++++++++ apple/common/apple_input.h | 5 +++-- apple/common/apple_joypad.c | 22 +++++++++++++++++++++- apple/common/hidpad/apple_ps3_pad.c | 20 ++++++++++++++++++-- apple/common/hidpad/apple_wii_pad.c | 8 +++++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/apple/common/apple_input.c b/apple/common/apple_input.c index 720748f788..493736bb87 100644 --- a/apple/common/apple_input.c +++ b/apple/common/apple_input.c @@ -242,6 +242,7 @@ static bool apple_bind_button_pressed(void *data, int key) static void apple_input_free_input(void *data) { (void)data; + g_joydriver->destroy(); } static void apple_input_set_keybinds(void *data, unsigned device, unsigned port, @@ -305,6 +306,12 @@ static void apple_input_set_keybinds(void *data, unsigned device, unsigned port, #endif } +static bool apple_input_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength) +{ + return input_joypad_set_rumble(g_joydriver, port, effect, strength); +} + + const input_driver_t input_apple = { apple_input_init, apple_input_poll, @@ -313,4 +320,7 @@ const input_driver_t input_apple = { apple_input_free_input, apple_input_set_keybinds, "apple_input", + NULL, + apple_input_set_rumble, + NULL }; diff --git a/apple/common/apple_input.h b/apple/common/apple_input.h index 0c739484a8..67c4525617 100644 --- a/apple/common/apple_input.h +++ b/apple/common/apple_input.h @@ -49,6 +49,7 @@ struct apple_pad_interface void* (*connect)(struct apple_pad_connection* connection, uint32_t slot); 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, uint16_t strength); }; @@ -61,8 +62,8 @@ void apple_joypad_packet(uint32_t slot, uint8_t* data, uint32_t length); void apple_joypad_send_hid_control(struct apple_pad_connection* connection, uint8_t* data, size_t size); // Input data for the main thread and the game thread -extern apple_input_data_t g_current_input_data; //< Main thread data -extern apple_input_data_t g_polled_input_data; //< Game thread data +extern apple_input_data_t g_current_input_data; +extern apple_input_data_t g_polled_input_data; // Main thread only void apple_input_enable_icade(bool on); diff --git a/apple/common/apple_joypad.c b/apple/common/apple_joypad.c index 64d9d286ae..b025ad416f 100644 --- a/apple/common/apple_joypad.c +++ b/apple/common/apple_joypad.c @@ -108,6 +108,14 @@ static bool apple_joypad_query_pad(unsigned pad) static void apple_joypad_destroy(void) { + for (int i = 0; i != MAX_PLAYERS; i ++) + { + if (slots[i].used && slots[i].iface) + { + slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0); + slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0); + } + } } static bool apple_joypad_button(unsigned port, uint16_t joykey) @@ -146,6 +154,18 @@ static void apple_joypad_poll(void) { } +static bool apple_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) +{ + if (pad < MAX_PLAYERS && slots[pad].used && slots[pad].iface) + { + slots[pad].iface->set_rumble(slots[pad].data, effect, strength); + return true; + } + + return false; +} + + static const char *apple_joypad_name(unsigned joypad) { (void)joypad; @@ -159,7 +179,7 @@ const rarch_joypad_driver_t apple_joypad = { apple_joypad_button, apple_joypad_axis, apple_joypad_poll, - NULL, + apple_joypad_rumble, apple_joypad_name, "apple" }; diff --git a/apple/common/hidpad/apple_ps3_pad.c b/apple/common/hidpad/apple_ps3_pad.c index 1da630a861..84a2e9a32f 100644 --- a/apple/common/hidpad/apple_ps3_pad.c +++ b/apple/common/hidpad/apple_ps3_pad.c @@ -28,6 +28,8 @@ struct hidpad_ps3_data uint32_t slot; bool have_led; + + uint16_t motors[2]; }; static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) @@ -35,7 +37,7 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) // TODO: Can this be modified to turn off motion tracking? static uint8_t report_buffer[] = { 0x52, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x27, 0x10, 0x00, 0x32, 0xff, 0x27, 0x10, 0x00, 0x32, @@ -47,6 +49,8 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) }; report_buffer[11] = 1 << ((device->slot % 4) + 1); + report_buffer[4] = device->motors[1] >> 8; + report_buffer[6] = device->motors[0] >> 8; apple_pad_send_control(device->connection, report_buffer, sizeof(report_buffer)); } @@ -122,9 +126,21 @@ static void hidpad_ps3_packet_handler(struct hidpad_ps3_data* device, uint8_t *p g_current_input_data.pad_axis[device->slot][i] = hidpad_ps3_get_axis(device, i); } +static void hidpad_ps3_set_rumble(struct hidpad_ps3_data* device, enum retro_rumble_effect effect, uint16_t strength) +{ + unsigned index = (effect == RETRO_RUMBLE_STRONG) ? 0 : 1; + + if (device->motors[index] != strength) + { + device->motors[index] = strength; + hidpad_ps3_send_control(device); + } +} + struct apple_pad_interface apple_pad_ps3 = { (void*)&hidpad_ps3_connect, (void*)&hidpad_ps3_disconnect, - (void*)&hidpad_ps3_packet_handler + (void*)&hidpad_ps3_packet_handler, + (void*)&hidpad_ps3_set_rumble }; diff --git a/apple/common/hidpad/apple_wii_pad.c b/apple/common/hidpad/apple_wii_pad.c index 5215db83ad..78aebc968c 100644 --- a/apple/common/hidpad/apple_wii_pad.c +++ b/apple/common/hidpad/apple_wii_pad.c @@ -98,9 +98,15 @@ static void hidpad_wii_packet_handler(struct wiimote_t* device, uint8_t *packet, g_current_input_data.pad_axis[device->unid][i] = hidpad_wii_get_axis(device, i); } +static void hidpad_wii_set_rumble(struct wiimote_t* device, enum retro_rumble_effect effect, uint16_t strength) +{ + // TODO +} + struct apple_pad_interface apple_pad_wii = { (void*)&hidpad_wii_connect, (void*)&hidpad_wii_disconnect, - (void*)&hidpad_wii_packet_handler + (void*)&hidpad_wii_packet_handler, + (void*)&hidpad_wii_set_rumble };