I'm attempting to read the name, vendor ID and product ID for a USB joystick on Ubuntu (specifically I'm working with a wired Xbox 360 pad on Ubuntu 13.10 x64). I can read the name but when attempting to read the vendor and product IDs I get an EINVAL
error. The code is as follows:
if (plugged[index])
{
char name[32];
std::snprintf(name, sizeof(name), "/dev/input/js%u", index);
// Open the joystick's file descriptor (read-only and non-blocking)
m_file = ::open(name, O_RDONLY | O_NONBLOCK);
if (m_file >= 0)
{
// Retrieve the axes mapping
ioctl(m_file, JSIOCGAXMAP, m_mapping);
// Get the name
char joyname[128];
if (ioctl(m_file, JSIOCGNAME(128), joyname) < 0) {
m_name = "Unknown Joystick";
} else {
m_name = joyname;
}
// Get vendor and product IDs
input_id inpid;
if (ioctl(m_file, EVIOCGID, &inpid) < 0) {
if (errno == EBADF) printf("EBADF\n");
if (errno == EFAULT) printf("EFAULT\n");
if (errno == ENOTTY) printf("ENOTTY\n");
if (errno == EINVAL) printf("EINVAL\n");
m_manufacturerID = 0;
m_productID = 0;
} else {
m_manufacturerID = inpid.vendor;
m_productID = inpid.product;
}
// Reset the joystick state
m_state = JoystickState();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
The snippet that reads vendor and product IDs is:
ioctl(m_file, EVIOCGID, &inpid)
According the man page for ioctl, EINVAL
the request (EVIOCGID
) or argp (inpid
) is invalid.
How can I determine which is invalid?