From 65fa84d3b77bd55606dbfd00c0cc9eaa867b6d82 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 29 Sep 2012 09:57:28 +0200 Subject: [PATCH] Make sure to get initial state of joypad. --- input/linuxraw_joypad.c | 72 ++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/input/linuxraw_joypad.c b/input/linuxraw_joypad.c index 43624b3b18..292f6f704d 100644 --- a/input/linuxraw_joypad.c +++ b/input/linuxraw_joypad.c @@ -32,6 +32,40 @@ struct linuxraw_joypad static struct linuxraw_joypad g_pads[MAX_PLAYERS]; +static void poll_pad(struct linuxraw_joypad *pad) +{ + struct js_event event; + while (read(pad->fd, &event, sizeof(event)) == (ssize_t)sizeof(event)) + { + unsigned type = event.type & ~JS_EVENT_INIT; + + switch (type) + { + case JS_EVENT_BUTTON: + if (event.number < NUM_BUTTONS) + pad->buttons[event.number] = event.value; + break; + + case JS_EVENT_AXIS: + if (event.number < NUM_AXES) + pad->axes[event.number] = event.value; + break; + } + } +} + +static void linuxraw_joypad_poll(void) +{ + for (unsigned i = 0; i < MAX_PLAYERS; i++) + { + struct linuxraw_joypad *pad = &g_pads[i]; + if (pad->fd < 0) + continue; + + poll_pad(pad); + } +} + static bool linuxraw_joypad_init(void) { bool has_pad = false; @@ -47,6 +81,10 @@ static bool linuxraw_joypad_init(void) has_pad |= pad->fd >= 0; } + // Get initial state. + if (has_pad) + linuxraw_joypad_poll(); + return has_pad; } @@ -95,40 +133,6 @@ static int16_t linuxraw_joypad_axis(unsigned port, uint32_t joyaxis) return val; } -static void poll_pad(struct linuxraw_joypad *pad) -{ - struct js_event event; - while (read(pad->fd, &event, sizeof(event)) == (ssize_t)sizeof(event)) - { - unsigned type = event.type & ~JS_EVENT_INIT; - - switch (type) - { - case JS_EVENT_BUTTON: - if (event.number < NUM_BUTTONS) - pad->buttons[event.number] = event.value; - break; - - case JS_EVENT_AXIS: - if (event.number < NUM_AXES) - pad->axes[event.number] = event.value; - break; - } - } -} - -static void linuxraw_joypad_poll(void) -{ - for (unsigned i = 0; i < MAX_PLAYERS; i++) - { - struct linuxraw_joypad *pad = &g_pads[i]; - if (pad->fd < 0) - continue; - - poll_pad(pad); - } -} - const rarch_joypad_driver_t linuxraw_joypad = { linuxraw_joypad_init, linuxraw_joypad_destroy,