mirror of
https://github.com/libretro/RetroArch
synced 2025-04-02 07:20:34 +00:00
Make sure to get initial state of joypad.
This commit is contained in:
parent
be7a4b4c09
commit
65fa84d3b7
@ -32,6 +32,40 @@ struct linuxraw_joypad
|
|||||||
|
|
||||||
static struct linuxraw_joypad g_pads[MAX_PLAYERS];
|
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)
|
static bool linuxraw_joypad_init(void)
|
||||||
{
|
{
|
||||||
bool has_pad = false;
|
bool has_pad = false;
|
||||||
@ -47,6 +81,10 @@ static bool linuxraw_joypad_init(void)
|
|||||||
has_pad |= pad->fd >= 0;
|
has_pad |= pad->fd >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get initial state.
|
||||||
|
if (has_pad)
|
||||||
|
linuxraw_joypad_poll();
|
||||||
|
|
||||||
return has_pad;
|
return has_pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,40 +133,6 @@ static int16_t linuxraw_joypad_axis(unsigned port, uint32_t joyaxis)
|
|||||||
return val;
|
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 = {
|
const rarch_joypad_driver_t linuxraw_joypad = {
|
||||||
linuxraw_joypad_init,
|
linuxraw_joypad_init,
|
||||||
linuxraw_joypad_destroy,
|
linuxraw_joypad_destroy,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user