Skip to content

Commit

Permalink
use real vendor/product id
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nadenislamarre authored and garbear committed May 27, 2024
1 parent 6a88107 commit 73b87c0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/api/udev/JoystickUdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#include "log/Log.h"

#include <algorithm>
#include <cstdio>
#include <errno.h>
#include <fcntl.h>
#include <libudev.h>
#include <limits.h>
#include <linux/input.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 73b87c0

Please sign in to comment.