Reputation: 870
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 :)
Upvotes: 3
Views: 4961
Reputation: 98328
If you want to read the raw joystick you have two basic options:
/dev/js0
(or /dev/input/js0
) device with joystick events./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:
/dev/input/event*
, with open()
.ioctl()
system call with the EVIO*
codes to identify the device.read()
into input_event
structs.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.
Upvotes: 3