2019-10-14 16:48:35 +00:00
# A3XX FMGC/Autoflight
# Joshua Davidson (Octal450) and Jonathan Redpath (legoboyvdlp)
2020-04-18 05:36:46 +00:00
# Copyright (c) 2020 Josh Davidson (Octal450)
2019-10-14 16:48:35 +00:00
2020-10-03 09:29:57 +00:00
var at = nil;
var athr = nil;
var ap1 = nil;
var ap2 = nil;
var elapsedtime = nil;
var engout = nil;
var engstate1 = nil;
var engstate2 = nil;
var fd1 = nil;
var fd2 = nil;
var flx = nil;
var gear1 = nil;
var gear2 = nil;
var gs_defl = nil;
var latText = nil;
var MCPalt = nil;
var nav_defl = nil;
var newfd = nil;
var newarm = nil;
var newap = nil;
var newlat = nil;
var newvert = nil;
var newvert2arm = nil;
var newvertarm = nil;
var newthr = nil;
var state1 = nil;
var state2 = nil;
var thr = nil;
var thr1 = nil;
var thr2 = nil;
var trk = nil;
var vert = nil;
var vertText = nil;
2019-10-14 16:48:35 +00:00
2020-10-03 09:29:57 +00:00
var Modes = {
FCU: {
hdgTime: props.globals.initNode("/modes/fcu/hdg-time", -45, "DOUBLE")
},
PFD: {
FMA: {
athr: props.globals.initNode("/modes/pfd/fma/athr-armed", 0, "BOOL"),
athrBox: props.globals.initNode("/modes/pfd/fma/athr-armed-box", 0, "BOOL"),
athrMode: props.globals.initNode("/modes/pfd/fma/at-mode", " ", "STRING"),
athrModeBox: props.globals.initNode("/modes/pfd/fma/athr-mode-box", 0, "BOOL"),
apMode: props.globals.initNode("/modes/pfd/fma/ap-mode", " ", "STRING"),
apModeBox: props.globals.initNode("/modes/pfd/fma/ap-mode-box", 0, "BOOL"),
apModeTime: props.globals.initNode("/modes/pfd/fma/ap-mode-time", 0, "DOUBLE"),
athrModeTime: props.globals.initNode("/modes/pfd/fma/athr-mode-time", 0, "DOUBLE"),
fdMode: props.globals.initNode("/modes/pfd/fma/fd-mode", " ", "STRING"),
fdModeBox: props.globals.initNode("/modes/pfd/fma/fd-mode-box", 0, "BOOL"),
fdModeTime: props.globals.initNode("/modes/pfd/fma/fd-mode-time", 0, "DOUBLE"),
rollMode: props.globals.initNode("/modes/pfd/fma/roll-mode", " ", "STRING"),
rollModeBox: props.globals.initNode("/modes/pfd/fma/roll-mode-box", 0, "BOOL"),
rollModeArmed: props.globals.initNode("/modes/pfd/fma/roll-mode-armed", " ", "STRING"),
rollModeArmedBox: props.globals.initNode("/modes/pfd/fma/roll-mode-armed-box", 0, "BOOL"),
rollModeTime: props.globals.initNode("/modes/pfd/fma/roll-mode-time", 0, "DOUBLE"),
rollModeArmedTime: props.globals.initNode("/modes/pfd/fma/roll-mode-armed-time", 0, "DOUBLE"),
pitchMode: props.globals.initNode("/modes/pfd/fma/pitch-mode", " ", "STRING"),
pitchModeBox: props.globals.initNode("/modes/pfd/fma/pitch-mode-box", 0, "BOOL"),
pitchModeArmed: props.globals.initNode("/modes/pfd/fma/pitch-mode-armed", " ", "STRING"),
pitchModeArmedBox: props.globals.initNode("/modes/pfd/fma/pitch-mode-armed-box", 0, "BOOL"),
pitchMode2Armed: props.globals.initNode("/modes/pfd/fma/pitch-mode2-armed", " ", "STRING"),
pitchModeTime: props.globals.initNode("/modes/pfd/fma/pitch-mode-time", 0, "DOUBLE"),
pitchModeArmedTime: props.globals.initNode("/modes/pfd/fma/pitch-mode-armed-time", 0, "DOUBLE"),
pitchMode2ArmedTime: props.globals.initNode("/modes/pfd/fma/pitch-mode2-armed-time", 0, "DOUBLE"),
pitchMode2ArmedBox: props.globals.initNode("/modes/pfd/fma/pitch-mode2-armed-box", 0, "BOOL"),
throttle: props.globals.initNode("/modes/pfd/fma/throttle-mode", " ", "STRING"),
throttleModeBox: props.globals.initNode("/modes/pfd/fma/throttle-mode-box", 0, "BOOL"),
throttleModeTime: props.globals.initNode("/modes/pfd/fma/throttle-mode-time", 0, "DOUBLE"),
},
},
};
var init = func() {
Internal.alt.setValue(10000);
Modes.PFD.FMA.throttle.setValue(" ");
Modes.PFD.FMA.pitchMode.setValue(" ");
Modes.PFD.FMA.pitchModeArmed.setValue(" ");
Modes.PFD.FMA.pitchMode2Armed.setValue(" ");
Modes.PFD.FMA.rollMode.setValue(" ");
Modes.PFD.FMA.rollModeArmed.setValue(" ");
Modes.PFD.FMA.apMode.setValue(" ");
Modes.PFD.FMA.fdMode.setValue(" ");
Modes.PFD.FMA.athrMode.setValue(" ");
Modes.PFD.FMA.athr.setValue(0);
Modes.PFD.FMA.throttleModeBox.setValue(0);
Modes.PFD.FMA.pitchModeBox.setValue(0);
Modes.PFD.FMA.pitchModeArmedBox.setValue(0);
Modes.PFD.FMA.pitchMode2ArmedBox.setValue(0);
Modes.PFD.FMA.rollModeBox.setValue(0);
Modes.PFD.FMA.rollModeArmedBox.setValue(0);
Modes.PFD.FMA.apModeBox.setValue(0);
Modes.PFD.FMA.fdModeBox.setValue(0);
Modes.PFD.FMA.athrModeBox.setValue(0);
Modes.PFD.FMA.throttleModeTime.setValue(0);
Modes.PFD.FMA.pitchModeTime.setValue(0);
Modes.PFD.FMA.pitchModeArmedTime.setValue(0);
Modes.PFD.FMA.pitchMode2ArmedTime.setValue(0);
Modes.PFD.FMA.rollModeTime.setValue(0);
Modes.PFD.FMA.rollModeArmedTime.setValue(0);
Modes.PFD.FMA.apModeTime.setValue(0);
Modes.PFD.FMA.fdModeTime.setValue(0);
Modes.PFD.FMA.athrModeTime.setValue(0);
2019-10-14 16:48:35 +00:00
loopFMA.start();
2020-10-03 09:29:57 +00:00
};
2019-10-14 16:48:35 +00:00
# Master Thrust
var loopFMA = maketimer(0.05, func {
2020-10-03 09:29:57 +00:00
state1 = pts.Systems.Thrust.state[0].getValue();
state2 = pts.Systems.Thrust.state[1].getValue();
thr1 = pts.Controls.Engines.Engine.throttlePos[0].getValue();
thr2 = pts.Controls.Engines.Engine.throttlePos[1].getValue();
newthr = Modes.PFD.FMA.throttle.getValue();
engout = pts.Systems.Thrust.engOut.getValue();
2019-10-14 16:48:35 +00:00
if (state1 == "TOGA" or state2 == "TOGA") {
if (newthr != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue(" ");
2019-10-14 16:48:35 +00:00
}
} else if ((state1 == "MAN THR" and thr1 >= 0.83) or (state2 == "MAN THR" and thr2 >= 0.83)) {
if (newthr != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if ((state1 == "MCT" or state2 == "MCT") and !engout) {
2019-10-14 16:48:35 +00:00
if (newthr != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (((state1 == "MAN THR" and thr1 < 0.83) or (state2 == "MAN THR" and thr2 < 0.83)) and !engout) {
2019-10-14 16:48:35 +00:00
if (newthr != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue(" ");
2019-10-14 16:48:35 +00:00
}
} else {
2020-10-03 09:29:57 +00:00
vert = Output.vert.getValue();
if (vert == 4 or vert >= 6 or vert <= 8) {
if (Output.ap1.getBoolValue() or Output.ap2.getBoolValue() or Output.fd1.getBoolValue() or Output.fd2.getBoolValue()) {
thr = Output.thrMode.getValue();
2019-10-14 16:48:35 +00:00
if (thr == 0) {
loopFMA_b();
} else if (thr == 1) {
if (newthr != "THR IDLE") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("THR IDLE");
2019-10-14 16:48:35 +00:00
}
} else if (thr == 2) {
2020-10-03 09:29:57 +00:00
if (state1 == "MCT" or state2 == "MCT" and engout) {
2019-10-14 16:48:35 +00:00
if (newthr != "THR MCT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("THR MCT");
2019-10-14 16:48:35 +00:00
}
} else if (state1 == "CL" or state2 == "CL") {
if (newthr != "THR CLB") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("THR CLB");
2019-10-14 16:48:35 +00:00
}
} else {
if (newthr != "THR LVR") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("THR LVR");
2019-10-14 16:48:35 +00:00
}
}
}
2020-10-03 09:29:57 +00:00
} else {
loopFMA_b();
2019-10-14 16:48:35 +00:00
}
} else {
loopFMA_b();
}
}
# A/THR Armed/Active
2020-10-03 09:29:57 +00:00
athr = Output.athr.getValue();
if (athr and (state1 == "MAN THR" or state2 == "MAN THR" or state1 == "MCT" or state2 == "MCT" or state1 == "TOGA" or state2 == "TOGA") and engout != 1) {
if (!Modes.PFD.FMA.athr.getValue()) {
Modes.PFD.FMA.athr.setValue(1);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (athr and ((state1 == "MAN THR" and thr1 >= 0.83) or (state2 == "MAN THR" and thr2 >= 0.83) or (fadec.Thrust.thrustLimit.getValue() == "FLX" and (state1 == "MCT" or state2 == "MCT"))
or state1 == "TOGA" or state2 == "TOGA") and engout) {
if (!Modes.PFD.FMA.athr.getValue()) {
Modes.PFD.FMA.athr.setValue(1);
2019-10-14 16:48:35 +00:00
}
} else {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.athr.getValue()) {
Modes.PFD.FMA.athr.setValue(0);
2019-10-14 16:48:35 +00:00
}
}
# SRS RWY Engagement
2020-10-03 09:29:57 +00:00
flx = fadec.Thrust.limFlex.getValue();
newlat = Modes.PFD.FMA.rollMode.getValue();
engstate1 = pts.Engines.Engine.state[0].getValue();
engstate2 = pts.Engines.Engine.state[1].getValue();
2019-10-14 16:48:35 +00:00
if (((state1 == "TOGA" or state2 == "TOGA") or (flx == 1 and (state1 == "MCT" or state2 == "MCT")) or (flx == 1 and ((state1 == "MAN THR" and thr1 >= 0.83) or (state2 == "MAN THR" and thr2 >= 0.83)))) and (engstate1 == 3 or engstate2 == 3)) {
# RWY Engagement would go here, but automatic ILS selection is not simulated yet.
2020-10-03 09:29:57 +00:00
gear1 = pts.Gear.wow[0].getValue();
if (gear1 and FMGCInternal.v2set and Output.vert.getValue() != 7) {
2019-10-14 16:48:35 +00:00
ITAF.setVertMode(7);
2020-10-03 09:29:57 +00:00
Text.vert.setValue("T/O CLB");
2019-10-14 16:48:35 +00:00
}
} else {
2020-10-03 09:29:57 +00:00
gear1 = pts.Gear.wow[0].getValue();
gear2 = pts.Gear.wow[2].getValue();
if (Input.lat.getValue() == 5 and (gear1 or gear2)) {
2019-10-14 16:48:35 +00:00
ITAF.setLatMode(9);
}
2020-10-03 09:29:57 +00:00
if (Input.vert.getValue() == 7 and (gear1 or gear2)) {
2019-10-14 16:48:35 +00:00
ITAF.setVertMode(9);
}
}
2020-10-03 09:29:57 +00:00
trk = Custom.trkFpa.getValue();
latText = Text.lat.getValue();
if (latText == "HDG" and trk == 0) {
2019-10-14 16:48:35 +00:00
if (newlat != "HDG") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("HDG");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (latText == "HDG" and trk == 1) {
2019-10-14 16:48:35 +00:00
if (newlat != "TRACK") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("TRACK");
2019-10-14 16:48:35 +00:00
}
}
# Boxes
2020-10-03 09:29:57 +00:00
elapsedtime = pts.Sim.Time.elapsedSec.getValue();
if (Modes.PFD.FMA.apModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.apModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.apModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.fdModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.fdModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.fdModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.athrModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.athrModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.athrModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.throttleModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.throttleModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttleModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.rollModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchModeTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.pitchModeBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchModeBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollModeArmedTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.rollModeArmedBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmedBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchModeArmedTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.pitchModeArmedBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchModeArmedBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchMode2ArmedTime.getValue() + 10 >= elapsedtime) {
Modes.PFD.FMA.pitchMode2ArmedBox.setValue(1);
2019-10-14 16:48:35 +00:00
} else {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2ArmedBox.setValue(0);
2019-10-14 16:48:35 +00:00
}
});
var loopFMA_b = func {
2020-10-03 09:29:57 +00:00
newthr = Modes.PFD.FMA.throttle.getValue();
if (!Input.ktsMach.getValue()) {
2019-10-14 16:48:35 +00:00
if (newthr != "SPEED") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("SPEED");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else {
2019-10-14 16:48:35 +00:00
if (newthr != "MACH") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.throttle.setValue("MACH");
2019-10-14 16:48:35 +00:00
}
}
}
# Master Lateral
setlistener("/it-autoflight/mode/lat", func {
2020-10-03 09:29:57 +00:00
latText = Text.lat.getValue();
newlat = Modes.PFD.FMA.rollMode.getValue();
if (latText == "LNAV") {
2019-10-14 16:48:35 +00:00
if (newlat != "NAV") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("NAV");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (latText == "LOC") {
2019-10-14 16:48:35 +00:00
if (newlat != "LOC*" and newlat != "LOC") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("LOC*");
2019-10-14 16:48:35 +00:00
locupdate.start();
}
2020-10-03 09:29:57 +00:00
} else if (latText == "ALGN") {
2019-10-14 16:48:35 +00:00
if (newlat != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (latText == "RLOU") {
2019-10-14 16:48:35 +00:00
if (newlat != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (latText == "T/O") {
2019-10-14 16:48:35 +00:00
if (newlat != "RWY") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("RWY");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (latText == " ") {
2019-10-14 16:48:35 +00:00
if (newlat != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
});
var locupdate = maketimer(0.5, func {
2020-10-03 09:29:57 +00:00
latText = Text.lat.getValue();
newlat = Modes.PFD.FMA.rollMode.getValue();
nav_defl = pts.Instrumentation.Nav.locDeflection.getValue();
if (latText == "LOC") {
2019-10-14 16:48:35 +00:00
if (nav_defl > -0.06 and nav_defl < 0.06) {
locupdate.stop();
if (newlat != "LOC") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollMode.setValue("LOC");
2019-10-14 16:48:35 +00:00
}
}
}
});
# Master Vertical
setlistener("/it-autoflight/mode/vert", func {
2020-10-03 09:29:57 +00:00
vertText = Text.vert.getValue();
newvert = Modes.PFD.FMA.pitchMode.getValue();
newvertarm = Modes.PFD.FMA.pitchMode2Armed.getValue();
if (vertText == "ALT HLD") {
2019-10-14 16:48:35 +00:00
altvert();
if (newvertarm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "ALT CAP") {
2019-10-14 16:48:35 +00:00
altvert();
if (newvertarm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "V/S") {
2019-10-14 16:48:35 +00:00
if (newvert != "V/S") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("V/S");
2019-10-14 16:48:35 +00:00
}
if (newvertarm != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "G/S") {
2019-10-14 16:48:35 +00:00
if (newvert != "G/S*" and newvert != "G/S") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("G/S*");
2019-10-14 16:48:35 +00:00
gsupdate.start();
}
if (newvertarm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "SPD CLB") {
2019-10-14 16:48:35 +00:00
if (newvert != "OP CLB") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("OP CLB");
2019-10-14 16:48:35 +00:00
}
if (newvertarm != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "SPD DES") {
2019-10-14 16:48:35 +00:00
if (newvert != "OP DES") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("OP DES");
2019-10-14 16:48:35 +00:00
}
if (newvertarm != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "FPA") {
2019-10-14 16:48:35 +00:00
if (newvert != "FPA") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("FPA");
2019-10-14 16:48:35 +00:00
}
if (newvertarm != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "LAND") {
2019-10-14 16:48:35 +00:00
if (newvert != "LAND") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("LAND");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "FLARE") {
2019-10-14 16:48:35 +00:00
if (newvert != "FLARE") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("FLARE");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "ROLLOUT") {
2019-10-14 16:48:35 +00:00
if (newvert != "ROLL OUT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("ROLL OUT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "T/O CLB") {
2019-10-14 16:48:35 +00:00
if (newvert != "SRS") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("SRS");
2019-10-14 16:48:35 +00:00
}
updatePitchArm2();
2020-10-03 09:29:57 +00:00
} else if (vertText == "G/A CLB") {
2019-10-14 16:48:35 +00:00
if (newvert != "SRS") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("SRS");
2019-10-14 16:48:35 +00:00
}
if (newvertarm != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == " ") {
2019-10-14 16:48:35 +00:00
if (newvert != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
updatePitchArm2();
}
altvert();
});
var updatePitchArm2 = func {
2020-10-03 09:29:57 +00:00
newvertarm = Modes.PFD.FMA.pitchMode2Armed.getValue();
2020-07-09 22:59:11 +00:00
if (newvertarm != "CLB" and FMGCInternal.v2set) {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode2Armed.setValue("CLB");
} else if (newvertarm != " " and !FMGCInternal.v2set) {
Modes.PFD.FMA.pitchMode2Armed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
var gsupdate = maketimer(0.5, func {
2020-10-03 09:29:57 +00:00
vertText = Text.vert.getValue();
newvert = Modes.PFD.FMA.pitchMode.getValue();
gs_defl = pts.Instrumentation.Nav.gsDeflection.getValue();
if (vertText == "G/S") {
2019-10-14 16:48:35 +00:00
if (gs_defl > -0.06 and gs_defl < 0.06) {
gsupdate.stop();
if (newvert != "G/S") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("G/S");
2019-10-14 16:48:35 +00:00
}
}
}
});
var altvert = func {
2020-10-03 09:29:57 +00:00
MCPalt = Internal.alt.getValue();
vertText = Text.vert.getValue();
newvert = Modes.PFD.FMA.pitchMode.getValue();
if (abs(fmgc.FMGCInternal.crzFt - MCPalt) <= 20) {
if (vertText == "ALT HLD") {
2019-10-14 16:48:35 +00:00
if (newvert != "ALT CRZ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("ALT CRZ");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "ALT CAP") {
2019-10-14 16:48:35 +00:00
if (newvert != "ALT CRZ*") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("ALT CRZ*");
2019-10-14 16:48:35 +00:00
}
}
} else {
2020-10-03 09:29:57 +00:00
if (vertText == "ALT HLD") {
2019-10-14 16:48:35 +00:00
if (newvert != "ALT") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("ALT");
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
} else if (vertText == "ALT CAP") {
2019-10-14 16:48:35 +00:00
if (newvert != "ALT*") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchMode.setValue("ALT*");
2019-10-14 16:48:35 +00:00
}
}
}
}
# Arm HDG or NAV
setlistener("/it-autoflight/mode/arm", func {
2020-10-03 09:29:57 +00:00
arm = Text.arm.getValue();
newarm = Modes.PFD.FMA.rollModeArmed.getValue();
2019-10-14 16:48:35 +00:00
if (arm == "HDG") {
if (newarm != "HDG") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
} else if (arm == "LNV") {
if (newarm != "NAV") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmed.setValue("NAV");
2019-10-14 16:48:35 +00:00
}
} else if (arm == " ") {
if (newarm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
});
# Arm LOC
setlistener("/it-autoflight/output/loc-armed", func {
2020-10-03 09:29:57 +00:00
newarm = Modes.PFD.FMA.rollModeArmed.getValue();
if (Output.locArm.getValue()) {
2019-10-14 16:48:35 +00:00
if (newarm != "LOC") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmed.setValue("LOC");
2019-10-14 16:48:35 +00:00
}
} else {
if (newarm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.rollModeArmed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
});
# Arm G/S
setlistener("/it-autoflight/output/appr-armed", func {
2020-10-03 09:29:57 +00:00
newvert2arm = Modes.PFD.FMA.pitchModeArmed.getValue();
if (Output.apprArm.getValue()) {
2019-10-14 16:48:35 +00:00
if (newvert2arm != "G/S") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchModeArmed.setValue("G/S");
2019-10-14 16:48:35 +00:00
}
} else {
if (newvert2arm != " ") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.pitchModeArmed.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
});
# AP
var ap = func {
2020-10-03 09:29:57 +00:00
ap1 = Output.ap1.getValue();
ap2 = Output.ap2.getValue();
newap = Modes.PFD.FMA.apMode.getValue();
2019-10-14 16:48:35 +00:00
if (ap1 and ap2 and newap != "AP1+2") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.apMode.setValue("AP 1+2");
2019-10-14 16:48:35 +00:00
} else if (ap1 and !ap2 and newap != "AP 1") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.apMode.setValue("AP 1");
2019-10-14 16:48:35 +00:00
} else if (ap2 and !ap1 and newap != "AP 2") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.apMode.setValue("AP 2");
2019-10-14 16:48:35 +00:00
} else if (!ap1 and !ap2) {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.apMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
# FD
var fd = func {
2020-10-03 09:29:57 +00:00
fd1 = Output.fd1.getValue();
fd2 = Output.fd2.getValue();
newfd = Modes.PFD.FMA.fdMode.getValue();
2019-10-14 16:48:35 +00:00
if (fd1 and fd2 and newfd != "1FD2") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.fdMode.setValue("1 FD 2");
2019-10-14 16:48:35 +00:00
} else if (fd1 and !fd2 and newfd != "1 FD -") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.fdMode.setValue("1 FD -");
2019-10-14 16:48:35 +00:00
} else if (fd2 and !fd1 and newfd != "- FD 2") {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.fdMode.setValue("- FD 2");
2019-10-14 16:48:35 +00:00
} else if (!fd1 and !fd2) {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.fdMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
# AT
2020-10-03 09:29:57 +00:00
var atMode = func {
at = Output.athr.getValue();
if (at and Modes.PFD.FMA.athrMode.getValue() != "A/THR") {
Modes.PFD.FMA.athrMode.setValue("A/THR");
2019-10-14 16:48:35 +00:00
} else if (!at) {
2020-10-03 09:29:57 +00:00
Modes.PFD.FMA.athrMode.setValue(" ");
2019-10-14 16:48:35 +00:00
}
}
var boxchk = func {
2020-10-03 09:29:57 +00:00
if ((Output.ap1.getValue() or Output.ap2.getValue() or Output.fd1.getValue() or Output.fd2.getValue()) and !Custom.Output.fmaPower.getValue()) {
Input.lat.setValue(3);
2019-10-14 16:48:35 +00:00
boxchk_b();
}
}
var boxchk_b = func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollMode.getValue() != " ") {
Modes.PFD.FMA.rollModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchMode.getValue() != " ") {
Modes.PFD.FMA.pitchModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollModeArmed.getValue() != " ") {
Modes.PFD.FMA.rollModeArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchModeArmed.getValue() != " ") {
Modes.PFD.FMA.pitchModeArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchMode2Armed.getValue() != " ") {
Modes.PFD.FMA.pitchMode2ArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
}
# Update AP FD ATHR
setlistener("/it-autoflight/output/ap1", func {
ap();
boxchk();
});
setlistener("/it-autoflight/output/ap2", func {
ap();
boxchk();
});
setlistener("/it-autoflight/output/fd1", func {
fd();
boxchk();
});
setlistener("/it-autoflight/output/fd2", func {
fd();
boxchk();
});
setlistener("/it-autoflight/output/athr", func {
2020-10-03 09:29:57 +00:00
atMode();
2019-10-14 16:48:35 +00:00
});
# Boxes
setlistener("/modes/pfd/fma/ap-mode", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.apMode.getValue() != " ") {
Modes.PFD.FMA.apModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/fd-mode", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.fdMode.getValue() != " ") {
Modes.PFD.FMA.fdModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/at-mode", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.athrMode.getValue() != " ") {
Modes.PFD.FMA.throttleModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
Modes.PFD.FMA.athrModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/athr-armed", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.athrMode.getValue() != " ") {
Modes.PFD.FMA.athrModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/throttle-mode", func {
2020-10-03 09:29:57 +00:00
state1 = pts.Systems.Thrust.state[0].getValue();
state2 = pts.Systems.Thrust.state[1].getValue();
athr = Output.athr.getValue();
if (athr == 1 and state1 != "MCT" and state2 != "MCT" and state1 != "MAN THR" and state2 != "MAN THR" and state1 != "TOGA" and state2 != "TOGA" and state1 != "IDLE" and state2 != "IDLE" and
!pts.Systems.Thrust.engOut.getValue()) {
Modes.PFD.FMA.throttleModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
} else if (athr == 1 and state1 != "TOGA" and state2 != "TOGA" and state1 != "IDLE" and state2 != "IDLE" and pts.Systems.Thrust.engOut.getValue()) {
if (pts.Controls.Engines.Engine.throttlePos[0].getValue() < 0.83 and pts.Controls.Engines.Engine.throttlePos[1].getValue() < 0.83) {
Modes.PFD.FMA.throttleModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
}
});
setlistener("/modes/pfd/fma/roll-mode", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollMode.getValue() != " ") {
Modes.PFD.FMA.rollModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/pitch-mode", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchMode.getValue() != " ") {
Modes.PFD.FMA.pitchModeTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/roll-mode-armed", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.rollModeArmed.getValue() != " ") {
Modes.PFD.FMA.rollModeArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/pitch-mode-armed", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchModeArmed.getValue() != " ") {
Modes.PFD.FMA.pitchModeArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
setlistener("/modes/pfd/fma/pitch-mode2-armed", func {
2020-10-03 09:29:57 +00:00
if (Modes.PFD.FMA.pitchMode2Armed != " ") {
Modes.PFD.FMA.pitchMode2ArmedTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-14 16:48:35 +00:00
}
});
2020-10-03 09:29:57 +00:00
2021-05-18 12:02:11 +00:00
setlistener("/sim/signals/fdm-initialized", func {
2020-10-03 09:29:57 +00:00
init();
});