(udev_joypad.c) Cleanups
This commit is contained in:
parent
96d39a78cc
commit
42a0618812
|
@ -335,28 +335,16 @@ static void udev_check_device(struct udev_device *dev, const char *path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pad = udev_find_vacant_pad();
|
if ((pad = udev_find_vacant_pad()) < 0)
|
||||||
if (pad < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fd = udev_open_joystick(path);
|
if ((fd = udev_open_joystick(path)) < 0)
|
||||||
if (fd < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ret = udev_add_pad(dev, pad, fd, path);
|
if (udev_add_pad(dev, pad, fd, path) == -1)
|
||||||
|
|
||||||
switch (ret)
|
|
||||||
{
|
{
|
||||||
case -1:
|
|
||||||
RARCH_ERR("[udev]: Failed to add pad: %s.\n", path);
|
RARCH_ERR("[udev]: Failed to add pad: %s.\n", path);
|
||||||
close(fd);
|
close(fd);
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
/* Pad was autoconfigured. */
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +400,6 @@ static void udev_joypad_destroy(void)
|
||||||
static bool udev_set_rumble(unsigned i,
|
static bool udev_set_rumble(unsigned i,
|
||||||
enum retro_rumble_effect effect, uint16_t strength)
|
enum retro_rumble_effect effect, uint16_t strength)
|
||||||
{
|
{
|
||||||
int old_effect;
|
|
||||||
uint16_t old_strength;
|
uint16_t old_strength;
|
||||||
struct udev_joypad *pad = (struct udev_joypad*)&udev_pads[i];
|
struct udev_joypad *pad = (struct udev_joypad*)&udev_pads[i];
|
||||||
|
|
||||||
|
@ -422,10 +409,9 @@ static bool udev_set_rumble(unsigned i,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
old_strength = pad->strength[effect];
|
old_strength = pad->strength[effect];
|
||||||
if (old_strength == strength)
|
if (old_strength != strength)
|
||||||
return true;
|
{
|
||||||
|
int old_effect = pad->has_set_ff[effect] ? pad->effects[effect] : -1;
|
||||||
old_effect = pad->has_set_ff[effect] ? pad->effects[effect] : -1;
|
|
||||||
|
|
||||||
if (strength && strength != pad->configured_strength[effect])
|
if (strength && strength != pad->configured_strength[effect])
|
||||||
{
|
{
|
||||||
|
@ -469,7 +455,7 @@ static bool udev_set_rumble(unsigned i,
|
||||||
/* It seems that we can update strength with EVIOCSFF atomically. */
|
/* It seems that we can update strength with EVIOCSFF atomically. */
|
||||||
if ((!!strength) != (!!old_strength))
|
if ((!!strength) != (!!old_strength))
|
||||||
{
|
{
|
||||||
struct input_event play = {{0}};
|
struct input_event play;
|
||||||
|
|
||||||
play.type = EV_FF;
|
play.type = EV_FF;
|
||||||
play.code = pad->effects[effect];
|
play.code = pad->effects[effect];
|
||||||
|
@ -482,6 +468,7 @@ static bool udev_set_rumble(unsigned i,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -602,27 +589,23 @@ static void *udev_joypad_init(void *data)
|
||||||
for (i = 0; i < MAX_USERS; i++)
|
for (i = 0; i < MAX_USERS; i++)
|
||||||
udev_pads[i].fd = -1;
|
udev_pads[i].fd = -1;
|
||||||
|
|
||||||
udev_joypad_fd = udev_new();
|
if (!(udev_joypad_fd = udev_new()))
|
||||||
if (!udev_joypad_fd)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
udev_joypad_mon = udev_monitor_new_from_netlink(udev_joypad_fd, "udev");
|
if ((udev_joypad_mon = udev_monitor_new_from_netlink(udev_joypad_fd, "udev")))
|
||||||
if (udev_joypad_mon)
|
|
||||||
{
|
{
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(
|
udev_monitor_filter_add_match_subsystem_devtype(
|
||||||
udev_joypad_mon, "input", NULL);
|
udev_joypad_mon, "input", NULL);
|
||||||
udev_monitor_enable_receiving(udev_joypad_mon);
|
udev_monitor_enable_receiving(udev_joypad_mon);
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerate = udev_enumerate_new(udev_joypad_fd);
|
if (!(enumerate = udev_enumerate_new(udev_joypad_fd)))
|
||||||
if (!enumerate)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
|
udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
|
||||||
udev_enumerate_add_match_subsystem(enumerate, "input");
|
udev_enumerate_add_match_subsystem(enumerate, "input");
|
||||||
udev_enumerate_scan_devices(enumerate);
|
udev_enumerate_scan_devices(enumerate);
|
||||||
devs = udev_enumerate_get_list_entry(enumerate);
|
if (!(devs = udev_enumerate_get_list_entry(enumerate)))
|
||||||
if (!devs)
|
|
||||||
RARCH_DBG("[udev]: Couldn't open any joypads. Are permissions set correctly for /dev/input/event* and /run/udev/?\n");
|
RARCH_DBG("[udev]: Couldn't open any joypads. Are permissions set correctly for /dev/input/event* and /run/udev/?\n");
|
||||||
|
|
||||||
udev_list_entry_foreach(item, devs)
|
udev_list_entry_foreach(item, devs)
|
||||||
|
@ -750,15 +733,14 @@ static int16_t udev_joypad_state(
|
||||||
const struct retro_keybind *binds,
|
const struct retro_keybind *binds,
|
||||||
unsigned port)
|
unsigned port)
|
||||||
{
|
{
|
||||||
unsigned i;
|
|
||||||
int16_t ret = 0;
|
int16_t ret = 0;
|
||||||
uint16_t port_idx = joypad_info->joy_idx;
|
uint16_t port_idx = joypad_info->joy_idx;
|
||||||
|
|
||||||
|
if (port_idx < DEFAULT_MAX_PADS)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
const struct udev_joypad *pad = (const struct udev_joypad*)
|
const struct udev_joypad *pad = (const struct udev_joypad*)
|
||||||
&udev_pads[port_idx];
|
&udev_pads[port_idx];
|
||||||
|
|
||||||
if (port_idx >= DEFAULT_MAX_PADS)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||||
{
|
{
|
||||||
/* Auto-binds are per joypad, not per user. */
|
/* Auto-binds are per joypad, not per user. */
|
||||||
|
@ -776,6 +758,7 @@ static int16_t udev_joypad_state(
|
||||||
/ 0x8000) > joypad_info->axis_threshold)
|
/ 0x8000) > joypad_info->axis_threshold)
|
||||||
ret |= (1 << i);
|
ret |= (1 << i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue