From 73b87c0bd362b63d885239dda6d3622c21fe3964 Mon Sep 17 00:00:00 2001 From: Nicolas Adenis-Lamarre Date: Mon, 24 Oct 2022 12:59:58 +0000 Subject: [PATCH] use real vendor/product id the current way doesn't provide the real vendor/produc ids that can be found via evtest. This patch applies the same commands from the evtest source code. It works for any pad, including bluetooth pads. This patch was originally written for the batocera project at: https://github.com/batocera-linux/batocera.linux/tree/master/board/batocera/patches/kodi-peripheral-joystick Signed-off-by: Nicolas Adenis-Lamarre --- src/api/udev/JoystickUdev.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/api/udev/JoystickUdev.cpp b/src/api/udev/JoystickUdev.cpp index c4df957b..3a026cdd 100644 --- a/src/api/udev/JoystickUdev.cpp +++ b/src/api/udev/JoystickUdev.cpp @@ -11,10 +11,12 @@ #include "log/Log.h" #include +#include #include #include #include #include +#include #include #include #include @@ -278,15 +280,18 @@ bool CJoystickUdev::GetProperties() } SetName(name); - // Don't worry about unref'ing the parent - struct udev_device* parent = udev_device_get_parent_with_subsystem_devtype(m_dev, "usb", "usb_device"); - - const char* buf; - if ((buf = udev_device_get_sysattr_value(parent, "idVendor")) != nullptr) - SetVendorID(strtol(buf, NULL, 16)); + unsigned short id[4] = {}; + char val[16] = {}; + if (ioctl(m_fd, EVIOCGID, id) == 0) + { + std::sprintf(val, "%x", id[ID_VENDOR]); + SetVendorID(strtol(val, NULL, 16)); + dsyslog("[udev] Joystick information vendorid=%s for %s", val, m_path.c_str()); - if ((buf = udev_device_get_sysattr_value(parent, "idProduct")) != nullptr) - SetProductID(strtol(buf, NULL, 16)); + std::sprintf(val, "%x", id[ID_PRODUCT]); + SetProductID(strtol(val, NULL, 16)); + dsyslog("[udev] Joystick information productid=%s for %s", val, m_path.c_str()); + } struct stat st; if (fstat(m_fd, &st) < 0)