From a88a8e6843959fbc91d4ea41f0f5c51030cedf44 Mon Sep 17 00:00:00 2001 From: hbeni Date: Mon, 31 Oct 2022 10:48:58 +0100 Subject: [PATCH] KAP140: Upstream update to reiszner/KAP140@8e24f86 Refactoring to button press events, so external hardware can more easily integrate with the KAP140 (Dedicated to Angi, who put my brain into autopilot :) I love you) --- .../Avionics/kap140/kap140-properties.xml | 6 +- .../Avionics/kap140/kap140-proprules.xml | 32 +- Models/Instruments/Avionics/kap140/kap140.xml | 1509 +++-------------- Nasal/kap140.nas | 411 +++++ c182s-set.xml | 9 +- gui/dialogs/kap140-dlg.xml | 2 +- 6 files changed, 633 insertions(+), 1336 deletions(-) create mode 100644 Nasal/kap140.nas diff --git a/Models/Instruments/Avionics/kap140/kap140-properties.xml b/Models/Instruments/Avionics/kap140/kap140-properties.xml index 0d16d51b..0f0bec3e 100644 --- a/Models/Instruments/Avionics/kap140/kap140-properties.xml +++ b/Models/Instruments/Avionics/kap140/kap140-properties.xml @@ -21,6 +21,10 @@ false false + + false + false + 0 0 @@ -92,8 +96,6 @@ - false - false false 0 0 diff --git a/Models/Instruments/Avionics/kap140/kap140-proprules.xml b/Models/Instruments/Avionics/kap140/kap140-proprules.xml index 7598c400..37941c88 100644 --- a/Models/Instruments/Avionics/kap140/kap140-proprules.xml +++ b/Models/Instruments/Avionics/kap140/kap140-proprules.xml @@ -343,8 +343,8 @@ We have captured the localizer and the GS. autopilot/kap140/panel/baro-timer autopilot/kap140/panel/nav-timer autopilot/kap140/panel/gs-timer - autopilot/kap140/settings/cws - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-cws + autopilot/kap140/event/button-disc autopilot/kap140/servo/roll-servo/check-timer autopilot/kap140/servo/pitch-servo/check-timer @@ -1098,7 +1098,7 @@ We have captured the localizer and the GS. autopilot/kap140/roll-axis-fail autopilot/kap140/sensors/turn-indicator-operable - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws autopilot/kap140/sensors/excess-g @@ -1167,8 +1167,8 @@ We have captured the localizer and the GS. autopilot/kap140/panel/baro-timer autopilot/kap140/panel/digit-timer autopilot/kap140/panel/button-ap - autopilot/kap140/settings/cws - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-cws + autopilot/kap140/event/button-disc autopilot/kap140/sensors/pitch-up autopilot/kap140/sensors/pitch-down @@ -1181,7 +1181,7 @@ We have captured the localizer and the GS. false - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc autopilot/kap140/panel/state 6 @@ -1189,7 +1189,7 @@ We have captured the localizer and the GS. 0 - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc @@ -1198,7 +1198,7 @@ We have captured the localizer and the GS. false - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc autopilot/kap140/panel/state 6 @@ -1219,7 +1219,7 @@ We have captured the localizer and the GS. false - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc autopilot/kap140/panel/state 6 @@ -1646,7 +1646,7 @@ We have captured the localizer and the GS. autopilot/kap140/settings/vertical-mode 1 - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws autopilot/internal/vert-speed-fpm @@ -1698,7 +1698,7 @@ We have captured the localizer and the GS. autopilot/kap140/settings/vertical-mode 1 - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws @@ -1746,7 +1746,7 @@ We have captured the localizer and the GS. autopilot/kap140/settings/vertical-mode 2 - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws @@ -1869,7 +1869,6 @@ We have captured the localizer and the GS. 6 instrumentation/nav-source/signal-valid - @@ -1878,7 +1877,6 @@ We have captured the localizer and the GS. autopilot/kap140/settings/lateral-mode 1 - @@ -1889,7 +1887,6 @@ We have captured the localizer and the GS. 0 - @@ -1899,7 +1896,6 @@ We have captured the localizer and the GS. - instrumentation/nav-source/heading-needle-deflection-norm @@ -2794,7 +2790,7 @@ We have captured the localizer and the GS. 6 /autopilot/kap140/roll-axis-fail - /autopilot/kap140/settings/cws + /autopilot/kap140/event/button-cws /autopilot/internal/logic/roll-active @@ -2944,7 +2940,7 @@ We have captured the localizer and the GS. 6 /autopilot/kap140/pitch-axis-fail - /autopilot/kap140/settings/cws + /autopilot/kap140/event/button-cws /autopilot/internal/logic/pitch-active diff --git a/Models/Instruments/Avionics/kap140/kap140.xml b/Models/Instruments/Avionics/kap140/kap140.xml index a956ad7e..9dd742c5 100644 --- a/Models/Instruments/Avionics/kap140/kap140.xml +++ b/Models/Instruments/Avionics/kap140/kap140.xml @@ -20,6 +20,10 @@ KAP140TwoAxisAlt kap140.ac + + + + annunciators @@ -87,23 +91,18 @@ btn-baro - - - - - glass - select - - - 0 - 1 - - - + + 0 + 0 + 0 + 0 + + - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 1 - - - autopilot/kap140/panel/fpm-timer - 0 - - - property-adjust - autopilot/internal/target-climb-rate - -100 - -2000 - 2000 - false - - - property-assign - autopilot/kap140/panel/fpm-old - autopilot/internal/target-climb-rate - - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 2 - - - property-adjust - autopilot/internal/target-pressure - 0.022 - 5.0 - 35.0 - false - - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 2 - - - sim/time/elapsed-sec - - - autopilot/kap140/panel/button-down - 1 - - - - - property-assign - autopilot/internal/target-pressure - - - - property-assign - autopilot/kap140/panel/button-down - 0 - - - - - - - pick - btn-up - - UP Button - - - nasal - - - - property-assign - autopilot/kap140/panel/button-up - sim/time/elapsed-sec - - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 1 - - - autopilot/kap140/panel/fpm-timer - 0 - - - property-adjust - autopilot/internal/target-climb-rate - 100 - -2000 - 2000 - false - - - property-assign - autopilot/kap140/panel/fpm-old - autopilot/internal/target-climb-rate - - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 2 - - - property-adjust - autopilot/internal/target-pressure - -0.022 - 5.0 - 35.0 - false - - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-mode - 2 - - - sim/time/elapsed-sec - - - autopilot/kap140/panel/button-up - 1 - - - - - property-assign - autopilot/internal/target-pressure - - - - property-assign - autopilot/kap140/panel/button-up - 0 - - - - - - - pick - btn-arm - - ARM Button - - - nasal - - - - property-assign - autopilot/kap140/panel/button-arm - sim/time/elapsed-sec - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-arm - 2 - - - property-assign - autopilot/kap140/settings/vertical-arm - -1 - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-arm - 0 - - - property-assign - autopilot/kap140/settings/vertical-arm - 2 - - - - - autopilot/kap140/panel/state - 6 - - - autopilot/kap140/settings/vertical-arm - 0 - - - property-assign - autopilot/kap140/settings/vertical-arm - 0 - - - - property-assign - autopilot/kap140/panel/button-arm - 0 - - - - - - - pick - btn-baro - - BARO Button - nasal - - property-assign - autopilot/kap140/panel/button-baro - sim/time/elapsed-sec - - - - - autopilot/kap140/panel/state - 3 - - - property-assign - autopilot/kap140/panel/baro-mode-old - autopilot/kap140/panel/baro-mode - property-assign - autopilot/kap140/panel/button-baro + autopilot/kap140/event/button-baro 0 @@ -2506,136 +1669,14 @@ knob knob-outer - - - - nasal - - - - - - autopilot/kap140/panel/state - 4 - - - autopilot/kap140/panel/digit-mode - 1 - - - property-adjust - autopilot/internal/target-altitude - 1000 - -1000 - 35000 - false - - - - - - autopilot/kap140/panel/state - 5 - - - autopilot/kap140/panel/digit-mode - 1 - - - autopilot/kap140/settings/vertical-arm - 0 - - - property-assign - autopilot/kap140/settings/vertical-arm - 2 - - - - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - autopilot/kap140/panel/baro-mode - 0 - - - property-adjust - - 0.1 - 26.0 - 33.0 - false - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - autopilot/kap140/panel/baro-mode - 1 - - property-adjust - - 10 - 880 - 1118 - false - - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - property-assign - autopilot/kap140/panel/baro-timer - sim/time/elapsed-sec - - - - - - autopilot/kap140/panel/state - 4 - - - property-assign - autopilot/kap140/panel/state - 5 + autopilot/kap140/event/knob-outer + 1 - - - - property-adjust - autopilot/kap140/panel/knob-outer-pos - 1 + nasal + @@ -2645,138 +1686,15 @@ knob knob-inner - - - - nasal - - - - - - autopilot/kap140/panel/state - 4 - - - autopilot/kap140/panel/digit-mode - 1 - - - property-adjust - autopilot/internal/target-altitude - 100 - -1000 - 35000 - false - - - - - - autopilot/kap140/panel/state - 5 - - - autopilot/kap140/panel/digit-mode - 1 - - - autopilot/kap140/settings/vertical-arm - 0 - - - property-assign - autopilot/kap140/settings/vertical-arm - 2 - - - - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - autopilot/kap140/panel/baro-mode - 0 - - - property-adjust - - 0.01 - 26.0 - 33.0 - false - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - autopilot/kap140/panel/baro-mode - 1 - - property-adjust - + autopilot/kap140/event/knob-inner 1 - 880 - 1118 - false - - - - - - - autopilot/kap140/panel/state - 3 - - - autopilot/kap140/panel/digit-mode - 3 - - - property-assign - autopilot/kap140/panel/baro-timer - sim/time/elapsed-sec - - - - - - autopilot/kap140/panel/state - 4 - - - property-assign - autopilot/kap140/panel/state - 5 - - - - property-adjust - autopilot/kap140/panel/knob-inner-pos - 1 + nasal + - @@ -2803,12 +1721,8 @@ translate btn-ap - autopilot/kap140/panel/button-ap + autopilot/kap140/event/button-ap 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2817,12 +1731,8 @@ translate btn-hdg - autopilot/kap140/panel/button-hdg + autopilot/kap140/event/button-hdg 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2831,12 +1741,8 @@ translate btn-nav - autopilot/kap140/panel/button-nav + autopilot/kap140/event/button-nav 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2845,12 +1751,8 @@ translate btn-apr - autopilot/kap140/panel/button-apr + autopilot/kap140/event/button-apr 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2859,12 +1761,8 @@ translate btn-rev - autopilot/kap140/panel/button-rev + autopilot/kap140/event/button-rev 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2873,12 +1771,8 @@ translate btn-alt - autopilot/kap140/panel/button-alt + autopilot/kap140/event/button-alt 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2887,12 +1781,8 @@ translate btn-up - autopilot/kap140/panel/button-up + autopilot/kap140/event/button-up 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2901,12 +1791,8 @@ translate btn-down - autopilot/kap140/panel/button-down + autopilot/kap140/event/button-down 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2915,12 +1801,8 @@ translate btn-arm - autopilot/kap140/panel/button-arm + autopilot/kap140/event/button-arm 1 - - 0.00.0 - 1.01.0 - knob-axis @@ -2929,15 +1811,20 @@ translate btn-baro - autopilot/kap140/panel/button-baro + autopilot/kap140/event/button-baro 1 - - 0.00.0 - 1.01.0 - knob-axis + + + diff --git a/Nasal/kap140.nas b/Nasal/kap140.nas new file mode 100644 index 00000000..dc30d8ee --- /dev/null +++ b/Nasal/kap140.nas @@ -0,0 +1,411 @@ +var config = io.read_properties("Models/Instruments/Avionics/kap140/kap140-config.xml"); + +var kap140_ap = props.globals.initNode("autopilot/kap140/event/button-ap" , 0, "BOOL"); +var kap140_hdg = props.globals.initNode("autopilot/kap140/event/button-hdg", 0, "BOOL"); +var kap140_nav = props.globals.initNode("autopilot/kap140/event/button-nav", 0, "BOOL"); +var kap140_apr = props.globals.initNode("autopilot/kap140/event/button-apr", 0, "BOOL"); +var kap140_rev = props.globals.initNode("autopilot/kap140/event/button-rev", 0, "BOOL"); +var kap140_alt = props.globals.initNode("autopilot/kap140/event/button-alt", 0, "BOOL"); +var kap140_down = props.globals.initNode("autopilot/kap140/event/button-down", 0, "BOOL"); +var kap140_up = props.globals.initNode("autopilot/kap140/event/button-up", 0, "BOOL"); +var kap140_arm = props.globals.initNode("autopilot/kap140/event/button-arm", 0, "BOOL"); +var kap140_baro = props.globals.initNode("autopilot/kap140/event/button-baro", 0, "BOOL"); +var kap140_outer= props.globals.initNode("autopilot/kap140/event/knob-outer", 0, "INT"); +var kap140_inner= props.globals.initNode("autopilot/kap140/event/knob-inner", 0, "INT"); + + + +setlistener(kap140_ap, func(ap) { + if (ap.getBoolValue()) { + setprop("autopilot/kap140/panel/button-ap", getprop("sim/time/elapsed-sec")); + setprop("autopilot/kap140/panel/state-old", getprop("autopilot/kap140/panel/state")); + setprop("autopilot/internal/target-climb-rate", getprop("autopilot/internal/vert-speed-fpm")); + } + else + { + setprop("autopilot/kap140/panel/button-ap", 0); + } +},0,0); + +setlistener(kap140_hdg, func(hdg) { + if (hdg.getBoolValue()) { + setprop("autopilot/kap140/panel/button-hdg", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + if ( + getprop("autopilot/kap140/settings/lateral-mode") < 3 and + getprop("autopilot/kap140/settings/lateral-arm") < 3 + ) { + if (getprop("autopilot/kap140/settings/lateral-mode") == 1) + { + setprop("autopilot/kap140/settings/lateral-mode", 2); + } + else if (getprop("autopilot/kap140/settings/lateral-mode") == 2) + { + setprop("autopilot/kap140/settings/lateral-mode", 1); + } + } + if ( + getprop("autopilot/kap140/settings/lateral-mode") > 2 and + getprop("autopilot/kap140/settings/lateral-mode") < 6 + ) { + if (getprop("autopilot/kap140/settings/from-hdg")) + { + setprop("autopilot/kap140/settings/lateral-mode", 2); + } + else + { + setprop("autopilot/kap140/settings/lateral-mode", 1); + } + } + if (getprop("autopilot/kap140/settings/lateral-mode") < 3) + { + setprop("autopilot/kap140/settings/from-hdg", 0); + } + } + } + else + { + setprop("autopilot/kap140/panel/button-hdg", 0); + } + setprop("autopilot/kap140/settings/lateral-arm", 0); + setprop("autopilot/internal/target-roll-deg", 0); + setprop("autopilot/internal/target-intercept-angle", 0); + setprop("autopilot/kap140/panel/hdg-timer", 0); + setprop("autopilot/kap140/panel/nav-timer", 0); +},0,0); + +setlistener(kap140_nav, func(nav) { + if (nav.getBoolValue()) { + setprop("autopilot/kap140/panel/button-nav", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + var hsi_installed = config.getValue("params/hsi-installed"); + if (getprop("autopilot/kap140/settings/lateral-mode") != 3) { + if (getprop("autopilot/kap140/settings/lateral-arm") == 3) { + setprop("autopilot/kap140/settings/lateral-arm", 0); + } + else + { + setprop("autopilot/kap140/settings/lateral-arm", 3); + } + } + if (!getprop(hsi_installed)) + { + if (getprop("autopilot/kap140/settings/lateral-arm") == 3) + { + if (getprop("autopilot/kap140/settings/lateral-mode") == 2) + { + setprop("autopilot/kap140/settings/from-hdg", 1); + } + setprop("autopilot/kap140/panel/hdg-timer", getprop("sim/time/elapsed-sec")); + } + else + { + setprop("autopilot/kap140/settings/from-hdg", 0); + setprop("autopilot/kap140/panel/hdg-timer", 0); + } + } + } + } + else + { + setprop("autopilot/kap140/panel/button-nav", 0); + } + setprop("autopilot/kap140/panel/nav-timer", 0); +},0,0); + +setlistener(kap140_apr, func(apr) { + if (apr.getBoolValue()) { + setprop("autopilot/kap140/panel/button-apr", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + var hsi_installed = config.getValue("params/hsi-installed"); + if (getprop("autopilot/kap140/settings/lateral-mode") != 4) { + if (getprop("autopilot/kap140/settings/lateral-arm") == 4) { + setprop("autopilot/kap140/settings/lateral-arm", 0); + } + else + { + setprop("autopilot/kap140/settings/lateral-arm", 4); + } + } + if (!getprop(hsi_installed)) + { + if (getprop("autopilot/kap140/settings/lateral-arm") == 4) + { + if (getprop("autopilot/kap140/settings/lateral-mode") == 2) + { + setprop("autopilot/kap140/settings/from-hdg", 1); + } + setprop("autopilot/kap140/panel/hdg-timer", getprop("sim/time/elapsed-sec")); + } + else + { + setprop("autopilot/kap140/settings/from-hdg", 0); + setprop("autopilot/kap140/panel/hdg-timer", 0); + } + } + } + } + else + { + setprop("autopilot/kap140/panel/button-apr", 0); + } + setprop("autopilot/kap140/panel/nav-timer", 0); +},0,0); + +setlistener(kap140_rev, func(rev) { + if (rev.getBoolValue()) { + setprop("autopilot/kap140/panel/button-rev", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + var hsi_installed = config.getValue("params/hsi-installed"); + if (getprop("autopilot/kap140/settings/lateral-mode") != 5) { + if (getprop("autopilot/kap140/settings/lateral-arm") == 5) { + setprop("autopilot/kap140/settings/lateral-arm", 0); + } + else + { + setprop("autopilot/kap140/settings/lateral-arm", 5); + } + } + if (!getprop(hsi_installed)) + { + if (getprop("autopilot/kap140/settings/lateral-arm") == 5) + { + if (getprop("autopilot/kap140/settings/lateral-mode") == 2) + { + setprop("autopilot/kap140/settings/from-hdg", 1); + } + setprop("autopilot/kap140/panel/hdg-timer", getprop("sim/time/elapsed-sec")); + } + else + { + setprop("autopilot/kap140/settings/from-hdg", 0); + setprop("autopilot/kap140/panel/hdg-timer", 0); + } + } + } + } + else + { + setprop("autopilot/kap140/panel/button-rev", 0); + } + setprop("autopilot/kap140/panel/nav-timer", 0); +},0,0); + +setlistener(kap140_alt, func(alt) { + if (alt.getBoolValue()) { + setprop("autopilot/kap140/panel/button-alt", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + var pressure_source = config.getValue("params/pressure-source"); + if (getprop("autopilot/kap140/settings/vertical-mode") == 2) { + setprop("autopilot/kap140/settings/vertical-mode", 1); + setprop("autopilot/internal/target-pressure", 0.0); + } + else if (getprop("autopilot/kap140/settings/vertical-mode") == 1) + { + setprop("autopilot/kap140/settings/vertical-mode", 2); + setprop("autopilot/internal/target-pressure", getprop(pressure_source)); + } + setprop("autopilot/kap140/panel/gs-timer", 0); + } + } + else + { + setprop("autopilot/kap140/panel/button-alt", 0); + } +},0,0); + +setlistener(kap140_down, func(down) { + if (down.getBoolValue()) { + setprop("autopilot/kap140/panel/button-down", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + if (getprop("autopilot/kap140/settings/vertical-mode") == 1 and + getprop("autopilot/kap140/panel/fpm-timer") > 0) + { + var climb = getprop("autopilot/internal/target-climb-rate") - 100; + if (climb < -2000) climb = -2000; + setprop("autopilot/internal/target-climb-rate", climb); + } + if (getprop("autopilot/kap140/settings/vertical-mode") == 2) + { + var pressure = getprop("autopilot/internal/target-pressure") + .022; + if (pressure > 35.0) pressure = 35.0; + setprop("autopilot/internal/target-pressure", pressure); + } + setprop("autopilot/kap140/panel/fpm-old", getprop("autopilot/internal/target-climb-rate")); + } + } + else + { + if (getprop("autopilot/kap140/panel/state") == 6 and + getprop("autopilot/kap140/settings/vertical-mode") == 2 and + getprop("sim/time/elapsed-sec") > getprop("autopilot/kap140/panel/button-down") + 1 + ) + { + var pressure_source = config.getValue("params/pressure-source"); + setprop("autopilot/internal/target-pressure", getprop(pressure_source)); + } + setprop("autopilot/kap140/panel/button-down", 0); + } +},0,0); + +setlistener(kap140_up, func(up) { + if (up.getBoolValue()) { + setprop("autopilot/kap140/panel/button-up", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + if (getprop("autopilot/kap140/settings/vertical-mode") == 1 and + getprop("autopilot/kap140/panel/fpm-timer") > 0) + { + var climb = getprop("autopilot/internal/target-climb-rate") + 100; + if (climb > 2000) climb = 2000; + setprop("autopilot/internal/target-climb-rate", climb); + } + if (getprop("autopilot/kap140/settings/vertical-mode") == 2) + { + var pressure = getprop("autopilot/internal/target-pressure") - .022; + if (pressure < 5.0) pressure = 5.0; + setprop("autopilot/internal/target-pressure", pressure); + } + setprop("autopilot/kap140/panel/fpm-old", getprop("autopilot/internal/target-climb-rate")); + } + } + else + { + if (getprop("autopilot/kap140/panel/state") == 6 and + getprop("autopilot/kap140/settings/vertical-mode") == 2 and + getprop("sim/time/elapsed-sec") > getprop("autopilot/kap140/panel/button-up") + 1 + ) + { + var pressure_source = config.getValue("params/pressure-source"); + setprop("autopilot/internal/target-pressure", getprop(pressure_source)); + } + setprop("autopilot/kap140/panel/button-up", 0); + } +},0,0); + +setlistener(kap140_arm, func(arm) { + if (arm.getBoolValue()) { + setprop("autopilot/kap140/panel/button-arm", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") == 6) { + if (getprop("autopilot/kap140/settings/vertical-arm") == 2) { + setprop("autopilot/kap140/settings/vertical-arm", 0); + } + else + { + setprop("autopilot/kap140/settings/vertical-arm", 2); + } + } + } + else + { + setprop("autopilot/kap140/panel/button-arm", 0); + } +},0,0); + +setlistener(kap140_baro, func(baro) { + if (baro.getBoolValue()) { + setprop("autopilot/kap140/panel/button-baro", getprop("sim/time/elapsed-sec")); + if (getprop("autopilot/kap140/panel/state") > 3) { + setprop("autopilot/kap140/panel/baro-mode-old", getprop("autopilot/kap140/panel/baro-mode")); + } + } + else + { + setprop("autopilot/kap140/panel/button-baro", 0); + } +},0,0); + +setlistener(kap140_outer, func(outer) { + if (outer.getValue()) { + var baro_tied = config.getValue("params/baro-tied"); + var baro_inhg = config.getValue("params/baro-inhg"); + var baro_hpa = config.getValue("params/baro-hpa"); + + if (getprop("autopilot/kap140/panel/state") > 3 and + getprop("autopilot/kap140/panel/digit-mode") == 3 and + !getprop(baro_tied)) + { + if (getprop("autopilot/kap140/panel/baro-mode") == 0) { + var baro = getprop(baro_inhg) + outer.getValue() * 0.1; + if (baro < 26.0) baro = 26.0; + if (baro > 33.0) baro = 33.0; + setprop(baro_inhg, baro); + } + if (getprop("autopilot/kap140/panel/baro-mode") == 1) { + var baro = getprop(baro_hpa) + outer.getValue() * 10; + if (baro < 880) baro = 880; + if (baro > 1118) baro = 1118; + setprop(baro_hpa, baro); + } + setprop("autopilot/kap140/panel/baro-timer", getprop("sim/time/elapsed-sec")); + } + + if (getprop("autopilot/kap140/panel/state") == 4) { + setprop("autopilot/kap140/panel/state", 5); + } + + if (getprop("autopilot/kap140/panel/state") > 4 and + getprop("autopilot/kap140/panel/digit-mode") == 1) + { + var altitude = getprop("autopilot/internal/target-altitude") + outer.getValue() * 1000; + if (altitude < -1000) altitude = -1000; + if (altitude > 35000) altitude = 35000; + setprop("autopilot/internal/target-altitude", altitude); + + if (getprop("autopilot/kap140/panel/state") > 5) { + setprop("autopilot/kap140/settings/vertical-arm", 2); + } + } + + setprop("autopilot/kap140/panel/knob-outer-pos", getprop("autopilot/kap140/panel/knob-outer-pos") + outer.getValue()); + setprop("autopilot/kap140/event/knob-outer", 0); + } +},0,0); + + +setlistener(kap140_inner, func(inner) { + if (inner.getValue()) { + var baro_tied = config.getValue("params/baro-tied"); + var baro_inhg = config.getValue("params/baro-inhg"); + var baro_hpa = config.getValue("params/baro-hpa"); + + if (getprop("autopilot/kap140/panel/state") > 3 and + getprop("autopilot/kap140/panel/digit-mode") == 3 and + !getprop(baro_tied)) + { + if (getprop("autopilot/kap140/panel/baro-mode") == 0) { + var baro = getprop(baro_inhg) + inner.getValue() * 0.01; + if (baro < 26.0) baro = 26.0; + if (baro > 33.0) baro = 33.0; + setprop(baro_inhg, baro); + } + if (getprop("autopilot/kap140/panel/baro-mode") == 1) { + var baro = getprop(baro_hpa) + inner.getValue(); + if (baro < 880) baro = 880; + if (baro > 1118) baro = 1118; + setprop(baro_hpa, baro); + } + setprop("autopilot/kap140/panel/baro-timer", getprop("sim/time/elapsed-sec")); + } + + if (getprop("autopilot/kap140/panel/state") == 4) { + setprop("autopilot/kap140/panel/state", 5); + } + + if (getprop("autopilot/kap140/panel/state") > 4 and + getprop("autopilot/kap140/panel/digit-mode") == 1) + { + var altitude = getprop("autopilot/internal/target-altitude") + inner.getValue() * 100; + if (altitude < -1000) altitude = -1000; + if (altitude > 35000) altitude = 35000; + setprop("autopilot/internal/target-altitude", altitude); + + if (getprop("autopilot/kap140/panel/state") > 5) { + setprop("autopilot/kap140/settings/vertical-arm", 2); + } + } + + setprop("autopilot/kap140/panel/knob-inner-pos", getprop("autopilot/kap140/panel/knob-inner-pos") + inner.getValue()); + setprop("autopilot/kap140/event/knob-inner", 0); + } +},0,0); + diff --git a/c182s-set.xml b/c182s-set.xml index 230d4dec..dc50fd99 100644 --- a/c182s-set.xml +++ b/c182s-set.xml @@ -1431,6 +1431,7 @@ Aircraft/c182s/Nasal/c182s.nas Aircraft/c182s/Nasal/engine.nas Aircraft/c182s/Nasal/fuelcontamination.nas + Aircraft/c182s/Nasal/kap140.nas Aircraft/c182s/Nasal/kx165a.nas Aircraft/c182s/Nasal/kt76c.nas Aircraft/c182s/Nasal/kn62a.nas @@ -1528,13 +1529,13 @@ CWS Button KAP 140 property-assign - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws 1 property-assign - autopilot/kap140/settings/cws + autopilot/kap140/event/button-cws 0 @@ -1544,13 +1545,13 @@ AP-DISC Button KAP 140 property-assign - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc 1 property-assign - autopilot/kap140/settings/ap-disc + autopilot/kap140/event/button-disc 0 diff --git a/gui/dialogs/kap140-dlg.xml b/gui/dialogs/kap140-dlg.xml index 8cf839c3..02d72457 100644 --- a/gui/dialogs/kap140-dlg.xml +++ b/gui/dialogs/kap140-dlg.xml @@ -112,7 +112,7 @@ /autopilot/kap140/panel/state 6 - /autopilot/kap140/settings/cws + /autopilot/kap140/event/button-cws