Question

There are a fair few questions about this already, but none answered my question.

I have a Saitek P990 Dual Analog Gamepad, and want to read the joystick movements as intelligible data that I can use to control motors etc.

How would I go about doing this? I would like to write some c code to do this job, if it's possible, but I'm quite new to C and so would need pretty clear explanation :)

Was it helpful?

Solution

If you want to read the raw joystick you have two basic options:

  • Read the old /dev/js0 (or /dev/input/js0) device with joystick events.
  • Find the relevant new /dev/input/event* device and read generic input events.

You can find examples of both easily on the Internet. Or you can use the source (joydev.c, input.c)!

For quick testing, many distributions have the input-utils package. Its source code will be most enlightening.

QUICK LINK:

See for example the tutorial here. The basics are:

  1. Open the device /dev/input/event*, with open().
  2. Use the ioctl() system call with the EVIO* codes to identify the device.
  3. Read the events with read() into input_event structs.
  4. Identify the interesting events and use them!

As I said before, it will be most useful to run the input-events util from the console, to see the input events as your program will receive them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top