C code to read USB Joysticks

Matt Graham danceswithcrows at usa.net
Mon Mar 2 14:02:43 MST 2009


From: Mike Bushroe <mbushroe at gmail.com>
> I am trying to write a control program for my Underwater Robot. I plan to
> use several USB Joysticks to input direction, speed, and robotic arm
control
> commands. I was planning on writing the control software running on the
> laptop in C, with a simple loop to poll the joysticks

> My problem is that I have no idea how to read the values of the joystick X,
> Y, and Z and buttons in C code. I have a test program that graphically
shows
> the joystick position and button states, so I know it can be done. But
> without a sample of the interface routine, or directions on how to use an
> API that someone else has provided, I am kind of stuck.

> Does anyone have a link to code that I can work from? Or suggestions on
> where to read instructions on how to do this?

/usr/src/linux/Documentation/joystick-api.txt ?  It's pretty low-level, and
you'll want to read the whole thing before writing any code.

If you want something higher-level, you may want to take a look at something
like SDL.  But you can just open() and read() from the /dev/input/js? devs
and have it all work.  You just need to think at a low level, or use SDL
or something like it.

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see






More information about the PLUG-discuss mailing list