From 8b1ac3bc9e7d0fad1c7799006626d088288ae797 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 25 Sep 2013 23:58:02 +0200 Subject: [PATCH] Add rumble tests to libretro-test. --- driver.c | 2 +- input/input_common.c | 2 +- input/udev_joypad.c | 13 ++++++++----- libretro-test/libretro-test.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/driver.c b/driver.c index d96275c7fd..254a782820 100644 --- a/driver.c +++ b/driver.c @@ -311,7 +311,7 @@ void driver_set_nonblock_state(bool nonblock) bool driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable) { - if (driver.input && driver.input_data) + if (driver.input && driver.input_data && driver.input->set_rumble) return driver.input->set_rumble(driver.input_data, port, effect, enable); else return false; diff --git a/input/input_common.c b/input/input_common.c index daa69be9cb..3ddf32e3fc 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -109,7 +109,7 @@ const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joyp bool input_joypad_set_rumble(const rarch_joypad_driver_t *driver, unsigned port, enum retro_rumble_effect effect, bool state) { - if (!driver) + if (!driver || !driver->set_rumble) return false; int joy_index = g_settings.input.joypad_map[port]; diff --git a/input/udev_joypad.c b/input/udev_joypad.c index 5295031e70..aea413d37c 100644 --- a/input/udev_joypad.c +++ b/input/udev_joypad.c @@ -177,8 +177,9 @@ end: udev_device_unref(dev); } -static bool udev_set_rumble(unsigned i, unsigned effect, bool state) +static bool udev_set_rumble(unsigned i, enum retro_rumble_effect effect, bool state) { + fprintf(stderr, "Rumble: Pad %u, Effect %u, State %u.\n", i, (unsigned)effect, (unsigned)state); struct udev_joypad *pad = &g_pads[i]; if (pad->fd < 0) @@ -264,13 +265,11 @@ static int find_vacant_pad(void) static void free_pad(unsigned pad) { if (g_pads[pad].fd >= 0) - { - udev_set_rumble(pad, 0, false); - udev_set_rumble(pad, 1, false); close(g_pads[pad].fd); - } free(g_pads[pad].path); + if (g_pads[pad].ident) + *g_pads[pad].ident = '\0'; memset(&g_pads[pad], 0, sizeof(g_pads[pad])); g_pads[pad].fd = -1; @@ -280,8 +279,12 @@ static void free_pad(unsigned pad) static bool add_pad(unsigned i, int fd, const char *path) { struct udev_joypad *pad = &g_pads[i]; + pad->ident = g_settings.input.device_names[i]; if (ioctl(fd, EVIOCGNAME(sizeof(g_settings.input.device_names[0])), pad->ident) < 0) + { + RARCH_LOG("[udev]: Failed to get pad name.\n"); return false; + } RARCH_LOG("[udev]: Plugged pad: %s on port #%u.\n", pad->ident, i); diff --git a/libretro-test/libretro-test.c b/libretro-test/libretro-test.c index abf5c6c2c5..791818bc2a 100644 --- a/libretro-test/libretro-test.c +++ b/libretro-test/libretro-test.c @@ -61,6 +61,8 @@ static retro_environment_t environ_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; +static struct retro_rumble_interface rumble; + void retro_set_environment(retro_environment_t cb) { environ_cb = cb; @@ -173,6 +175,30 @@ static void update_input(void) x_coord = (x_coord + dir_x) & 31; y_coord = (y_coord + dir_y) & 31; + + if (rumble.set_rumble_state) + { + static bool old_start; + static bool old_select; + bool start = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START); + bool select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT); + if (old_start != start) + { + fprintf(stderr, "Strong rumble: %s.\n", start ? "ON": "OFF"); + if (!rumble.set_rumble_state(0, RETRO_RUMBLE_STRONG, start)) + fprintf(stderr, "Strong rumble; failed to set state.\n"); + } + + if (old_select != select) + { + fprintf(stderr, "Weak rumble: %s.\n", select ? "ON": "OFF"); + if (!rumble.set_rumble_state(0, RETRO_RUMBLE_WEAK, select)) + fprintf(stderr, "Weak rumble; failed to set state.\n"); + } + + old_start = start; + old_select = select; + } } static void render_checkered(void) @@ -262,6 +288,10 @@ bool retro_load_game(const struct retro_game_info *info) struct retro_keyboard_callback cb = { keyboard_cb }; environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &cb); + if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) + fprintf(stderr, "Rumble environment supported.\n"); + else + fprintf(stderr, "Rumble environment not supported.\n"); check_variables();