(Apple) Add rumble support for DualShock 3 controllers.

This commit is contained in:
meancoot 2013-10-03 18:04:28 -04:00
parent fae300aaaf
commit ad6aebb277
5 changed files with 59 additions and 6 deletions

View File

@ -242,6 +242,7 @@ static bool apple_bind_button_pressed(void *data, int key)
static void apple_input_free_input(void *data) static void apple_input_free_input(void *data)
{ {
(void)data; (void)data;
g_joydriver->destroy();
} }
static void apple_input_set_keybinds(void *data, unsigned device, unsigned port, 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 #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 = { const input_driver_t input_apple = {
apple_input_init, apple_input_init,
apple_input_poll, apple_input_poll,
@ -313,4 +320,7 @@ const input_driver_t input_apple = {
apple_input_free_input, apple_input_free_input,
apple_input_set_keybinds, apple_input_set_keybinds,
"apple_input", "apple_input",
NULL,
apple_input_set_rumble,
NULL
}; };

View File

@ -49,6 +49,7 @@ struct apple_pad_interface
void* (*connect)(struct apple_pad_connection* connection, uint32_t slot); void* (*connect)(struct apple_pad_connection* connection, uint32_t slot);
void (*disconnect)(void* device); void (*disconnect)(void* device);
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size); 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); 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 // 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_current_input_data;
extern apple_input_data_t g_polled_input_data; //< Game thread data extern apple_input_data_t g_polled_input_data;
// Main thread only // Main thread only
void apple_input_enable_icade(bool on); void apple_input_enable_icade(bool on);

View File

@ -108,6 +108,14 @@ static bool apple_joypad_query_pad(unsigned pad)
static void apple_joypad_destroy(void) 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) 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) static const char *apple_joypad_name(unsigned joypad)
{ {
(void)joypad; (void)joypad;
@ -159,7 +179,7 @@ const rarch_joypad_driver_t apple_joypad = {
apple_joypad_button, apple_joypad_button,
apple_joypad_axis, apple_joypad_axis,
apple_joypad_poll, apple_joypad_poll,
NULL, apple_joypad_rumble,
apple_joypad_name, apple_joypad_name,
"apple" "apple"
}; };

View File

@ -28,6 +28,8 @@ struct hidpad_ps3_data
uint32_t slot; uint32_t slot;
bool have_led; bool have_led;
uint16_t motors[2];
}; };
static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) 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? // TODO: Can this be modified to turn off motion tracking?
static uint8_t report_buffer[] = { static uint8_t report_buffer[] = {
0x52, 0x01, 0x52, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x27, 0x10, 0x00, 0x32, 0xff, 0x27, 0x10, 0x00, 0x32,
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[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)); 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); 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 = struct apple_pad_interface apple_pad_ps3 =
{ {
(void*)&hidpad_ps3_connect, (void*)&hidpad_ps3_connect,
(void*)&hidpad_ps3_disconnect, (void*)&hidpad_ps3_disconnect,
(void*)&hidpad_ps3_packet_handler (void*)&hidpad_ps3_packet_handler,
(void*)&hidpad_ps3_set_rumble
}; };

View File

@ -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); 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 = struct apple_pad_interface apple_pad_wii =
{ {
(void*)&hidpad_wii_connect, (void*)&hidpad_wii_connect,
(void*)&hidpad_wii_disconnect, (void*)&hidpad_wii_disconnect,
(void*)&hidpad_wii_packet_handler (void*)&hidpad_wii_packet_handler,
(void*)&hidpad_wii_set_rumble
}; };