Yamaha32088 Yamaha32088 - 4 months ago 23
C Question

Getting live info from /dev/input

I am unsure if this is the correct place for this question. I am attempting to obtain the axis position values from a joystick

on my system. If I run
jstest /dev/input/js0
it will give me live feedback on all buttons and axis positions. I am trying to feed this information into my C program to control servos. Is there a function for doing this? I have not worked much with input devices in programming so this is all new to me. Any help is greatly appreciated.


This page: http://scaryreasoner.wordpress.com/2008/02/22/programming-joysticks-with-linux/ has a nice writeup on how to read the info from /dev/input/js0

The format of the events you read from the file are documented here: https://www.kernel.org/doc/Documentation/input/input.txt . It's a simple struct containing a timestamp, the event type and identifier and the value:

struct input_event {
    struct timeval time;
    unsigned short type;
    unsigned short code;
    unsigned int value;