(PS4/joypad_connection) PS4 joypad is starting to work

This commit is contained in:
Twinaphex 2015-03-31 21:18:21 +02:00
parent 047fdbd3fc
commit ebd85ea02b
2 changed files with 43 additions and 54 deletions

View File

@ -26,6 +26,7 @@ struct hidpad_ps4_data
struct pad_connection* connection;
send_control_t send_control;
uint8_t data[512];
uint64_t buttonstate;
uint32_t slot;
bool have_led;
uint16_t motors[2];
@ -64,8 +65,8 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
return NULL;
}
device->connection = connection;
device->slot = slot;
device->connection = connection;
device->slot = slot;
device->send_control = ptr;
#if 0
@ -92,42 +93,11 @@ static void hidpad_ps4_deinit(void *data)
static uint64_t hidpad_ps4_get_buttons(void *data)
{
uint64_t result = 0;
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
struct Report
{
uint8_t leftX;
uint8_t leftY;
uint8_t rightX;
uint8_t rightY;
uint8_t buttons[3];
uint8_t leftTrigger;
uint8_t rightTrigger;
};
struct Report* rpt = (struct Report*)&device->data[4];
const uint8_t dpad_state = rpt->buttons[0] & 0xF;
result |= ((rpt->buttons[0] & 0x20) ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0);
result |= ((rpt->buttons[0] & 0x40) ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0);
result |= ((rpt->buttons[0] & 0x10) ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0);
result |= ((rpt->buttons[0] & 0x80) ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0);
result |= ((rpt->buttons[1] & 0x01) ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0);
result |= ((rpt->buttons[1] & 0x02) ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0);
result |= ((rpt->buttons[1] & 0x04) ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0);
result |= ((rpt->buttons[1] & 0x08) ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0);
result |= ((rpt->buttons[1] & 0x10) ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0);
result |= ((rpt->buttons[1] & 0x20) ? (1 << RETRO_DEVICE_ID_JOYPAD_START) : 0);
result |= ((rpt->buttons[1] & 0x40) ? (1 << RETRO_DEVICE_ID_JOYPAD_L3) : 0);
result |= ((rpt->buttons[1] & 0x80) ? (1 << RETRO_DEVICE_ID_JOYPAD_R3) : 0);
result |= ((dpad_state & 0x00) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0);
result |= ((dpad_state & 0x02) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0);
result |= ((dpad_state & 0x04) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0);
result |= ((dpad_state & 0x06) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0);
result |= ((rpt->buttons[2] & 0x01) ? (1 << 16) : 0);
return result;
if (!device)
return 0;
return device->buttonstate;
}
static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)
@ -146,14 +116,12 @@ static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)
static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size)
{
uint32_t i;
uint32_t buttons, buttons2, buttons3;
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
if (!device)
return;
(void)i;
#if 0
if (!device->have_led)
{
@ -161,19 +129,40 @@ static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size
device->have_led = true;
}
#endif
struct Report
{
uint8_t leftX;
uint8_t leftY;
uint8_t rightX;
uint8_t rightY;
uint8_t buttons[3];
uint8_t leftTrigger;
uint8_t rightTrigger;
};
uint8_t *rpt_ptr = (uint8_t*)&packet[4];
device->buttonstate = 0;
struct Report *rpt = (struct Report*)&packet[4];
(void)rpt;
buttons = rpt_ptr[2];
buttons2 = rpt_ptr[3];
buttons3 = rpt_ptr[4];
//RARCH_LOG("L2 button: %d\n", rpt_ptr[5]);
//RARCH_LOG("R2 button: %d\n", rpt_ptr[6]);
//RARCH_LOG("Test: %d\n", rpt_ptr[4] & 0x01);
//RARCH_LOG("Left stick X: %d\n", rpt_ptr[-2]);
//RARCH_LOG("Left stick Y: %d\n", rpt_ptr[-1]);
//RARCH_LOG("Right stick X: %d\n", rpt_ptr[0]);
//RARCH_LOG("Right stick Y: %d\n", rpt_ptr[1]);
//RARCH_LOG("Digital buttons: %d\n", rpt_ptr[2]);
//RARCH_LOG("Start/share: %d\n", rpt_ptr[3]);
device->buttonstate |= ((buttons2 == 128)? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0);
device->buttonstate |= ((buttons2 == 64) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0);
device->buttonstate |= ((buttons2 == 32) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0);
device->buttonstate |= ((buttons2 == 16) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0);
device->buttonstate |= ((buttons2 == 8) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0);
device->buttonstate |= ((buttons2 == 4) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0);
device->buttonstate |= ((buttons2 == 2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0);
device->buttonstate |= ((buttons2 == 1) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0);
device->buttonstate |= ((buttons == 136) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0);
device->buttonstate |= ((buttons == 72) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0);
device->buttonstate |= ((buttons == 40) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0);
device->buttonstate |= ((buttons == 24) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0);
device->buttonstate |= ((buttons == 6) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0);
device->buttonstate |= ((buttons == 4) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0);
device->buttonstate |= ((buttons == 2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0);
device->buttonstate |= ((buttons == 0) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0);
device->buttonstate |= ((buttons3 & 0x01)? (1ULL << RARCH_MENU_TOGGLE) : 0);
}
static void hidpad_ps4_set_rumble(void *data,

View File

@ -73,9 +73,9 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
{
{ "Nintendo RVL-CNT-01", &pad_connection_wii },
#if 0
{ "Nintendo RVL-CNT-01-UC", &pad_connection_wii_u },
{ "Wireless Controller", &pad_connection_ps4 },
{ "Nintendo RVL-CNT-01-UC", &pad_connection_wii_u },
#endif
{ "Wireless Controller", &pad_connection_ps4 },
{ "PLAYSTATION(R)3 Controller", &pad_connection_ps3 },
{ 0, 0}
};