2020-04-30 19:26:36 +00:00
# Copyright (c) 2020 Matthew Maring (mattmaring)
2020-02-24 20:54:10 +00:00
2020-03-24 00:14:12 +00:00
# APPR PERF
2020-04-20 22:14:32 +00:00
var ldg_config_3_set = props.globals.getNode("/FMGC/internal/ldg-config-3-set", 1);
var ldg_config_f_set = props.globals.getNode("/FMGC/internal/ldg-config-f-set", 1);
2020-03-24 00:14:12 +00:00
2020-02-24 20:54:10 +00:00
var perfAPPRInput = func(key, i) {
2020-05-23 00:40:01 +00:00
var scratchpad = mcdu_scratchpad.scratchpads[i].scratchpad;
2020-03-24 00:14:12 +00:00
if (key == "L1") {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-qnh", -1);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-15 23:31:05 +00:00
} else if (num(scratchpad) != nil and (scratchpad >= 28.06 and scratchpad <= 31.01) or (scratchpad >= 745 and scratchpad <= 1050)) {
2020-03-28 20:40:02 +00:00
# doesn't support accidental temp input yet
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-qnh", scratchpad);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-03-28 20:40:02 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "L2") {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-temp", -999);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-15 23:31:05 +00:00
} else if (num(scratchpad) != nil and scratchpad >= -99 and scratchpad < 99) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-temp", scratchpad);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-03-28 20:40:02 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "L3") {
2020-03-28 20:40:02 +00:00
var tfs = size(scratchpad);
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-mag", -1);
setprop("/FMGC/internal/dest-wind", -1);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-03-28 20:40:02 +00:00
} else if (tfs >= 3 and tfs <= 7 and find("/", scratchpad) != -1) {
var weather = split("/", scratchpad);
2020-03-30 01:27:18 +00:00
var mags = size(weather[0]);
var winds = size(weather[1]);
if (mags >= 1 and mags <= 3 and winds >= 1 and winds <= 3) {
2020-06-14 17:30:58 +00:00
if (num(weather[0]) != nil and num(weather[1]) != nil and int(weather[0]) >= 0 and int(weather[0]) <= 360 and int(weather[1]) >= 0 and int(weather[1]) <= 200) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/dest-mag", weather[0]);
setprop("/FMGC/internal/dest-wind", weather[1]);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-03-30 01:27:18 +00:00
fmgc.updateARPT();
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-30 01:27:18 +00:00
}
2020-03-28 20:40:02 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "L4") {
2020-03-28 20:40:02 +00:00
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();
2020-03-28 20:40:02 +00:00
} else {
2020-05-16 14:48:26 +00:00
var tfs = size(scratchpad);
if (int(scratchpad) != nil and (tfs == 4 or tfs == 5) and scratchpad >= 1000 and scratchpad <= 39000) {
fmgc.FMGCInternal.transAlt = math.round(scratchpad, 500);
fmgc.FMGCInternal.transAltSet = 1;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-05-16 14:48:26 +00:00
} elsif (int(scratchpad) != nil and (tfs == 2 or tfs == 3) and scratchpad >= 10 and scratchpad <= 390) {
fmgc.FMGCInternal.transAlt = math.round(scratchpad * 100, 5);
fmgc.FMGCInternal.transAltSet = 1;
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-05-16 14:48:26 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-05-16 14:48:26 +00:00
}
2020-03-28 20:40:02 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "L5") {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/vapp-speed-set", 0);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-05-21 20:24:19 +00:00
} else if (int(scratchpad) != nil and scratchpad >= 100 and scratchpad <= 350) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/vapp-speed-set", 1);
setprop("/FMGC/internal/computed-speeds/vapp_appr", scratchpad);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-03-28 20:40:02 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "L6") {
2020-04-20 22:14:32 +00:00
setprop("/MCDU[" ~ i ~ "]/page", "PERFDES");
2020-04-18 13:59:05 +00:00
} else if (key == "R2") {
2020-04-20 02:08:42 +00:00
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/baro", 99999);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-20 22:14:32 +00:00
} else if (int(scratchpad) != nil and scratchpad >= getprop("/FMGC/internal/ldg-elev") and scratchpad <= 5000 + getprop("/FMGC/internal/ldg-elev")) {
if (getprop("/FMGC/internal/radio-no") == 0) {
setprop("/FMGC/internal/radio", 99999);
2020-04-18 13:59:05 +00:00
}
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/baro", scratchpad);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-18 13:59:05 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-04-18 13:59:05 +00:00
}
} else if (key == "R3") {
2020-04-20 02:08:42 +00:00
if (scratchpad == "CLR") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/radio", 99999);
setprop("/FMGC/internal/radio-no", 0);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-20 02:08:42 +00:00
} else if (scratchpad == "NO") {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/radio", 99999);
setprop("/FMGC/internal/radio-no", 1);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-18 13:59:05 +00:00
} else if (int(scratchpad) != nil and scratchpad >= 0 and scratchpad <= 700) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/baro", 99999);
setprop("/FMGC/internal/radio-no", 0);
setprop("/FMGC/internal/radio", scratchpad);
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[i].empty();
2020-04-18 13:59:05 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-04-18 13:59:05 +00:00
}
2020-04-19 01:22:36 +00:00
} else if (key == "R4") {
if (scratchpad == "" and ldg_config_f_set.getValue() == 1 and ldg_config_3_set.getValue() == 0) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/ldg-config-3-set", 1);
setprop("/FMGC/internal/ldg-config-f-set", 0);
2020-04-19 01:22:36 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-04-19 01:22:36 +00:00
}
2020-03-24 00:14:12 +00:00
} else if (key == "R5") {
2020-03-28 20:40:02 +00:00
if (scratchpad == "" and ldg_config_3_set.getValue() == 1 and ldg_config_f_set.getValue() == 0) {
2020-04-20 22:14:32 +00:00
setprop("/FMGC/internal/ldg-config-3-set", 0);
setprop("/FMGC/internal/ldg-config-f-set", 1);
2020-03-28 20:40:02 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(i, "NOT ALLOWED");
2020-03-28 20:40:02 +00:00
}
2020-03-22 13:03:02 +00:00
} else if (key == "R6") {
2020-04-20 22:14:32 +00:00
setprop("/MCDU[" ~ i ~ "]/page", "PERFGA");
2020-02-24 20:54:10 +00:00
}
2020-03-24 00:14:12 +00:00
2020-03-22 13:03:02 +00:00
}