• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Joystick programming

Dark Jaguar

Graduate Poster
Joined
Jan 19, 2006
Messages
1,666
I'm messing around with some input controls at the moment. Question, is there anything that would prevent me from taking a joystick axis such as a pressure sensitive shoulder button on a PC game controller and assigning different functions to different positions it could be in as opposed to assigning it's entire "range" to simply one function? That is, could I assign a pressure sensitive analog trigger to "gas pedal" in a car with most of the range basically just being how fast I go, but when I press it all the way down, the last bit of the range accesses a different function and fires a missile?

Seems like a simple "yes" to me, but someone else disagrees and barring actually testing it myself (which I won't be able to do for a while) I was just wanting to know if this person knows something I don't.
 
The only joystick programming I ever did was years ago with a very basic joystick, where the only input from the stick was an X value, a Y value, and a boolean indication as to whether or not the button was pressed.

If the button you are talking about sends more than an on/off signal, and you can indeed tell how far it has been pressed, then there should be nothing to prevent you from assigning whatever reaction you want to whatever degree of "pressed" the stick feeds back to you.

I don't know how user-friendly it would be, but that's another issue.
 
I figured as much. The trick is finding the right API for this sort of thing so I can get access to game controllers under Windows.
 
I think it shoud be possible, an analog stick reports its position, and a trigger in the game activates if the position exceeds a certain amount (or falls within a range).

But it does create a problem, what if the user wants to maximize their analog input without triggering the secondary function?
 
I thought as much. It's just a friend of my swears up and down it's impossible for some reason and I just wanted to be sure before I go through the effort.

Yeah, that's a problem but only if that extra range is actually needed. The real problem comes from how usable such a thing would be. I've seen some controllers that actually add this digital click (a normal digital button) that you get right at the "bottom" of the analog button, which makes it easy enough for the user to feel exactly where they have stopped with the primary function and just about hit the secondary function. It was comfortable to rest the finger that way too. With just the analog trigger, it'll be easy to accidently press it all the way, so I'll need to take that into consideration in making those ranges. Really this is an experiment more than anything. As it stands, the "digital analog combo" controller isn't a PC controller but rather a video game console controller, so that one's not an option to use.
 
Question, is there anything that would prevent me from taking a joystick axis such as a pressure sensitive shoulder button on a PC game controller and assigning different functions to different positions it could be in as opposed to assigning it's entire "range" to simply one function?
Yes, it is definitely possible. You "simply" need to write your own joystick device driver.

There is one problem though: how would you differentiate between a state such as 25% pulled, and GOING to a state, such as 75% pulled? I guess you would have to have a timer, so that if you spent more than 100 ms in one state, it would fire the state event, otherwise it would assume you are moving onto a different state.

Interesting idea though. Tough one to pull off.
 
While true for a mouse, my understanding is that a joystick is a different breed. It isn't the going to a state so much as actually being in a state that it detects. So, as opposed to a mouse which is only capable of detecting motion, a joystick can detect it's current position on an axis. The evidence that this is already in place is in every bit of "calibration" software I've seen for joysticks, where it shows your current position and it keeps it there so long as your joystick is still tilted that way. Further, numbers are assigned to each position along both axis (not sure of the plural of that), from 0 to 255 in the case of the Windows XP game controller one. Further, after calibration, if you hold the joystick in one direction while starting up an application that uses it, it'll detect that it was already in that angle and respond as a result (a miscalibrated joystick where the true center is percieved as "down" in the game can result in an annoying "scrolling" behavior in the starting menu of some games, for example). As such, while detecting speed would be, as you said, crucial in programming such things in a mouse, in a joystick it seems that such would be completely unneeded and simply assigning specific values of the axis to different functions would be enough.
 

Back
Top Bottom