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.