Hi all,

I wanted to share my modification of the axisHandler Nasal function (the 
one that implements control.throttleAxis, mixtureAxis, etc).

Purpose of the mod:

I have one of those joysticks that uses only 50% of the available 
movement range for the throttle. Unfortunately for me, if a binding in 
joystick.xml has a script target (eg. controls.throttleAxis) then the 
offset, factor, etc modifiers are all ignored. This resulted in me not 
being able to reduce throttle below 50%. I could have just mapped all 
the /controls/engines/engine[n]/throttle properties to this axis 
(Input/Joysticks/Logitech/wingman-force.xml does exactly that). Sadly at 
the time I didn't know that I can bind multiple actions to an axis, and 
somehow even after a lot of googling I didn't find the "obvious" 
solution to this problem.

Also it strikes me that throttleAxis exists so you don't have to map 
eight or more engines like that in the first place.

The mod:

The solution was really simple. I just extended the axisHanlder function 
in Nasal/controls.nas with extra parameters for factor and offset, and 
used those instead of the hard-coded values:

var axisHandler = func(pre, post) {
     func(invert = 0, factor = 2, offset = 1) {
         var val = cmdarg().getNode("setting").getValue();
         if(invert) val = -val;
         foreach(var e; engines)
             if(e.selected.getValue()) {
                 setprop(pre ~ e.index ~ post, (offset - val) * factor);
         }
     }
}

My throttle binding now looks like this:

  <axis n="2">
   <desc>Throttle</desc>
   <binding>
    <command>nasal</command>
    <!-- throttleAxis params: invert (0 or 1), factor, offset -->
    <script>controls.throttleAxis(0, 1.1, -0.1)</script>
   </binding>
  </axis>

Note that the invert param is really superfluous now -- you could just 
use a negative factor instead. But I kept it for backwards-compatibility 
with the way it works now. You could simplify the above function if you 
got rid of it but fgjs will need to be edited as well.

I hope you find this mod useful and add it to the next Flightgear 
release. If not, then at least it might show up in a Google search for 
the next guy with this problem :)

Cheers,
Vik
PS: thanks for all the hard work on Flightgear so far! :)

------------------------------------------------------------------------------
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to