mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
Implement button() for most HID drivers
== DETAILS The HID drivers in `input/connect/` were missing an implementation for button(), so I added it. The only exception is the wii driver, which is really complicated and more than I wanted to try to tackle-- especially since WIIU has its own wiimote drivers.
This commit is contained in:
parent
e02e345a28
commit
002c9a30c0
@ -139,6 +139,14 @@ const char * hidpad_nesusb_get_name(void *data)
|
||||
return "Generic NES USB Controller";
|
||||
}
|
||||
|
||||
static int32_t hidpad_nesusb_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_nesusb_data *pad = (struct hidpad_nesusb_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_nesusb = {
|
||||
hidpad_nesusb_init,
|
||||
hidpad_nesusb_deinit,
|
||||
@ -147,6 +155,6 @@ pad_connection_interface_t pad_connection_nesusb = {
|
||||
hidpad_nesusb_get_buttons,
|
||||
hidpad_nesusb_get_axis,
|
||||
hidpad_nesusb_get_name,
|
||||
NULL, /* button */
|
||||
hidpad_nesusb_button,
|
||||
false,
|
||||
};
|
||||
|
@ -174,6 +174,14 @@ const char * hidpad_ps2adapter_get_name(void *data)
|
||||
return "PS2/PSX Controller Adapter";
|
||||
}
|
||||
|
||||
static int32_t hidpad_ps2adapter_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_ps2adapter_data *pad = (struct hidpad_ps2adapter_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_ps2adapter = {
|
||||
hidpad_ps2adapter_init,
|
||||
hidpad_ps2adapter_deinit,
|
||||
@ -182,6 +190,6 @@ pad_connection_interface_t pad_connection_ps2adapter = {
|
||||
hidpad_ps2adapter_get_buttons,
|
||||
hidpad_ps2adapter_get_axis,
|
||||
hidpad_ps2adapter_get_name,
|
||||
NULL,
|
||||
hidpad_ps2adapter_button,
|
||||
false,
|
||||
};
|
||||
|
@ -285,6 +285,52 @@ static void hidpad_ps4_set_rumble(void *data,
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t hidpad_ps4_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
|
||||
struct ps4 *rpt = device ?
|
||||
(struct ps4*)&device->data : NULL;
|
||||
if (!device || !rpt || joykey > 31)
|
||||
return 0;
|
||||
|
||||
switch(joykey) {
|
||||
case RETRO_DEVICE_ID_JOYPAD_R3:
|
||||
return rpt->btn.r3;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L3:
|
||||
return rpt->btn.l3;
|
||||
case RETRO_DEVICE_ID_JOYPAD_START:
|
||||
return rpt->btn.options;
|
||||
case RETRO_DEVICE_ID_JOYPAD_SELECT:
|
||||
return rpt->btn.share;
|
||||
case RETRO_DEVICE_ID_JOYPAD_R2:
|
||||
return rpt->btn.r2;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L2:
|
||||
return rpt->btn.l2;
|
||||
case RETRO_DEVICE_ID_JOYPAD_R:
|
||||
return rpt->btn.r1;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L:
|
||||
return rpt->btn.l1;
|
||||
case RETRO_DEVICE_ID_JOYPAD_X:
|
||||
return rpt->btn.triangle;
|
||||
case RETRO_DEVICE_ID_JOYPAD_A:
|
||||
return rpt->btn.circle;
|
||||
case RETRO_DEVICE_ID_JOYPAD_B:
|
||||
return rpt->btn.cross;
|
||||
case RETRO_DEVICE_ID_JOYPAD_Y:
|
||||
return rpt->btn.square;
|
||||
case RETRO_DEVICE_ID_JOYPAD_LEFT:
|
||||
case RETRO_DEVICE_ID_JOYPAD_RIGHT:
|
||||
case RETRO_DEVICE_ID_JOYPAD_DOWN:
|
||||
case RETRO_DEVICE_ID_JOYPAD_UP:
|
||||
return hidpad_ps4_check_dpad(rpt, joykey);
|
||||
case RARCH_MENU_TOGGLE:
|
||||
return rpt->btn.ps;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pad_connection_interface_t pad_connection_ps4 = {
|
||||
hidpad_ps4_init,
|
||||
hidpad_ps4_deinit,
|
||||
@ -293,6 +339,6 @@ pad_connection_interface_t pad_connection_ps4 = {
|
||||
hidpad_ps4_get_buttons,
|
||||
hidpad_ps4_get_axis,
|
||||
NULL, /* get_name */
|
||||
NULL, /* button */
|
||||
hidpad_ps4_button,
|
||||
false
|
||||
};
|
||||
|
@ -178,6 +178,14 @@ const char * hidpad_ps4_hori_mini_get_name(void *data)
|
||||
return "HORI mini wired PS4";
|
||||
}
|
||||
|
||||
static int32_t hidpad_ps4_hori_mini_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_ps4_hori_mini_data *pad = (struct hidpad_ps4_hori_mini_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_ps4_hori_mini = {
|
||||
hidpad_ps4_hori_mini_init,
|
||||
hidpad_ps4_hori_mini_deinit,
|
||||
@ -186,6 +194,6 @@ pad_connection_interface_t pad_connection_ps4_hori_mini = {
|
||||
hidpad_ps4_hori_mini_get_buttons,
|
||||
hidpad_ps4_hori_mini_get_axis,
|
||||
hidpad_ps4_hori_mini_get_name,
|
||||
NULL, /* button */
|
||||
hidpad_ps4_hori_mini_button, /* button */
|
||||
false
|
||||
};
|
||||
|
@ -183,6 +183,14 @@ const char * hidpad_psxadapter_get_name(void *data)
|
||||
return "PSX to PS3 Controller Adapter";
|
||||
}
|
||||
|
||||
static int32_t hidpad_psxadapter_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_psxadapter_data *pad = (struct hidpad_psxadapter_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_psxadapter = {
|
||||
hidpad_psxadapter_init,
|
||||
hidpad_psxadapter_deinit,
|
||||
@ -191,6 +199,6 @@ pad_connection_interface_t pad_connection_psxadapter = {
|
||||
hidpad_psxadapter_get_buttons,
|
||||
hidpad_psxadapter_get_axis,
|
||||
hidpad_psxadapter_get_name,
|
||||
NULL, /* button */
|
||||
hidpad_psxadapter_button,
|
||||
false
|
||||
};
|
||||
|
@ -189,6 +189,14 @@ const char * hidpad_retrode_get_name(void *data)
|
||||
return "Retrode";
|
||||
}
|
||||
|
||||
static int32_t hidpad_retrode_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_retrode_data *pad = (struct hidpad_retrode_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_retrode = {
|
||||
hidpad_retrode_init,
|
||||
hidpad_retrode_deinit,
|
||||
@ -197,6 +205,6 @@ pad_connection_interface_t pad_connection_retrode = {
|
||||
hidpad_retrode_get_buttons,
|
||||
hidpad_retrode_get_axis,
|
||||
hidpad_retrode_get_name,
|
||||
NULL, /* button */
|
||||
hidpad_retrode_button,
|
||||
false,
|
||||
};
|
||||
|
@ -140,6 +140,14 @@ const char * hidpad_snesusb_get_name(void *data)
|
||||
return "Generic SNES USB Controller";
|
||||
}
|
||||
|
||||
static int32_t hidpad_snesusb_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_snesusb_data *pad = (struct hidpad_snesusb_data*)data;
|
||||
if (!pad || joykey > 31)
|
||||
return 0;
|
||||
return pad->buttons & (1 << joykey);
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_snesusb = {
|
||||
hidpad_snesusb_init,
|
||||
hidpad_snesusb_deinit,
|
||||
@ -148,6 +156,6 @@ pad_connection_interface_t pad_connection_snesusb = {
|
||||
hidpad_snesusb_get_buttons,
|
||||
hidpad_snesusb_get_axis,
|
||||
hidpad_snesusb_get_name,
|
||||
NULL, /* button */
|
||||
hidpad_snesusb_button,
|
||||
false
|
||||
};
|
||||
|
@ -722,6 +722,8 @@ static void hidpad_wii_set_rumble(void *data,
|
||||
(void)strength;
|
||||
}
|
||||
|
||||
/* TODO: implement hidpad_wii_button(). */
|
||||
|
||||
pad_connection_interface_t pad_connection_wii = {
|
||||
hidpad_wii_init,
|
||||
hidpad_wii_deinit,
|
||||
|
@ -248,6 +248,56 @@ static void hidpad_wiiupro_set_rumble(void *data,
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
static int32_t hidpad_wiiupro_button(void *data, uint16_t joykey)
|
||||
{
|
||||
struct hidpad_wiiupro_data *device = (struct hidpad_wiiupro_data*)data;
|
||||
struct wiiupro *rpt = device ?
|
||||
(struct wiiupro*)&device->data : NULL;
|
||||
|
||||
if (!device || !rpt)
|
||||
return 0;
|
||||
|
||||
switch(joykey) {
|
||||
case RETRO_DEVICE_ID_JOYPAD_R3:
|
||||
return rpt->btn.r3;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L3:
|
||||
return rpt->btn.l3;
|
||||
case RETRO_DEVICE_ID_JOYPAD_START:
|
||||
return rpt->btn.plus;
|
||||
case RETRO_DEVICE_ID_JOYPAD_SELECT:
|
||||
return rpt->btn.minus;
|
||||
case RETRO_DEVICE_ID_JOYPAD_R2:
|
||||
return rpt->btn.zr;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L2:
|
||||
return rpt->btn.zl;
|
||||
case RETRO_DEVICE_ID_JOYPAD_R:
|
||||
return rpt->btn.r;
|
||||
case RETRO_DEVICE_ID_JOYPAD_L:
|
||||
return rpt->btn.l;
|
||||
case RETRO_DEVICE_ID_JOYPAD_X:
|
||||
return rpt->btn.x;
|
||||
case RETRO_DEVICE_ID_JOYPAD_A:
|
||||
return rpt->btn.a;
|
||||
case RETRO_DEVICE_ID_JOYPAD_B:
|
||||
return rpt->btn.b;
|
||||
case RETRO_DEVICE_ID_JOYPAD_Y:
|
||||
return rpt->btn.y;
|
||||
case RETRO_DEVICE_ID_JOYPAD_LEFT:
|
||||
return rpt->btn.left;
|
||||
case RETRO_DEVICE_ID_JOYPAD_RIGHT:
|
||||
return rpt->btn.right;
|
||||
case RETRO_DEVICE_ID_JOYPAD_DOWN:
|
||||
return rpt->btn.down;
|
||||
case RETRO_DEVICE_ID_JOYPAD_UP:
|
||||
return rpt->btn.up;
|
||||
case RARCH_MENU_TOGGLE:
|
||||
return rpt->btn.home;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pad_connection_interface_t pad_connection_wiiupro = {
|
||||
hidpad_wiiupro_init,
|
||||
hidpad_wiiupro_deinit,
|
||||
@ -256,6 +306,6 @@ pad_connection_interface_t pad_connection_wiiupro = {
|
||||
hidpad_wiiupro_get_buttons,
|
||||
hidpad_wiiupro_get_axis,
|
||||
NULL, /* get_name */
|
||||
NULL, /* button */
|
||||
hidpad_wiiupro_button,
|
||||
false
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user