diff --git a/Nasal/controls.nas b/Nasal/controls.nas index 276d1b899..78cea711c 100644 --- a/Nasal/controls.nas +++ b/Nasal/controls.nas @@ -65,6 +65,35 @@ var throttleMouse = func { } } +setprop("/controls/engines/throttle-all",0); +setprop("/controls/engines/mixture-all",0); +setprop("/controls/engines/propeller-pitch-all",0); + +setForAllEnginesProperty= func(type){ + var engineRoot = props.globals.getNode("/controls/engines"); + var v = getprop("/controls/engines/"~type~"-all"); + v = -v; + v = (v+1)*0.5; # scale from -1..1 to 0..1 + foreach( var c; engineRoot.getChildren() ){ + if (c.getName() =="engine"){ + var n = c.getNode(type); + if(n!=nil) { + n.setValue(v); + } + } + } +} + +_setlistener("/controls/engines/throttle-all", func{ + setForAllEnginesProperty("throttle"); +},0,0); +_setlistener("/controls/engines/mixture-all", func{ + setForAllEnginesProperty("mixture"); +},0,0); +_setlistener("/controls/engines/propeller-pitch-all", func{ + setForAllEnginesProperty("propeller-pitch"); +},0,0); + # Joystick axis handlers (use cmdarg). Shouldn't be called from # other contexts. A non-null argument reverses the axis direction. var axisHandler = func(pre, post) { @@ -232,7 +261,23 @@ var slewProp = func(prop, delta) { # range of a trim axis is 2.0. Should probably read this out of a # property... var TRIM_RATE = 0.045; - +var setElevatorTrimToPosition_listener = nil; +setElevatorTrimToPosition = func() { + if (setElevatorTrimToPosition_listener != nil) { + removelistener(setElevatorTrimToPosition_listener); + setElevatorTrimToPosition_listener = nil; + } + var nv = getprop("/controls/flight/elevator")+getprop("/controls/flight/elevator-trim"); + var lv = getprop("/controls/flight/elevator"); + var setElevatorTrimToPosition_listener = setlistener("/controls/flight/elevator", func(v){ + if (v.getValue() != lv) { + setprop("controls/flight/elevator",0); + removelistener(setElevatorTrimToPosition_listener); + print("set trim to ",nv); + setprop("/controls/flight/elevator-trim", nv); + } + } , 0, 0); +}; ## # Handlers. These are suitable for binding to repeatable button press # events. They are *not* good for binding to the keyboard, since (at @@ -394,14 +439,26 @@ var elevatorTrimAxis = func { elevatorTrim(cmdarg().getNode("setting").getValue( var aileronTrimAxis = func { aileronTrim(cmdarg().getNode("setting").getValue()); } var rudderTrimAxis = func { rudderTrim(cmdarg().getNode("setting").getValue()); } +# +# to avoid clash with "gearToggle"; this will only toggle when +# given a parameter of 1; as the controls button binding will pass 0 when the button is pressed and +# 1 when the button is released. +var gearTogglePosition = func(v) { + if (v){ + if (getprop("/controls/gear/gear-down")) + setprop("/controls/gear/gear-down", 0); + else + setprop("/controls/gear/gear-down", 1); + } +} ## # Gear handling. -# +# - parameter v is either 1 (down), -1 up (retracted) var gearDown = func(v) { if (v < 0) { - setprop("/controls/gear/gear-down", 0); + setprop("/controls/gear/gear-down", 0); } elsif (v > 0) { - setprop("/controls/gear/gear-down", 1); + setprop("/controls/gear/gear-down", 1); } } var gearToggle = func { gearDown(getprop("/controls/gear/gear-down") > 0 ? -1 : 1); } @@ -421,6 +478,62 @@ var applyParkingBrake = func(v) { setprop(p, var i = !getprop(p)); return i; } +var parkingBrakeToggle = func(v) { + if (v){ + if (getprop("/controls/gear/brake-parking")) + setprop("/controls/gear/brake-parking", 0); + else + setprop("/controls/gear/brake-parking", 1); + } +} +var toggleNWS = func(v) { + if (v){ + if (getprop("/controls/gear/nose-wheel-steering")) + setprop("/controls/gear/nose-wheel-steering", 0); + else + setprop("/controls/gear/nose-wheel-steering", 1); + } +} + +var weAppliedSpeedBrake = 99; +var weAppliedWheelBrake = 99; + +# +# allows one binding to do airbrakes and wheel brakes +var applyApplicableBrakes = func(v, which = 0) { + var wow = getprop ("/gear/gear[0]/wow") + or getprop ("/gear/gear[1]/wow") + or getprop ("/gear/gear[2]/wow") + or getprop ("/gear/gear[3]/wow") + or getprop ("/gear/gear[4]/wow") + or getprop ("/gear/gear[5]/wow") + or getprop ("/gear/gear[6]/wow") + ; + + if (wow) { + if (!v and weAppliedSpeedBrake != 99) { + setprop("controls/flight/speedbrake", 0); + weAppliedSpeedBrake=0; + } + if (which <= 0) { + interpolate("/controls/gear/brake-left", v, controls.fullBrakeTime); + } + if (which >= 0) { + interpolate("/controls/gear/brake-right", v, controls.fullBrakeTime); + } + weAppliedWheelBrake = which; + } + else { + if (!v and weAppliedWheelBrake != 99) { + if (weAppliedWheelBrake <= 0) { interpolate("/controls/gear/brake-left", 0, controls.fullBrakeTime); } + if (weAppliedWheelBrake >= 0) { interpolate("/controls/gear/brake-right", 0, controls.fullBrakeTime); } + weAppliedWheelBrake=0; + } + + weAppliedSpeedBrake=which; + setprop("controls/flight/speedbrake", v); + } +} # 1: Deploy, -1: Release var deployChute = func(v) setprop("/controls/flight/drag-chute", v); diff --git a/Nasal/joystick.nas b/Nasal/joystick.nas index 8eb494ab5..a5c985b9b 100644 --- a/Nasal/joystick.nas +++ b/Nasal/joystick.nas @@ -269,6 +269,19 @@ var axisBindings = [ NasalScaleAxis.new("Mixture 2", "controls.perEngineSelectedAxisHandler(1)([1]);", "/controls/engines/engine[1]/mixture") , NasalScaleAxis.new("Propeller 2", "controls.perEngineSelectedAxisHandler(2)([1]);", "/controls/engines/engine[1]/propeller-pitch") , +# 2018.2 (RJH); change engine bindings to use the scaled axis configuration; the -all property +# that is used has a listener in controls.nas that will propogate the value to all configured engines. +# - mainly to allow the use of the "invert" option. + PropertyScaleAxis.new("Throttle All Engines", "/controls/engines/throttle-all") , + PropertyScaleAxis.new("Mixture All Engines", "/controls/engines/mixture-all") , + PropertyScaleAxis.new("Propeller All Engines", "/controls/engines/propeller-pitch-all") , + PropertyScaleAxis.new("Throttle Engine 0", "/controls/engines/engine[0]/throttle") , + PropertyScaleAxis.new("Mixture Engine 0", "/controls/engines/engine[0]/mixture") , + PropertyScaleAxis.new("Propeller Pitch Engine 0", "/controls/engines/engine[0]/propeller-pitch") , + PropertyScaleAxis.new("Throttle Engine 1", "/controls/engines/engine[1]/throttle") , + PropertyScaleAxis.new("Mixture Engine 1", "/controls/engines/engine[1]/mixture") , + PropertyScaleAxis.new("Propeller Pitch Engine 1", "/controls/engines/engine[1]/propeller-pitch"), + NasalLowHighAxis.new("View (horizontal)", "setprop(\"/sim/current-view/goal-heading-offset-deg\", getprop(\"/sim/current-view/goal-heading-offset-deg\") + 30);", "setprop(\"/sim/current-view/goal-heading-offset-deg\", getprop(\"/sim/current-view/goal-heading-offset-deg\") - 30);", @@ -277,14 +290,17 @@ var axisBindings = [ "setprop(\"/sim/current-view/goal-pitch-offset-deg\", getprop(\"/sim/current-view/goal-pitch-offset-deg\") - 20);", "setprop(\"/sim/current-view/goal-pitch-offset-deg\", getprop(\"/sim/current-view/goal-pitch-offset-deg\") + 20);", "/sim/current-view/goal-heading-offset-deg"), -# PropertyScaleAxis.new("Aileron Trim", "/controls/flight/aileron-trim"), -# PropertyScaleAxis.new("Elevator Trim", "/controls/flight/elevator-trim"), -# PropertyScaleAxis.new("Rudder Trim", "/controls/flight/rudder-trim"), + PropertyScaleAxis.new("Aileron Trim", "/controls/flight/aileron-trim"), + PropertyScaleAxis.new("Elevator Trim", "/controls/flight/elevator-trim"), + PropertyScaleAxis.new("Rudder Trim", "/controls/flight/rudder-trim"), PropertyScaleAxis.new("Brake Left", "/controls/gear/brake-left", 0.5, 1.0), PropertyScaleAxis.new("Brake Right", "/controls/gear/brake-right", 0.5, 1.0), - NasalLowHighAxis.new("Aileron Trim", "controls.aileronTrim(-1);", "controls.aileronTrim(1);", "/controls/flight/aileron-trim"), - NasalLowHighAxis.new("Elevator Trim", "controls.elevatorTrim(-1);", "controls.elevatorTrim(1);", "/controls/flight/elevator-trim"), - NasalLowHighAxis.new("Rudder Trim", "controls.rudderTrim(-1);", "controls.rudderTrim(1);", "/controls/flight/rudder-trim"), + NasalLowHighAxis.new("Aileron Trim Incremental", "controls.aileronTrim(-1);", "controls.aileronTrim(1);", "/controls/flight/aileron-trim-delta"), + NasalLowHighAxis.new("Elevator Trim Incremental", "controls.elevatorTrim(-1);", "controls.elevatorTrim(1);", "/controls/flight/elevator-trim-delta"), + NasalLowHighAxis.new("Rudder Trim Incremental", "controls.rudderTrim(-1);", "controls.rudderTrim(1);", "/controls/flight/rudder-trim-delta"), + + PropertyScaleAxis.new("View Horizontal Axis", "/sim/current-view/goal-heading-offset-deg", 180, 0), + PropertyScaleAxis.new("View Vertical Axis", "/sim/current-view/goal-pitch-offset-deg", 180, 0), CustomAxis.new(), UnboundAxis.new(), ]; @@ -519,13 +535,30 @@ var buttonBindings = [ NasalButton.new("Aileron Trim Right", "controls.aileronTrim(1);", 1), NasalHoldButton.new("FGCom PTT", "controls.ptt(1);", "controls.ptt(0);"), NasalHoldButton.new("Trigger", "controls.trigger(1);", "controls.trigger(0);"), - NasalHoldButton.new("Flaps Up", "controls.flapsDown(-1);", "controls.flapsDown(0);"), - NasalHoldButton.new("Flaps Down", "controls.flapsDown(1);", "controls.flapsDown(0);"), - NasalHoldButton.new("Gear Up", "controls.gearDown(-1);", "controls.gearDown(0);"), - NasalHoldButton.new("Gear Down", "controls.gearDown(1);", "controls.gearDown(0);"), + NasalButton.new("Flaps Up", "controls.flapsDown(-1);",0), + NasalButton.new("Flaps Down", "controls.flapsDown(1);",0), + NasalButton.new("Gear Up", "controls.gearDown(-1);",0), + NasalButton.new("Gear Down", "controls.gearDown(1);",0), + NasalButton.new("Gear Toggle", "controls.gearTogglePosition(1);",0), NasalHoldButton.new("Spoilers Retract", "controls.stepSpoilers(-1);", "controls.stepSpoilers(0);"), NasalHoldButton.new("Spoilers Deploy", "controls.stepSpoilers(1);", "controls.stepSpoilers(0);"), NasalHoldButton.new("Brakes", "controls.applyBrakes(1);", "controls.applyBrakes(0);"), + NasalHoldButton.new("Brakes (air/wheel)", "controls.applyApplicableBrakes(1);", "controls.applyApplicableBrakes(0);"), + NasalHoldButton.new("Parking brakes", "controls.parkingBrakeToggle(0);", "controls.parkingBrakeToggle(1);"), + NasalHoldButton.new("NWS toggle", "controls.toggleNWS(0);", "controls.toggleNWS(1);"), + +# with all of these it is expected the the armament system in the selected aircraft +# will manage the wrap around and or reset to zero. + PropertyAdjustButton.new("Pickle", "/controls/armament/pickle-target", "1"), + PropertyAdjustButton.new("Target next", "/controls/armament/target-selected", "1"), + PropertyAdjustButton.new("Target previous", "/controls/armament/target-selected", "-1"), + PropertyAdjustButton.new("Weapon next", "/controls/armament/weapon-selected", "1"), + PropertyAdjustButton.new("Weapon previous", "/controls/armament/weapon-selected", "-1"), + PropertyAdjustButton.new("Azimuth left", "/controls/radar/azimuth-deg", "-5"), + PropertyAdjustButton.new("Azimuth right", "/controls/radar/azimuth-deg", "5"), + PropertyAdjustButton.new("Elevation up", "/controls/radar/elevation-deg", "5"), + PropertyAdjustButton.new("Elevation down", "/controls/radar/elevation-deg", "-5"), + PropertyAdjustButton.new("Missile Reject", "/controls/armament/missile-reject", "1"), NasalButton.new("View Decrease", "view.decrease(0.75);", 1), NasalButton.new("View Increase", "view.increase(0.75);", 1), diff --git a/gui/dialogs/button-axis-config.xml b/gui/dialogs/button-axis-config.xml new file mode 100644 index 000000000..e294b8dc6 --- /dev/null +++ b/gui/dialogs/button-axis-config.xml @@ -0,0 +1,438 @@ + + + + + + + + + + + button-axis-config + vbox + true + true + 3 + + + hbox + 1 + + true + + + + + + true + + + + + + + + left + + + + + + + table + + + 0 + 0 + + + + + + + + + + + + + + + + 0 + 3 + + + + + + + + + + + + + + + + + 0 + 1 + + + + + + + + + + + + + + + + + + + + + 0 + 2 + + + + + + + + + + + + + + + + + + true + + hbox + + + + + + true + + + + diff --git a/gui/dialogs/button-config.xml b/gui/dialogs/button-config.xml index 7c76e2b8b..6cde0866a 100644 --- a/gui/dialogs/button-config.xml +++ b/gui/dialogs/button-config.xml @@ -205,11 +205,24 @@ var assignButton = func(cmd) { - + + + + + + + @@ -497,6 +536,133 @@ var assignButton = func(cmd) { + + 0 + 5 + + + + + + + + + + + + + + @@ -505,6 +671,16 @@ var assignButton = func(cmd) { hbox + +