From 2322d0dbe821006fa3c2bd60e4943f07610d6196 Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Sat, 28 Jul 2018 00:33:19 +0200 Subject: [PATCH] Joystick binding changes; - added extra bindings - reworked the view axis (usually bound to the hat); to move at a better rate. - trim to elevator position. When selected this will remember the current position and when the joystick is centered it will apply this as the trim. Very useful for carrier approaches; and also it helps to do something that is much easier with loaded controls when you can feel the pressure being reduced by the operations of the trim switch --- Nasal/controls.nas | 33 +++++++--- Nasal/joystick.nas | 31 +++++++--- gui/dialogs/button-axis-config.xml | 36 +++++++++-- gui/dialogs/button-config.xml | 99 ++++++++++++++++++++++++------ 4 files changed, 154 insertions(+), 45 deletions(-) diff --git a/Nasal/controls.nas b/Nasal/controls.nas index 78cea711c..84be8cac7 100644 --- a/Nasal/controls.nas +++ b/Nasal/controls.nas @@ -268,16 +268,28 @@ setElevatorTrimToPosition = func() { setElevatorTrimToPosition_listener = nil; } var nv = getprop("/controls/flight/elevator")+getprop("/controls/flight/elevator-trim"); + nv = math.min(math.max(-1.0,nv),1.0); 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); -}; + if (math.abs(lv) <= 0.001){ + print("Elevator trim: centre"); + setprop("/controls/flight/elevator-trim", 0); + } else { +print("Trim when centered stick"); + setElevatorTrimToPosition_listener = setlistener("/controls/flight/elevator", func(v){ + if (math.abs(v.getValue()) <= 0.001) { + setprop("controls/flight/elevator",0); + removelistener(setElevatorTrimToPosition_listener); + setElevatorTrimToPosition_listener = nil; + print("set trim to ",nv); + setprop("/controls/flight/elevator-trim", nv); + } + else + print("Not trimming yet ",v.getValue()); + + }, 0, 0); + } +} + ## # Handlers. These are suitable for binding to repeatable button press # events. They are *not* good for binding to the keyboard, since (at @@ -471,6 +483,9 @@ var applyBrakes = func(v, which = 0) { if (which <= 0) { interpolate("/controls/gear/brake-left", v, fullBrakeTime); } if (which >= 0) { interpolate("/controls/gear/brake-right", v, fullBrakeTime); } } +var applyTrigger = func(v) { +setprop("/controls/armament/pickle", v); +} var applyParkingBrake = func(v) { if (!v) { return; } diff --git a/Nasal/joystick.nas b/Nasal/joystick.nas index a5c985b9b..4443a3187 100644 --- a/Nasal/joystick.nas +++ b/Nasal/joystick.nas @@ -195,10 +195,11 @@ var NasalScaleAxis = { }; var NasalLowHighAxis = { - new: func(name, lowscript, highscript, prop) { + new: func(name, lowscript, highscript, prop, repeatable) { var m = { parents: [NasalLowHighAxis, Axis.new(name, prop, 1) ] }; m.lowscript = lowscript; m.highscript = highscript; + m.repeatable = repeatable; return m; }, @@ -209,6 +210,7 @@ var NasalLowHighAxis = { m.lowscript = me.lowscript; m.highscript = me.highscript; + m.repeatable = me.repeatable; return m; }, @@ -238,7 +240,9 @@ var NasalLowHighAxis = { p.getNode("desc", 1).setValue(me.name); p.getNode("low", 1).getNode("binding", 1).getNode("command", 1).setValue("nasal"); + p.getNode("low", 1).getNode("repeatable", 1).setBoolValue(me.repeatable); p.getNode("high", 1).getNode("binding", 1).getNode("command", 1).setValue("nasal"); + p.getNode("high", 1).getNode("repeatable", 1).setBoolValue(me.repeatable); if (me.inverted) { p.getNode("low", 1).getNode("binding", 1).getNode("script", 1).setValue(me.highscript); @@ -283,21 +287,24 @@ var axisBindings = [ 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);", - "/sim/current-view/goal-heading-offset-deg"), + "setprop(\"/sim/current-view/goal-heading-offset-deg\", getprop(\"/sim/current-view/goal-heading-offset-deg\") + 2);", + "setprop(\"/sim/current-view/goal-heading-offset-deg\", getprop(\"/sim/current-view/goal-heading-offset-deg\") - 2);", + "/sim/current-view/goal-heading-offset-deg",1), NasalLowHighAxis.new("View (vertical)", - "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"), + "setprop(\"/sim/current-view/goal-pitch-offset-deg\", getprop(\"/sim/current-view/goal-pitch-offset-deg\") - 1);", + "setprop(\"/sim/current-view/goal-pitch-offset-deg\", getprop(\"/sim/current-view/goal-pitch-offset-deg\") + 1);", + "/sim/current-view/goal-heading-offset-deg",1), 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 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("Flaps", "/controls/flight/flaps", 0.5, 1.0), + PropertyScaleAxis.new("Wings", "/controls/flight/wings", 0.5, 1.0), + PropertyScaleAxis.new("Brake Right", "/controls/gear/brake-right", 0.5, 1.0), + NasalLowHighAxis.new("Aileron Trim inc.", "controls.aileronTrim(-1);", "controls.aileronTrim(1);", "/controls/flight/aileron-trim-delta", 1), + NasalLowHighAxis.new("Elevator Trim inc.", "controls.elevatorTrim(-1);", "controls.elevatorTrim(1);", "/controls/flight/elevator-trim-delta", 1), + NasalLowHighAxis.new("Rudder Trim inc.", "controls.rudderTrim(-1);", "controls.rudderTrim(1);", "/controls/flight/rudder-trim-delta", 1), 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), @@ -529,6 +536,7 @@ var buttonBindings = [ NasalButton.new("Elevator Trim Up", "controls.elevatorTrim(-1);", 1), NasalButton.new("Elevator Trim Down", "controls.elevatorTrim(1);", 1), + NasalButton.new("Elevator Trim Pos", "controls.setElevatorTrimToPosition();", 1), NasalButton.new("Rudder Trim Left", "controls.rudderTrim(-1);", 1), NasalButton.new("Rudder Trim Right", "controls.rudderTrim(1);", 1), NasalButton.new("Aileron Trim Left", "controls.aileronTrim(-1);", 1), @@ -547,8 +555,11 @@ var buttonBindings = [ NasalHoldButton.new("Parking brakes", "controls.parkingBrakeToggle(0);", "controls.parkingBrakeToggle(1);"), NasalHoldButton.new("NWS toggle", "controls.toggleNWS(0);", "controls.toggleNWS(1);"), + PropertyToggleButton.new("Total Freeze", "/sim/freeze/clock"), + # 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. + NasalHoldButton.new("Trigger", "controls.applyTrigger(1);","controls.applyTrigger(0);"), 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"), diff --git a/gui/dialogs/button-axis-config.xml b/gui/dialogs/button-axis-config.xml index e294b8dc6..a57507d73 100644 --- a/gui/dialogs/button-axis-config.xml +++ b/gui/dialogs/button-axis-config.xml @@ -134,6 +134,30 @@ var assignAxis = func(cmd) { + + @@ -185,11 +209,11 @@ var assignAxis = func(cmd) { 4 3 fill - Aileron Trim Incremental + Aileron Trim inc. nasal @@ -197,11 +221,11 @@ var assignAxis = func(cmd) { 5 3 fill - Elevator Trim Incremental + Elevator Trim inc. nasal @@ -209,11 +233,11 @@ var assignAxis = func(cmd) { 6 3 fill - Rudder Trim Incremental + Rudder Trim inc. nasal diff --git a/gui/dialogs/button-config.xml b/gui/dialogs/button-config.xml index 6cde0866a..74a930f41 100644 --- a/gui/dialogs/button-config.xml +++ b/gui/dialogs/button-config.xml @@ -21,8 +21,17 @@ var assignButton = func(cmd) { ]]> - - button-config + + + + button-config vbox true true @@ -100,6 +109,19 @@ var assignButton = func(cmd) { 3 0 fill + Elevator Trim Pos + + nasal + + + + + + + + 0 @@ -547,6 +594,18 @@ var assignButton = func(cmd) { 1 5 fill + Trigger + + nasal + + + +