2020-04-30 19:26:36 +00:00
# A3XX mCDU by Joshua Davidson (Octal450), Jonathan Redpath, and Matthew Maring (mattmaring)
2019-10-14 16:48:35 +00:00
2022-01-11 02:17:41 +00:00
# Copyright (c) 2022 Josh Davidson (Octal450)
2020-04-30 19:26:36 +00:00
# Copyright (c) 2020 Matthew Maring (mattmaring)
2019-10-14 16:48:35 +00:00
2022-01-25 09:42:04 +00:00
# TODO - DepArp elevation or current elevation (on ground only!!) -> math.round(fmgc.flightPlanController.flightplans[2].departure.elevation * M2FT))
2020-12-31 20:03:47 +00:00
2022-01-25 12:30:35 +00:00
var doneMessageCheck = 0;
var perfToCheckTakeoffData = func(i) {
if (fmgc.FMGCInternal.v1set and fmgc.FMGCInternal.vrset and fmgc.FMGCInternal.v2set) {
if (doneMessageCheck) {
mcdu_scratchpad.messageQueues[i].deleteWithText("CHECK TAKE OFF DATA");
}
mcdu_scratchpad.messageQueues[i].addNewMsg(mcdu_scratchpad.MessageController.getTypeIIMsgByText("CHECK TAKE OFF DATA"));
doneMessageCheck = 1;
}
}
2020-12-31 20:03:47 +00:00
2022-01-25 09:42:04 +00:00
var doneMessageDisag = 0;
var perfTOCheckVSpeedsConsistency = func(i) {
2022-01-25 12:30:35 +00:00
if (fmgc.FMGCInternal.v1set and fmgc.FMGCInternal.vrset and fmgc.FMGCInternal.v2set) {
2022-01-25 09:42:04 +00:00
if (!(fmgc.FMGCInternal.v1 <= fmgc.FMGCInternal.vr and fmgc.FMGCInternal.vr <= fmgc.FMGCInternal.v2)) {
if (doneMessageDisag) {
mcdu_scratchpad.messageQueues[i].deleteWithText("V1/VR/V2 DISAGREE");
}
mcdu_scratchpad.messageQueues[i].addNewMsg(mcdu_scratchpad.MessageController.getTypeIIMsgByText("V1/VR/V2 DISAGREE"));
doneMessageDisag = 1;
}
}
}
var VMCA = props.globals.getNode("/FMGC/internal/vmca-kt");
var VMCG = props.globals.getNode("/FMGC/internal/vmcg-kt");
2020-12-31 20:03:47 +00:00
2022-01-25 12:30:35 +00:00
var chooseVS1G = func() {
if (fmgc.FMGCInternal.toFlap == 1) {
return fmgc.FMGCInternal.vs1g_conf_1f;
} elsif (fmgc.FMGCInternal.toFlap == 2) {
return fmgc.FMGCInternal.vs1g_conf_2;
} elsif (fmgc.FMGCInternal.toFlap == 3) {
return fmgc.FMGCInternal.vs1g_conf_3;
}
};
2020-12-31 20:03:47 +00:00
2022-01-25 09:42:04 +00:00
var doneMessageToLow = 0;
var perfTOCheckVSpeedsLimitations = func(i) {
2022-01-25 12:30:35 +00:00
if (fmgc.FMGCInternal.toFlapThsSet and fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet and fmgc.FMGCInternal.v1set and fmgc.FMGCInternal.vrset and fmgc.FMGCInternal.v2set) {
if (fmgc.FMGCInternal.v1 < VMCG.getValue() or fmgc.FMGCInternal.vr < (VMCA.getValue() * 1.05) or fmgc.FMGCInternal.v2 < (VMCA.getValue() * 1.10) or fmgc.FMGCInternal.v2 < (1.13 * chooseVS1G())) {
if (doneMessageToLow) {
mcdu_scratchpad.messageQueues[i].deleteWithText("T.O SPEEDS TOO LOW");
}
mcdu_scratchpad.messageQueues[i].addNewMsg(mcdu_scratchpad.MessageController.getTypeIIMsgByText("T.O SPEEDS TOO LOW"));
doneMessageToLow = 1;
2022-01-25 09:42:04 +00:00
}
2020-12-31 20:03:47 +00:00
}
}
2021-01-22 22:36:43 +00:00
var perfTOInput = func(key, i) {
2021-01-28 11:14:03 +00:00
var modifiable = (fmgc.FMGCInternal.phase == 1) ? 0 : 1;
2020-05-23 00:40:01 +00:00
var scratchpad = mcdu_scratchpad.scratchpads[i].scratchpad;
2020-12-31 20:03:47 +00:00
2021-01-22 22:36:43 +00:00
if (key == "L1" and modifiable) {
if (scratchpad == "CLR") {
fmgc.FMGCInternal.v1 = 0;
fmgc.FMGCInternal.v1set = 0;
fmgc.FMGCNodes.v1.setValue(0);
fmgc.FMGCNodes.v1set.setValue(0);
mcdu_scratchpad.scratchpads[i].empty();
} else {
var tfs = size(scratchpad);
if (tfs == 3) {
if (int(scratchpad) != nil and scratchpad >= 100 and scratchpad <= 350) {
fmgc.FMGCInternal.v1 = scratchpad;
fmgc.FMGCInternal.v1set = 1;
# for sounds:
fmgc.FMGCNodes.v1.setValue(scratchpad);
fmgc.FMGCNodes.v1set.setValue(1);
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 09:42:04 +00:00
perfTOCheckVSpeedsConsistency(i);
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
2021-01-22 22:36:43 +00:00
} else {
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "L2" and modifiable) {
if (scratchpad == "CLR") {
fmgc.FMGCInternal.vr = 0;
fmgc.FMGCInternal.vrset = 0;
mcdu_scratchpad.scratchpads[i].empty();
} else {
var tfs = size(scratchpad);
if (tfs == 3) {
if (int(scratchpad) != nil and scratchpad >= 100 and scratchpad <= 350) {
fmgc.FMGCInternal.vr = scratchpad;
fmgc.FMGCInternal.vrset = 1;
mcdu_scratchpad.scratchpads[i].empty();
2020-12-31 20:03:47 +00:00
2022-01-25 09:42:04 +00:00
perfTOCheckVSpeedsConsistency(i);
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
2021-01-22 22:36:43 +00:00
} else {
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "L3" and modifiable) {
if (scratchpad == "CLR") {
fmgc.FMGCInternal.v2 = 0;
fmgc.FMGCInternal.v2set = 0;
mcdu_scratchpad.scratchpads[i].empty();
} else {
var tfs = size(scratchpad);
if (tfs == 3) {
if (int(scratchpad) != nil and scratchpad >= 100 and scratchpad <= 350) {
fmgc.FMGCInternal.v2 = scratchpad;
fmgc.FMGCInternal.v2set = 1;
2022-01-10 16:26:31 +00:00
fmgc.setFmaText("pitchMode2Armed", fmgc.FMGCInternal.v2set ? "CLB" : " ", fmgc.genericCallback, "pitchMode2ArmedTime");
2021-01-22 22:36:43 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-12-31 20:03:47 +00:00
2022-01-25 09:42:04 +00:00
perfTOCheckVSpeedsConsistency(i);
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
2021-01-22 22:36:43 +00:00
} else {
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
} else if (key == "L4") {
if (scratchpad == "CLR") {
2020-05-16 14:48:26 +00:00
fmgc.FMGCInternal.transAlt = 18000;
fmgc.FMGCInternal.transAltSet = 0;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
var tfs = size(scratchpad);
2020-04-15 00:22:01 +00:00
if (int(scratchpad) != nil and (tfs == 4 or tfs <= 5) and scratchpad >= 1000 and scratchpad <= 39000) {
2020-05-16 14:48:26 +00:00
fmgc.FMGCInternal.transAlt = int(scratchpad / 10) * 10;
fmgc.FMGCInternal.transAltSet = 1;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "L5" and modifiable) {
2019-10-14 16:48:35 +00:00
if (scratchpad == "CLR") {
2021-04-22 21:44:17 +00:00
setprop("/fdm/jsbsim/fadec/clbreduc-ft", 1500);
2020-09-20 19:52:54 +00:00
setprop("/FMGC/internal/accel-agl-ft", 1500);
2020-02-07 16:10:54 +00:00
setprop("MCDUC/thracc-set", 0);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
var tfs = size(scratchpad);
2020-04-15 00:22:01 +00:00
if (find("/", scratchpad) != -1) {
2019-10-14 16:48:35 +00:00
var thracc = split("/", scratchpad);
2020-04-15 00:22:01 +00:00
var thrred = thracc[0];
var thrreds = size(thrred);
var acc = thracc[1];
var accs = size(acc);
2020-12-31 20:03:47 +00:00
#TODO - manual check - four digit alwway 0000 - default = runaway_elevation + 800 ft, min values runaway_elevation+400ft
2020-04-25 14:32:53 +00:00
if (int(thrred) != nil and (thrreds >= 3 and thrreds <= 5) and thrred >= 400 and thrred <= 39000 and int(acc) != nil and (accs == 3 or accs == 4 or accs == 5) and acc >= 400 and acc <= 39000) {
2020-12-31 20:03:47 +00:00
if (thrred<=acc) { # validation
2021-04-22 21:44:17 +00:00
setprop("/fdm/jsbsim/fadec/clbreduc-ft", int(thrred / 10) * 10);
2020-12-31 20:03:47 +00:00
setprop("/FMGC/internal/accel-agl-ft", int(acc / 10) * 10);
setprop("MCDUC/thracc-set", 1);
mcdu_scratchpad.scratchpads[i].empty();
} else {
mcdu_message(i, "NOT ALLOWED");
}
2020-04-25 14:32:53 +00:00
} else if (thrreds == 0 and int(acc) != nil and (accs >= 3 and accs <= 5) and acc >= 400 and acc <= 39000) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/accel-agl-ft", int(acc / 10) * 10);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
2020-04-25 14:32:53 +00:00
} else if (num(scratchpad) != nil and (tfs >= 3 and tfs <= 5) and scratchpad >= 400 and scratchpad <= 39000) {
2021-04-22 21:44:17 +00:00
setprop("/fdm/jsbsim/fadec/clbreduc-ft", int(scratchpad / 10) * 10);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "R3" and modifiable) {
2019-10-14 16:48:35 +00:00
if (scratchpad == "CLR") {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = 0;
fmgc.FMGCInternal.toThs = 0;
fmgc.FMGCInternal.toFlapThsSet = 0;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-04-15 00:22:01 +00:00
if (find("/", scratchpad) != -1) {
var flapths = split("/", scratchpad);
var flap = flapths[0];
var flaps = size(flap);
var trim = flapths[1];
var trims = size(trim);
var trima = substr(trim, 2);
var trimb = substr(trim, 0, 3);
2022-01-25 12:30:35 +00:00
2020-04-15 00:22:01 +00:00
var validtrima = num(trima) != nil and num(trima) >= 0 and num(trima) <= 7.0;
var validtrimb = num(trimb) != nil and num(trimb) >= 0 and num(trimb) <= 7.0;
2022-01-25 12:30:35 +00:00
if (flaps == 0 and fmgc.FMGCInternal.toFlapThsSet) {
2020-04-15 00:22:01 +00:00
if (trims == 5 and find("DN", trim) != -1 and validtrima) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toThs = -1 * trima;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
perfToCheckTakeoffData(i);
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("DN", trim) != -1 and validtrimb) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toThs = -1 * trimb;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
perfToCheckTakeoffData(i);
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("UP", trim) != -1 and validtrima) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toThs = trima;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
perfToCheckTakeoffData(i);
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("UP", trim) != -1 and validtrimb) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toThs = trimb;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
perfToCheckTakeoffData(i);
2020-04-15 00:22:01 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-04-15 00:22:01 +00:00
}
} else if (flaps == 1 and num(flap) != nil and flap >= 0 and flap <= 3) {
if (trims == 5 and find("DN", trim) != -1 and validtrima) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = flap;
fmgc.FMGCInternal.toThs = -1 * trima;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
if (fmgc.FMGCInternal.toFlapThsSet) {
perfToCheckTakeoffData(i);
}
fmgc.FMGCInternal.toFlapThsSet = 1;
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("DN", trim) != -1 and validtrimb) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = flap;
fmgc.FMGCInternal.toThs = -1 * trimb;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
if (fmgc.FMGCInternal.toFlapThsSet) {
perfToCheckTakeoffData(i);
}
fmgc.FMGCInternal.toFlapThsSet = 1;
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("UP", trim) != -1 and validtrima) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = flap;
fmgc.FMGCInternal.toThs = trima;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
if (fmgc.FMGCInternal.toFlapThsSet) {
perfToCheckTakeoffData(i);
}
fmgc.FMGCInternal.toFlapThsSet = 1;
2020-04-15 00:22:01 +00:00
} else if (trims == 5 and find("UP", trim) != -1 and validtrimb) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = flap;
fmgc.FMGCInternal.toThs = trimb;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
if (fmgc.FMGCInternal.toFlapThsSet) {
perfToCheckTakeoffData(i);
}
fmgc.FMGCInternal.toFlapThsSet = 1;
2020-04-15 00:22:01 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-04-15 00:22:01 +00:00
}
2020-03-30 01:27:18 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-30 01:27:18 +00:00
}
2020-04-15 00:22:01 +00:00
} else if (size(scratchpad) == 1 and num(scratchpad) != nil and scratchpad >= 0 and scratchpad <= 3) {
2022-01-25 12:30:35 +00:00
fmgc.FMGCInternal.toFlap = scratchpad;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
if (fmgc.FMGCInternal.toFlapThsSet) {
perfToCheckTakeoffData(i);
}
fmgc.FMGCInternal.toFlapThsSet = 1;
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "R4" and modifiable) {
2019-10-14 16:48:35 +00:00
if (scratchpad == "CLR") {
2021-04-22 21:44:17 +00:00
systems.FADEC.Limit.flexTemp.setValue(30);
systems.FADEC.Limit.flexActiveCmd.setBoolValue(0);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
var tfs = size(scratchpad);
if (tfs == 1 or tfs == 2) {
2020-04-15 00:22:01 +00:00
if (int(scratchpad) != nil and scratchpad >= 0 and scratchpad <= 99) {
2021-04-22 21:44:17 +00:00
systems.FADEC.Limit.flexTemp.setValue(scratchpad);
systems.FADEC.Limit.flexActiveCmd.setBoolValue(1);
2022-01-25 12:30:35 +00:00
perfTOCheckVSpeedsLimitations(i);
perfToCheckTakeoffData(i);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
2021-01-22 22:36:43 +00:00
} else if (key == "R5" and modifiable) {
2019-10-14 16:48:35 +00:00
if (scratchpad == "CLR") {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/eng-out-reduc", "1500");
2020-02-07 16:10:54 +00:00
setprop("MCDUC/reducacc-set", 0);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
var tfs = size(scratchpad);
2020-04-15 00:22:01 +00:00
if (int(scratchpad) != nil and (tfs == 4 or tfs == 5) and scratchpad >= 1000 and scratchpad <= 39000) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/eng-out-reduc", scratchpad);
2020-02-07 16:10:54 +00:00
setprop("MCDUC/reducacc-set", 1);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2019-10-14 16:48:35 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2019-10-14 16:48:35 +00:00
}
}
} else if (key == "R6") {
2020-03-30 03:39:31 +00:00
setprop("MCDU[" ~ i ~ "]/page", "PERFCLB");
2021-01-22 22:36:43 +00:00
} else {
mcdu_message(i, "NOT ALLOWED");
}
2019-10-14 16:48:35 +00:00
}