mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
(udev) Detect joypad vendor and product id
This commit is contained in:
parent
9b7a8d4654
commit
c9917ce6fe
@ -62,6 +62,8 @@ struct udev_joypad
|
|||||||
|
|
||||||
char *ident;
|
char *ident;
|
||||||
char *path;
|
char *path;
|
||||||
|
int32_t vid;
|
||||||
|
int32_t pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct udev *g_udev;
|
static struct udev *g_udev;
|
||||||
@ -147,7 +149,7 @@ static bool hotplug_available(void)
|
|||||||
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
|
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_device(const char *path, bool hotplugged);
|
static void check_device(struct udev_device *dev, const char *path, bool hotplugged);
|
||||||
static void remove_device(const char *path);
|
static void remove_device(const char *path);
|
||||||
|
|
||||||
static void handle_hotplug(void)
|
static void handle_hotplug(void)
|
||||||
@ -166,7 +168,7 @@ static void handle_hotplug(void)
|
|||||||
if (!strcmp(action, "add"))
|
if (!strcmp(action, "add"))
|
||||||
{
|
{
|
||||||
RARCH_LOG("[udev]: Hotplug add: %s.\n", devnode);
|
RARCH_LOG("[udev]: Hotplug add: %s.\n", devnode);
|
||||||
check_device(devnode, true);
|
check_device(dev, devnode, true);
|
||||||
}
|
}
|
||||||
else if (!strcmp(action, "remove"))
|
else if (!strcmp(action, "remove"))
|
||||||
{
|
{
|
||||||
@ -308,7 +310,7 @@ static void free_pad(unsigned pad, bool hotplug)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_pad(unsigned p, int fd, const char *path)
|
static bool add_pad(struct udev_device *dev, unsigned p, int fd, const char *path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct udev_joypad *pad = &g_pads[p];
|
struct udev_joypad *pad = &g_pads[p];
|
||||||
@ -318,7 +320,22 @@ static bool add_pad(unsigned p, int fd, const char *path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RARCH_LOG("[udev]: Plugged pad: %s on port #%u.\n", pad->ident, p);
|
const char *buf;
|
||||||
|
|
||||||
|
/* don't worry about unref'ing the parent */
|
||||||
|
struct udev_device *parent =
|
||||||
|
udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device");
|
||||||
|
|
||||||
|
pad->vid = pad->pid = 0;
|
||||||
|
|
||||||
|
if ((buf = udev_device_get_sysattr_value(parent, "idVendor")) != NULL)
|
||||||
|
pad->vid = strtol(buf, NULL, 16);
|
||||||
|
|
||||||
|
if ((buf = udev_device_get_sysattr_value(parent, "idProduct")) != NULL)
|
||||||
|
pad->pid = strtol(buf, NULL, 16);
|
||||||
|
|
||||||
|
RARCH_LOG("[udev]: Plugged pad: %s (%04x:%04x) on port #%u.\n",
|
||||||
|
pad->ident, pad->vid, pad->pid, p);
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstat(fd, &st) < 0)
|
if (fstat(fd, &st) < 0)
|
||||||
@ -367,10 +384,8 @@ static bool add_pad(unsigned p, int fd, const char *path)
|
|||||||
pad->fd = fd;
|
pad->fd = fd;
|
||||||
pad->path = strdup(path);
|
pad->path = strdup(path);
|
||||||
|
|
||||||
/* TODO - implement VID/PID? */
|
|
||||||
if (*pad->ident)
|
if (*pad->ident)
|
||||||
input_config_autoconfigure_joypad(p, pad->ident,
|
input_config_autoconfigure_joypad(p, pad->ident, pad->vid, pad->pid, "udev");
|
||||||
0, 0, "udev");
|
|
||||||
|
|
||||||
// Check for rumble features.
|
// Check for rumble features.
|
||||||
unsigned long ffbit[NBITS(FF_MAX)] = {0};
|
unsigned long ffbit[NBITS(FF_MAX)] = {0};
|
||||||
@ -387,7 +402,7 @@ static bool add_pad(unsigned p, int fd, const char *path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_device(const char *path, bool hotplugged)
|
static void check_device(struct udev_device *dev, const char *path, bool hotplugged)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -411,7 +426,7 @@ static void check_device(const char *path, bool hotplugged)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (add_pad(pad, fd, path))
|
if (add_pad(dev, pad, fd, path))
|
||||||
{
|
{
|
||||||
#ifndef IS_JOYCONFIG
|
#ifndef IS_JOYCONFIG
|
||||||
if (hotplugged)
|
if (hotplugged)
|
||||||
@ -501,7 +516,7 @@ static bool udev_joypad_init(void)
|
|||||||
struct udev_device *dev = udev_device_new_from_syspath(g_udev, name);
|
struct udev_device *dev = udev_device_new_from_syspath(g_udev, name);
|
||||||
const char *devnode = udev_device_get_devnode(dev);
|
const char *devnode = udev_device_get_devnode(dev);
|
||||||
if (devnode)
|
if (devnode)
|
||||||
check_device(devnode, false);
|
check_device(dev, devnode, false);
|
||||||
udev_device_unref(dev);
|
udev_device_unref(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user