3
\$\begingroup\$

Because SDL 1.3 is still a long way coming, I implemented native force feedback (rumble) support for Aquaria

However, I could not find a way to find the corresponding event device (force feedback device) for any given joystick (gamepad) device. I looked in the SDL 1.3 source and I thought this might be how it is done:

std::ostringstream os;
os << "/dev/input/js" << sdl_index;
std::string jsdevice(os.str());
char evdevice[128];
evdevice[0] = 0;

int fd = open(jsdevice.c_str(), O_RDONLY, 0);
if (fd <= 0) {
    std::cerr << "Could not open joystick [" << jsdevice << "]: " << strerror(errno) << std::endl;
    return;
}

if (ioctl(fd, EVIOCGNAME(sizeof(evdevice)), evdevice) == -1) {
    std::cerr << "Could not get event device for joystick [" << jsdevice << "]: " << strerror(errno) << std::endl;
    close(fd);
    return;
}

close(fd);

// ...

But it always just prints this:

Could not get event device for joystick [/dev/input/js0]: Invalid argument

Currently, I use an environment variable to indicate the force feedback device that should be used. Does anyone know how to automatically find the correct device? What I've got is the input device as an index (e.g. the 0 in /dev/input/js0) and therefore the path.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

The joystick devices (/dev/input/js*) can be queried via the ioctl function code defined in "joystick.h" (codes starting with JSIOC). The general input devices (/dev/input/event*) can be queried with the codes defined in "input.h" (codes starting with EVIOC).

Of course each joystick device has an associated event input device. I do'not know if this is for true for all distributions, but on my OpenSuse system, there are mappings like

/sys/class/input/js0/device/event7

Google for libjoyrumble.c to find some example code to detect the matching event device.

Heiko

\$\endgroup\$
0
\$\begingroup\$

Use the tool evtest from the force feedback/joystick suite. It listed the necessarz device nicely for me:

# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
...
/dev/input/event23: Microsoft SideWinder Force Feedback 2 Joystick
Select the device event number [0-23]: 

See also https://askubuntu.com/questions/1450181/force-feedback-joystick-support-ms-sidewinder-ff2/1450223#1450223

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .