Ok. I have written extensions to controls.nas. They enable adjusting elevator-, aileron- and rudder-trim, mixture and throttle with non-repeatable buttons.

An example is:

Button pressed

- Code: Select all
` controls.startAdjustThrottle(1)`

starts the throttle setting increasing.

When the button is released

- Code: Select all
` controls.startAdjustThrottle(0)`

stops the throttle setting right where it is.

Using -1 reduces the throttle setting.

Here is the code

- Code: Select all
`##`

# Trim aileron, elevator and rudder with non-repeating buttons.

# Pressing button starts trim by calling interpolate. Non-repeating button, so nothing else

# happens until button is released, which will interpolate from current position to current position

# in zero seconds, stopping interpolation and trim.

#

# If the argument is 0, stop interpolate. Otherwise start interpolate, either positive or negative.

#

# eg startTrimElevator(-1) starts trimming the elevator and stops it when startTrimElevator(0) received.

# Takes 30 seconds to get from 0 to extremes. Scaled if not starting at 0.

#

var startTrimElevator = func(d) {

var diff = 0;

var elevatortrim = props.globals.getNode("/controls/flight/elevator-trim");

var current = elevatortrim.getValue();

var speed = 30;

if (d == 0) {

# Stop interpolate

interpolate(elevatortrim, current, 0);

}

if (d < 0) {

# Head towards -1. Calculate diff depending on sign of current position

if (current >= 0) {

diff = 1 + current

} else {

diff = 1 - abs(current)

}

interpolate(elevatortrim, -1, diff * speed)

}

if (d > 0) {

# Head towards +1. Calculate diff depending on sign of current position

if (current <= 0) {

diff = 1 + abs(current)

} else {

diff = 1 - current

}

interpolate(elevatortrim, 1, diff * speed)

}

}

var startTrimAileron = func(d) {

var diff = 0;

var ailerontrim = props.globals.getNode("/controls/flight/aileron-trim");

var current = ailerontrim.getValue();

var speed = 30;

if (d == 0) {

# Stop interpolate

interpolate(ailerontrim, current, 0);

}

if (d < 0) {

# Head towards -1. Calculate diff depending on sign of current position

if (current >= 0) {

diff = 1 + current

} else {

diff = 1 - abs(current)

}

interpolate(ailerontrim, -1, diff * speed)

}

if (d > 0) {

# Head towards +1. Calculate diff depending on sign of current position

if (current <= 0) {

diff = 1 + abs(current)

} else {

diff = 1 - current

}

interpolate(ailerontrim, 1, diff * speed)

}

}

var startTrimRudder = func(d) {

var diff = 0;

var ruddertrim = props.globals.getNode("/controls/flight/rudder-trim");

var current = ruddertrim.getValue();

var speed = 30;

if (d == 0) {

# Stop interpolate

interpolate(ruddertrim, current, 0);

}

if (d < 0) {

# Head towards -1. Calculate diff depending on sign of current position

if (current >= 0) {

diff = 1 + current

} else {

diff = 1 - abs(current)

}

interpolate(ruddertrim, -1, diff * speed)

}

if (d > 0) {

# Head towards +1. Calculate diff depending on sign of current position

if (current <= 0) {

diff = 1 + abs(current)

} else {

diff = 1 - current

}

interpolate(ruddertrim, 1, diff * speed)

}

}

##

# Adjust mixture with non-repeating buttons.

# Pressing button starts adjust by calling interpolate. Non-repeating button, so nothing else

# happens until button is released, which will interpolate from current position to current position

# in zero seconds, stopping interpolation and adjust.

#

# If the argument is 0, stop interpolate. Otherwise start interpolate, either positive or negative.

#

# eg startaAdjustMixture(1) starts making the mixture richer and stops when startAdjustMixture(0) received.

# Takes 10 seconds to move between extremes. Scaled if started somewhere in the middle.

#

var startAdjustMixture = func(d) {

var diff = 0;

var mixture = props.globals.getNode("/controls/engines/engine/mixture");

var current = mixture.getValue();

var speed = 10;

# Do nothing if at either limit

if ((current == 0) or (current == 1)) {

return

}

if (d == 0) {

# Stop interpolate

interpolate(mixture, current, 0);

}

if (d < 0) {

# Head towards 0.

diff = current;

interpolate(mixture, 0, diff * speed)

}

if (d > 0) {

# Head towards 1.

diff = 1 - current;

interpolate(mixture, 1, diff * speed)

}

}

##

# Adjust throttle with non-repeating buttons.

# Pressing button starts adjust by calling interpolate. Non-repeating button, so nothing else

# happens until button is released, which will interpolate from current position to current position

# in zero seconds, stopping interpolation and adjust.

#

# If the argument is 0, stop interpolate. Otherwise start interpolate, either positive or negative.

#

# eg startAdjustThrottle(1) starts increasing the throttle setting and stops when startAdjustThrottle(0) received.

# Takes 10 seconds to move between extremes. Scaled if started somewhere in the middle.

#

var startAdjustThrottle = func(d) {

var diff = 0;

var throttle = props.globals.getNode("/controls/engines/engine/throttle");

var current = throttle.getValue();

var speed = 10;

# Do nothing if at either limit

if ((current == 0) or (current == 1)) {

return

}

if (d == 0) {

# Stop interpolate

interpolate(throttle, current, 0);

}

if (d < 0) {

# Head towards 0.

diff = current;

interpolate(throttle, 0, diff * speed)

}

if (d > 0) {

# Head towards 1.

diff = 1 - current;

interpolate(throttle, 1, diff * speed)

}

}

Could someone please check it, test it if you can, and, if approved, commit it. If committed, Stuart must know about it for his joystick settings dialog.

EDIT: If have removed the "do nothing if at either limit." Stupid.