Skip to main content
Don't repeat tags in title
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

Linux: find Find force feedback device for joystick device

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

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

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/dev/input/js0) and therefore the path.

Linux: find force feedback device for joystick device

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.

Find force feedback device for joystick device

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.

Tweeted twitter.com/#!/StackGameDev/status/61944829751463936
Source Link
panzi
  • 131
  • 3

Linux: find force feedback device for joystick device

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.