Writing Joystick Code: Part 3: Difference between revisions

no edit summary
No edit summary
Line 1: Line 1:
{{WIP}}


== Special snippets ==
== Special snippets ==
Line 402: Line 399:




-----------------------------------------------------------------------------
 
=== perIndexAxisHandler ===
 
This only works with ''real'' axes.
 
You have a quadrant with 3 levers. Normally they are assigned to controls.throttleAxis(), controls.PropellerAxis() and controls.mixtureAxis().
Now let's say you are flying an aircraft with 2 propeller-engines, it has mixture control, but not propeller-feathering (or you are prepared to use buttons for this).
Now you want the first 2 levers to control the throttles of each engine independently,and the last to do the mixture of both. In this case you would
leave lever 3 assigned to controls.mixtureAxis(), but would use perIndexAxisHandler for the first 2.
 
It works like this: controls.perIndexAxisHandler(function, engine-number).
 
The values for function are
  0 Throttle
  1 Mixture
  2 Propeller
 
Engine-number goes from 0 to 9.
 
So in our example, lever 1 would be assigned
  controls.perIndexAxisHandler(0,0)
and lever 2
  controls.perIndexAxisHandler(0,1)
 
 
See [http://flightgear.org/forums/viewtopic.php?f=24&t=17851 this post] for an example of using this.




You can assign a n axis to more than one engine. Let's say you have 4 engines. You only have 3 levers on the quadrant. You want the
first lever to do the port-outer engine throttle , lever 3 to do the starboard-outer engine throttle, and the middle lever to do the two inboard engine throttles.
So you need to assign the middle lever a list of engines.
Remembering that engines are numbered from 0 upwards for furthest left towards the right, the lever assignments from left to right are
  controls.perIndexAxisHandler(0,0)
  controls.perIndexAxisHandler(0,[1, 2])
  controls.perIndexAxisHandler(0,3)
Notice the list of engine numbers between [ and ] for the middle lever.


peraxisindexhandler


-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
224

edits