Yamaha32088 Yamaha32088 - 1 year ago 97
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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download