From 569de131a05eb443178132d927aca1058d14ce6b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 17 Apr 2014 20:47:11 +0200 Subject: [PATCH] Move device enums outside of driver.h - and create new callback for 'getting' the number of 'devices' the input driver supports --- android/native/jni/input_android.c | 6 ++ android/native/jni/input_autodetect.h | 66 ++++++++++++++++++ apple/common/apple_input.c | 19 +++++- blackberry-qnx/qnx_input.c | 17 +++++ driver.h | 96 +-------------------------- frontend/menu/menu_settings.c | 15 +++-- gx/gx_input.c | 18 +++++ input/dinput.c | 1 + input/linuxraw_input.c | 1 + input/rwebinput_input.c | 1 + input/sdl_input.c | 1 + input/udev_input.c | 1 + input/x11_input.c | 1 + ps3/ps3_input.c | 12 ++++ psp/psp_input.c | 12 ++++ xdk/xdk_xinput_input.c | 17 ++++- 16 files changed, 178 insertions(+), 106 deletions(-) diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index 7a60bb1597..9e68a616ee 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -2110,6 +2110,11 @@ static float android_input_get_sensor_input(void *data, unsigned port, unsigned return 0; } +unsigned android_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_android = { android_input_init, android_input_poll, @@ -2120,5 +2125,6 @@ const input_driver_t input_android = { android_input_set_sensor_state, android_input_get_sensor_input, android_input_get_capabilities, + android_input_devices_size, "android_input", }; diff --git a/android/native/jni/input_autodetect.h b/android/native/jni/input_autodetect.h index b2c777aced..e5113487ec 100644 --- a/android/native/jni/input_autodetect.h +++ b/android/native/jni/input_autodetect.h @@ -96,6 +96,72 @@ enum { AKEYCODE_ASSIST = 219, }; +enum input_devices +{ + DEVICE_NONE = 0, + DEVICE_LOGITECH_RUMBLEPAD2, + DEVICE_LOGITECH_DUAL_ACTION, + DEVICE_LOGITECH_PRECISION_GAMEPAD, + DEVICE_ICONTROLPAD_HID_JOYSTICK, + DEVICE_ICONTROLPAD_BLUEZ_IME, + DEVICE_TTT_THT_ARCADE, + DEVICE_TOMMO_NEOGEOX_ARCADE, + DEVICE_MADCATZ_PC_USB_STICK, + DEVICE_LOGICOOL_RUMBLEPAD2, + DEVICE_IDROID_X360, + DEVICE_ZEEMOTE_STEELSERIES, + DEVICE_HUIJIA_USB_SNES, + DEVICE_SUPER_SMARTJOY, + DEVICE_SAITEK_RUMBLE_P480, + DEVICE_MS_SIDEWINDER_DUAL_STRIKE, + DEVICE_MS_SIDEWINDER, + DEVICE_MS_XBOX, + DEVICE_WISEGROUP_PLAYSTATION2, + DEVICE_JCPS102_PLAYSTATION2, + DEVICE_GENERIC_PLAYSTATION2_CONVERTER, + DEVICE_PSMOVE_NAVI, + DEVICE_JXD_S7300B, + DEVICE_JXD_S7800B, + DEVICE_IDROID_CON, + DEVICE_GENIUS_MAXFIRE_G08XU, + DEVICE_USB_2_AXIS_8_BUTTON_GAMEPAD, + DEVICE_BUFFALO_BGC_FC801, + DEVICE_RETROUSB_RETROPAD, + DEVICE_RETROUSB_SNES_RETROPORT, + DEVICE_CYPRESS_USB, + DEVICE_MAYFLASH_WII_CLASSIC, + DEVICE_SZMY_POWER_DUAL_BOX_WII, + DEVICE_ARCHOS_GAMEPAD, + DEVICE_JXD_S5110, + DEVICE_JXD_S5110_SKELROM, + DEVICE_XPERIA_PLAY, + DEVICE_BROADCOM_BLUETOOTH_HID, + DEVICE_THRUST_PREDATOR, + DEVICE_DRAGONRISE, + DEVICE_PLAYSTATION3_VERSION1, + DEVICE_PLAYSTATION3_VERSION2, + DEVICE_MOGA_IME, + DEVICE_NYKO_PLAYPAD_PRO, + DEVICE_TOODLES_2008_CHIMP, + DEVICE_MOGA, + DEVICE_SEGA_VIRTUA_STICK_HIGH_GRADE, + DEVICE_CCPCREATIONS_WIIUSE_IME, + DEVICE_KEYBOARD_RETROPAD, + DEVICE_OUYA, + DEVICE_ONLIVE_WIRELESS_CONTROLLER, + DEVICE_TOMEE_NES_USB, + DEVICE_THRUSTMASTER_T_MINI, + DEVICE_GAMEMID, + DEVICE_DEFENDER_GAME_RACER_CLASSIC, + DEVICE_HOLTEK_JC_U912F, + DEVICE_NVIDIA_SHIELD, + DEVICE_MUCH_IREADGO_I5, + DEVICE_WIKIPAD, + DEVICE_FC30_GAMEPAD, + DEVICE_SAMSUNG_GAMEPAD_EIGP20, + DEVICE_LAST +}; + #define LAST_KEYCODE AKEYCODE_ASSIST void input_autodetect_setup(void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source, bool *primary); diff --git a/apple/common/apple_input.c b/apple/common/apple_input.c index c2bea7ad02..5abce10e4a 100644 --- a/apple/common/apple_input.c +++ b/apple/common/apple_input.c @@ -24,6 +24,16 @@ #include "keycode.inc" +enum input_devices +{ + DEVICE_NONE = 0, +#if defined(IOS) + DEVICE_WIIMOTE, + DEVICE_SIXAXIS, +#endif + DEVICE_LAST +}; + extern const rarch_joypad_driver_t apple_joypad; static const rarch_joypad_driver_t* const g_joydriver = &apple_joypad; @@ -432,9 +442,14 @@ static uint64_t apple_input_get_capabilities(void *data) return caps; } +unsigned apple_get_device_last_idx(void *data) +{ + return DEVICE_LAST; +} + const rarch_joypad_driver_t *apple_get_joypad_driver(void *data) { - return g_joydriver; + return g_joydriver; } const input_driver_t input_apple = { @@ -447,6 +462,8 @@ const input_driver_t input_apple = { NULL, NULL, apple_input_get_capabilities, + NULL, + apple_get_device_last_idx, "apple_input", NULL, apple_input_set_rumble, diff --git a/blackberry-qnx/qnx_input.c b/blackberry-qnx/qnx_input.c index 4963d3fd92..b6709a1d23 100644 --- a/blackberry-qnx/qnx_input.c +++ b/blackberry-qnx/qnx_input.c @@ -30,6 +30,17 @@ #define MAX_TOUCH 4 #endif +enum input_devices +{ + DEVICE_NONE, + DEVICE_WIIMOTE, + DEVICE_KEYBOARD, + DEVICE_IPEGA, + DEVICE_KEYPAD, + DEVICE_UNKNOWN, + DEVICE_LAST +}; + struct touches { int16_t x, y; @@ -854,6 +865,11 @@ static uint64_t qnx_input_get_capabilities(void *data) return caps; } +unsigned qnx_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_qnx = { qnx_input_init, qnx_input_poll, @@ -864,5 +880,6 @@ const input_driver_t input_qnx = { NULL, NULL, qnx_input_get_capabilities, + qnx_input_devices_size, "qnx_input", }; diff --git a/driver.h b/driver.h index fbacfe45a7..09574439a2 100644 --- a/driver.h +++ b/driver.h @@ -232,101 +232,6 @@ typedef struct audio_driver #define GET_HAT_DIR(x) (x & HAT_MASK) #define GET_HAT(x) (x & (~HAT_MASK)) -enum input_devices -{ -#if defined(ANDROID) - DEVICE_NONE = 0, - DEVICE_LOGITECH_RUMBLEPAD2, - DEVICE_LOGITECH_DUAL_ACTION, - DEVICE_LOGITECH_PRECISION_GAMEPAD, - DEVICE_ICONTROLPAD_HID_JOYSTICK, - DEVICE_ICONTROLPAD_BLUEZ_IME, - DEVICE_TTT_THT_ARCADE, - DEVICE_TOMMO_NEOGEOX_ARCADE, - DEVICE_MADCATZ_PC_USB_STICK, - DEVICE_LOGICOOL_RUMBLEPAD2, - DEVICE_IDROID_X360, - DEVICE_ZEEMOTE_STEELSERIES, - DEVICE_HUIJIA_USB_SNES, - DEVICE_SUPER_SMARTJOY, - DEVICE_SAITEK_RUMBLE_P480, - DEVICE_MS_SIDEWINDER_DUAL_STRIKE, - DEVICE_MS_SIDEWINDER, - DEVICE_MS_XBOX, - DEVICE_WISEGROUP_PLAYSTATION2, - DEVICE_JCPS102_PLAYSTATION2, - DEVICE_GENERIC_PLAYSTATION2_CONVERTER, - DEVICE_PSMOVE_NAVI, - DEVICE_JXD_S7300B, - DEVICE_JXD_S7800B, - DEVICE_IDROID_CON, - DEVICE_GENIUS_MAXFIRE_G08XU, - DEVICE_USB_2_AXIS_8_BUTTON_GAMEPAD, - DEVICE_BUFFALO_BGC_FC801, - DEVICE_RETROUSB_RETROPAD, - DEVICE_RETROUSB_SNES_RETROPORT, - DEVICE_CYPRESS_USB, - DEVICE_MAYFLASH_WII_CLASSIC, - DEVICE_SZMY_POWER_DUAL_BOX_WII, - DEVICE_ARCHOS_GAMEPAD, - DEVICE_JXD_S5110, - DEVICE_JXD_S5110_SKELROM, - DEVICE_XPERIA_PLAY, - DEVICE_BROADCOM_BLUETOOTH_HID, - DEVICE_THRUST_PREDATOR, - DEVICE_DRAGONRISE, - DEVICE_PLAYSTATION3_VERSION1, - DEVICE_PLAYSTATION3_VERSION2, - DEVICE_MOGA_IME, - DEVICE_NYKO_PLAYPAD_PRO, - DEVICE_TOODLES_2008_CHIMP, - DEVICE_MOGA, - DEVICE_SEGA_VIRTUA_STICK_HIGH_GRADE, - DEVICE_CCPCREATIONS_WIIUSE_IME, - DEVICE_KEYBOARD_RETROPAD, - DEVICE_OUYA, - DEVICE_ONLIVE_WIRELESS_CONTROLLER, - DEVICE_TOMEE_NES_USB, - DEVICE_THRUSTMASTER_T_MINI, - DEVICE_GAMEMID, - DEVICE_DEFENDER_GAME_RACER_CLASSIC, - DEVICE_HOLTEK_JC_U912F, - DEVICE_NVIDIA_SHIELD, - DEVICE_MUCH_IREADGO_I5, - DEVICE_WIKIPAD, - DEVICE_FC30_GAMEPAD, - DEVICE_SAMSUNG_GAMEPAD_EIGP20, -#elif defined(GEKKO) - DEVICE_GAMECUBE = 0, -#ifdef HW_RVL - DEVICE_WIIMOTE, - DEVICE_NUNCHUK, - DEVICE_CLASSIC, -#ifdef HAVE_LIBSICKSAXIS - DEVICE_SIXAXIS, -#endif -#endif -#elif defined(_XBOX) - DEVICE_XBOX_PAD = 0, -#elif defined(__CELLOS_LV2__) - DEVICE_SIXAXIS = 0, -#elif defined(PSP) - DEVICE_PSP = 0, -#elif defined(__BLACKBERRY_QNX__) - DEVICE_NONE, - DEVICE_WIIMOTE, - DEVICE_KEYBOARD, - DEVICE_IPEGA, - DEVICE_KEYPAD, - DEVICE_UNKNOWN, -#elif defined(IOS) - DEVICE_NONE, - DEVICE_WIIMOTE, - DEVICE_SIXAXIS, -#endif - DEVICE_LAST -}; - enum analog_dpad_mode { ANALOG_DPAD_NONE = 0, @@ -362,6 +267,7 @@ typedef struct input_driver bool (*set_sensor_state)(void *data, unsigned port, enum retro_sensor_action action, unsigned rate); float (*get_sensor_input)(void *data, unsigned port, unsigned id); uint64_t (*get_capabilities)(void *data); + unsigned (*devices_size)(void *data); const char *ident; void (*grab_mouse)(void *data, bool state); diff --git a/frontend/menu/menu_settings.c b/frontend/menu/menu_settings.c index 7e29412e1d..4c36f6e076 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -900,9 +900,10 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) case RGUI_SETTINGS_BIND_DEVICE: // If set_keybinds is supported, we do it more fancy, and scroll through // a list of supported devices directly. - if (driver.input->set_keybinds) + if (driver.input->set_keybinds && driver.input->devices_size) { - g_settings.input.device[port] += DEVICE_LAST; + unsigned device_last = driver.input->devices_size(driver.input_data); + g_settings.input.device[port] += device_last; if (action == RGUI_ACTION_START) g_settings.input.device[port] = 0; else if (action == RGUI_ACTION_LEFT) @@ -910,12 +911,12 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) else if (action == RGUI_ACTION_RIGHT) g_settings.input.device[port]++; - // DEVICE_LAST can be 0, avoid modulo. - if (g_settings.input.device[port] >= DEVICE_LAST) - g_settings.input.device[port] -= DEVICE_LAST; + // device_last can be 0, avoid modulo. + if (g_settings.input.device[port] >= device_last) + g_settings.input.device[port] -= device_last; // needs to be checked twice, in case we go right past the end of the list - if (g_settings.input.device[port] >= DEVICE_LAST) - g_settings.input.device[port] -= DEVICE_LAST; + if (g_settings.input.device[port] >= device_last) + g_settings.input.device[port] -= device_last; unsigned keybind_action = (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS); diff --git a/gx/gx_input.c b/gx/gx_input.c index c80abca173..008e2243d1 100644 --- a/gx/gx_input.c +++ b/gx/gx_input.c @@ -38,6 +38,18 @@ #define MAX_PADS 4 +enum input_devices +{ + DEVICE_GAMECUBE = 0, +#ifdef HW_RVL + DEVICE_WIIMOTE, + DEVICE_NUNCHUK, + DEVICE_CLASSIC, +#ifdef HAVE_LIBSICKSAXIS + DEVICE_SIXAXIS, +#endif + DEVICE_LAST +}; typedef struct gx_input { @@ -880,6 +892,11 @@ static const rarch_joypad_driver_t *gx_input_get_joypad_driver(void *data) return &gx_joypad; } +static unsigned gx_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_gx = { gx_input_init, gx_input_poll, @@ -890,6 +907,7 @@ const input_driver_t input_gx = { NULL, NULL, gx_input_get_capabilities, + gx_input_devices_size, "gx", NULL, diff --git a/input/dinput.c b/input/dinput.c index a10b2e6736..4aa59ecb41 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -558,6 +558,7 @@ const input_driver_t input_dinput = { NULL, NULL, dinput_get_capabilities, + NULL, "dinput", dinput_grab_mouse, diff --git a/input/linuxraw_input.c b/input/linuxraw_input.c index 03eca75376..72c20e3ed7 100644 --- a/input/linuxraw_input.c +++ b/input/linuxraw_input.c @@ -243,6 +243,7 @@ const input_driver_t input_linuxraw = { NULL, NULL, linuxraw_get_capabilities, + NULL, "linuxraw", NULL, linuxraw_set_rumble, diff --git a/input/rwebinput_input.c b/input/rwebinput_input.c index 13e8e15319..ce50c9f29c 100644 --- a/input/rwebinput_input.c +++ b/input/rwebinput_input.c @@ -157,6 +157,7 @@ const input_driver_t input_rwebinput = { NULL, NULL, rwebinput_get_capabilities, + NULL, "rwebinput", rwebinput_grab_mouse, }; diff --git a/input/sdl_input.c b/input/sdl_input.c index 2fd68bcaa7..b0277c122f 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -283,6 +283,7 @@ const input_driver_t input_sdl = { NULL, NULL, sdl_get_capabilities, + NULL, "sdl", NULL, sdl_set_rumble, diff --git a/input/udev_input.c b/input/udev_input.c index ede6a21c3a..db8ff9bec0 100644 --- a/input/udev_input.c +++ b/input/udev_input.c @@ -816,6 +816,7 @@ const input_driver_t input_udev = { NULL, NULL, udev_input_get_capabilities, + NULL, "udev", udev_input_grab_mouse, udev_input_set_rumble, diff --git a/input/x11_input.c b/input/x11_input.c index d8dab4cbc5..14a3302051 100644 --- a/input/x11_input.c +++ b/input/x11_input.c @@ -320,6 +320,7 @@ const input_driver_t input_x = { NULL, NULL, x_input_get_capabilities, + NULL, "x", x_grab_mouse, x_set_rumble, diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index 92c4912b8e..9bb2b28053 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -39,6 +39,12 @@ #define DEADZONE_LOW 105 #define DEADZONE_HIGH 145 +enum input_devices +{ + DEVICE_SIXAXIS = 0, + DEVICE_LAST +}; + typedef struct { float x; @@ -511,6 +517,11 @@ static const rarch_joypad_driver_t *ps3_input_get_joypad_driver(void *data) return &ps3_joypad; } +static unsigned ps3_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_ps3 = { ps3_input_init, ps3_input_poll, @@ -521,6 +532,7 @@ const input_driver_t input_ps3 = { ps3_input_set_sensor_state, NULL, ps3_input_get_capabilities, + ps3_input_devices_size, "ps3", NULL, diff --git a/psp/psp_input.c b/psp/psp_input.c index b8828d11fd..70017a0656 100644 --- a/psp/psp_input.c +++ b/psp/psp_input.c @@ -37,6 +37,12 @@ #define MAX_PADS 1 +enum input_devices +{ + DEVICE_PSP = 0, + DEVICE_LAST +}; + const struct platform_bind platform_keys[] = { { PSP_GAMEPAD_CIRCLE, "Circle button" }, { PSP_GAMEPAD_CROSS, "Cross button" }, @@ -336,6 +342,11 @@ static const rarch_joypad_driver_t *psp_input_get_joypad_driver(void *data) return &psp_joypad; } +static unsigned psp_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_psp = { psp_input_initialize, psp_input_poll, @@ -346,6 +357,7 @@ const input_driver_t input_psp = { NULL, NULL, psp_input_get_capabilities, + psp_input_devices_size, "psp", NULL, diff --git a/xdk/xdk_xinput_input.c b/xdk/xdk_xinput_input.c index c005d46496..97534b60a6 100644 --- a/xdk/xdk_xinput_input.c +++ b/xdk/xdk_xinput_input.c @@ -21,13 +21,18 @@ #include #endif -#define MAX_PADS 4 -#define DEADZONE (16000) - #include "../driver.h" #include "../general.h" #include "../libretro.h" +#define MAX_PADS 4 + +enum input_devices +{ + DEVICE_XBOX_PAD = 0, + DEVICE_LAST +}; + typedef struct xdk_input { uint64_t pad_state[MAX_PADS]; @@ -432,6 +437,11 @@ static const rarch_joypad_driver_t *xdk_input_get_joypad_driver(void *data) return &xdk_joypad; } +static unsigned xdk_input_devices_size(void *data) +{ + return DEVICE_LAST; +} + const input_driver_t input_xinput = { xdk_input_init, @@ -443,6 +453,7 @@ const input_driver_t input_xinput = NULL, NULL, xdk_input_get_capabilities, + xdk_input_devices_size, "xinput", NULL,