Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Because SDL 1.3 is still a long way coming I implemented native force feedback (rumble) support for Aquaria: https://bitbucket.org/panzi/aquaria/

However, I could not find a way to find the according 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.

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.