This repository has been archived on 2021-09-26. You can view files and clone it, but cannot push or open issues or pull requests.
IDG-A32X/Nasal/MCDU1.nas
Jonathan Redpath d90ee47d75 MCDU
2017-05-26 17:42:19 +01:00

448 lines
14 KiB
Text

##################################################################
# A3XX mCDU by Joshua Davidson (it0uchpods) and Jonathan Redpath #
##################################################################
var MCDU_init = func {
setprop("/MCDU[0]/brightness", "1.0");
MCDU_reset(); # Reset MCDU, clears data
}
var MCDU_reset = func {
setprop("/MCDU[0]/page", "STATUS");
setprop("/MCDU[0]/scratchpad", "");
setprop("/MCDUC/flight-num", "");
setprop("/MCDUC/flight-num-set", 0);
setprop("/MCDUC/thracc-set", 0);
setprop("/FMGC/internal/dep-arpt", "");
setprop("/FMGC/internal/arr-arpt", "");
setprop("/FMGC/internal/tofrom-set", 0);
setprop("/FMGC/internal/cruise-ft", 10000);
setprop("/FMGC/internal/cruise-fl", 100);
setprop("/FMGC/internal/cost-index", "0");
setprop("/FMGC/internal/cost-index-set", 0);
setprop("/FMGC/internal/cruise-lvl-set", 0);
}
var lskbutton = func(btn) {
if (btn == "2") {
if (getprop("/MCDU[0]/page") == "INITA") {
PerfInput("L2");
}
} else if (btn == "3") {
if (getprop("/MCDU[0]/page") == "INITA") {
initInputA("L3");
}
} else if (btn == "4") {
if (getprop("/MCDU[0]/page") == "DATA") {
setprop("/MCDU[0]/page", "STATUS");
}
} else if (btn == "5") {
if (getprop("/MCDU[0]/page") == "INITA") {
initInputA("L5");
} else if (getprop("/MCDU[0]/page") == "TO") {
PerfTOInput("L5");
} else if (getprop("/MCDU[0]/page") == "CLB") {
perfCLBInput("L5");
}
} else if (btn == "6") {
if (getprop("/MCDU[0]/page") == "INITA") {
initInputA("L6");
} else if (getprop("/MCDU[0]/page") == "CLB") {
perfCLBInput("L6");
} else if (getprop("/MCDU[0]/page") == "CRZ") {
perfCRZInput("L6");
}
}
}
var rskbutton = func(btn) {
if (btn == "1") {
if (getprop("/MCDU[0]/page") == "INITA") {
initInputA("R1");
}
} else if (btn == "3") {
if (getprop("/MCDU[0]/page") == "INITA") {
initInputA("R3");
}
} else if (btn == "6") {
if (getprop("/MCDU[0]/page") == "TO") {
PerfTOInput("R6");
} else if (getprop("/MCDU[0]/page") == "CLB") {
perfCLBInput("R6");
} # else if (getprop("/MCDU[0]/page") == "CRZ") {
# perfCRZInput("R6");
#}
}
}
var initInputA = func(key) {
var scratchpad = getprop("/MCDU[0]/scratchpad");
if (key == "L3") {
if (scratchpad == "CLR") {
setprop("/MCDUC/flight-num", "");
setprop("/MCDUC/flight-num-set", 0);
setprop("/MCDU[0]/scratchpad", "");
} else {
var flts = size(scratchpad);
if (flts >= 1 and flts <= 8) {
setprop("/MCDUC/flight-num", scratchpad);
setprop("/MCDUC/flight-num-set", 1);
setprop("/MCDU[0]/scratchpad", "");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "L5") {
if (scratchpad == "CLR") {
setprop("/FMGC/internal/cost-index", 0);
setprop("/FMGC/internal/cost-index-set", 0);
setprop("/MCDU[0]/scratchpad", "");
} else {
var ci = int(scratchpad);
var cis = size(scratchpad);
if (cis >= 1 and cis <= 3) {
if (ci == nil) {
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
} else if (ci >= 0 and ci <= 120) {
setprop("/FMGC/internal/cost-index", ci);
setprop("/FMGC/internal/cost-index-set", 1);
setprop("/MCDU[0]/scratchpad", "");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "L6") {
if (scratchpad == "CLR") {
setprop("/FMGC/internal/cruise-ft", 10000);
setprop("/FMGC/internal/cruise-fl", 100);
setprop("/FMGC/internal/cruise-lvl-set", 0);
setprop("/MCDU[0]/scratchpad", "");
} else {
var crz = int(scratchpad);
var crzs = size(scratchpad);
if (crzs >= 1 and crzs <= 3) {
if (crz == nil) {
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
} else if (crz > 0 and crz <= 430) {
setprop("/FMGC/internal/cruise-ft", crz * 100);
setprop("/FMGC/internal/cruise-fl", crz);
setprop("/FMGC/internal/cruise-lvl-set", 1);
setprop("/MCDU[0]/scratchpad", "");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "R1") {
if (scratchpad == "CLR") {
setprop("/FMGC/internal/dep-arpt", "");
setprop("/FMGC/internal/arr-arpt", "");
setprop("/FMGC/internal/tofrom-set", 0);
fmgc.updateARPT();
setprop("/MCDU[0]/scratchpad", "");
} else {
var tfs = size(scratchpad);
if (tfs == 9) {
var fromto = split("/", scratchpad);
var froms = size(fromto[0]);
var tos = size(fromto[1]);
if (froms == 4 and tos == 4) {
setprop("/FMGC/internal/dep-arpt", fromto[0]);
setprop("/FMGC/internal/arr-arpt", fromto[1]);
setprop("/FMGC/internal/tofrom-set", 1);
fmgc.updateARPT();
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "GPS PRIMARY");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "R3") {
if (getprop("/controls/adirs/mcducbtn") == 0) {
setprop("/controls/adirs/mcducbtn", 1);
}
}
}
var PerfTOInput = func(key) {
var scratchpad = getprop("/MCDU[0]/scratchpad");
if (key == "L5") {
if (scratchpad == "CLR") {
setprop("/systems/thrust/clbreduc-ft", "1500");
setprop("/it-autoflight/settings/reduc-agl-ft", "3000");
setprop("/MCDUC/thracc-set", 0);
setprop("/MCDU[0]/scratchpad", "");
} else {
var tfs = size(scratchpad);
if (tfs == 9) {
var thracc = split("/", scratchpad);
var thrred = size(thracc[0]);
var acc = size(thracc[1]);
if ((thrred >= 1 and thrred <= 4) and (acc >= 1 and acc <= 4)) {
setprop("/systems/thrust/clbreduc-ft", thracc[0]);
setprop("/it-autoflight/settings/reduc-agl-ft", thracc[1]);
setprop("/MCDUC/thracc-set", 1);
setprop("/MCDU[0]/scratchpad", "");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "R6") {
setprop("/MCDU[0]/page", "CLB");
}
}
var perfCLBInput = func(key) {
var scratchpad = getprop("/MCDU[0]/scratchpad");
if (key == "L5") {
if (scratchpad == "CLR") {
setprop("/FMGC/internal/cost-index", 0);
setprop("/FMGC/internal/cost-index-set", 0);
setprop("/MCDU[0]/scratchpad", "");
} else {
var ci = int(scratchpad);
var cis = size(scratchpad);
if (cis >= 1 and cis <= 3) {
if (ci == nil) {
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
} else if (ci >= 0 and ci <= 120) {
setprop("/FMGC/internal/cost-index", ci);
setprop("/FMGC/internal/cost-index-set", 1);
setprop("/MCDU[0]/scratchpad", "");
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
} else {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "NOT ALLOWED");
}
}
} else if (key == "L6") {
setprop("/MCDU[0]/page", "TO");
} else if (key == "R6") {
setprop("/MCDU[0]/page", "CRZ");
}
}
var perfCRZInput = func(key) {
if (key == "L6") {
setprop("/MCDU[0]/page", "CLB");
}
# if (key == "R6") {
# setprop("/MCDU[0]/page", "DES");
# }
}
var arrowbutton = func(btn) {
if (btn == "left") {
if (getprop("/MCDU[0]/page") == "DATA") {
setprop("/MCDU[0]/page", "DATA2");
} else if (getprop("/MCDU[0]/page") == "DATA2") {
setprop("/MCDU[0]/page", "DATA");
}
if (getprop("/MCDU[0]/page") == "INITA") {
setprop("/MCDU[0]/page", "INITB");
} else if (getprop("/MCDU[0]/page") == "INITB") {
setprop("/MCDU[0]/page", "INITA");
}
} else if (btn == "right") {
if (getprop("/MCDU[0]/page") == "DATA") {
setprop("/MCDU[0]/page", "DATA2");
} else if (getprop("/MCDU[0]/page") == "DATA2") {
setprop("/MCDU[0]/page", "DATA");
}
if (getprop("/MCDU[0]/page") == "INITA") {
setprop("/MCDU[0]/page", "INITB");
} else if (getprop("/MCDU[0]/page") == "INITB") {
setprop("/MCDU[0]/page", "INITA");
}
} else if (btn == "up") {
# Nothing for now
} else if (btn == "down") {
# Nothing for now
}
}
var pagebutton = func(btn) {
if (btn == "perf") {
if (getprop("/FMGC/status/phase") == 0 or getprop("/FMGC/status/phase") == 1) {
setprop("/MCDU[0]/page", "TO");
} else if (getprop("/FMGC/status/phase") == 2) {
setprop("/MCDU[0]/page", "CLB");
} else if (getprop("/FMGC/status/phase") == 3) {
setprop("/MCDU[0]/page", "CRZ");
}
} else if (btn == "init") {
setprop("/MCDU[0]/page", "INITA");
} else if (btn == "data") {
setprop("/MCDU[0]/page", "DATA");
} else if (btn == "mcdu") {
setprop("/MCDU[0]/page", "MCDU");
}
}
var button = func(btn) {
var scratchpad = getprop("/MCDU[0]/scratchpad");
if (btn == "A") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "A");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "B") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "B");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "C") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "C");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "D") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "D");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "E") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "E");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "F") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "F");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "G") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "G");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "H") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "H");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "I") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "I");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "J") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "J");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "K") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "K");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "L") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "L");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "M") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "M");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "N") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "N");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "O") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "O");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "P") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "P");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "Q") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "Q");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "R") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "R");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "S") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "S");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "T") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "T");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "U") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "U");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "V") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "V");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "W") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "W");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "X") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "X");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "Y") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "Y");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "Z") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "Z");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "SLASH") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "/");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "SP") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ " ");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "CLR") {
var scratchpad = getprop("/MCDU[0]/scratchpad");
if (size(scratchpad) == 0) {
setprop("/MCDU[0]/scratchpad-msg", "1");
setprop("/MCDU[0]/scratchpad", "CLR");
} else if (getprop("/MCDU[0]/scratchpad-msg") == 1) {
setprop("/MCDU[0]/scratchpad", "");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (size(scratchpad) > 0) {
setprop("/MCDU[0]/scratchpad", left(scratchpad, size(scratchpad)-1));
setprop("/MCDU[0]/scratchpad-msg", "0");
}
} else if (btn == "0") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "0");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "1") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "1");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "2") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "2");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "3") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "3");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "4") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "4");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "5") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "5");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "6") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "6");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "7") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "7");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "8") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "8");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "9") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "9");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "DOT") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ ".");
setprop("/MCDU[0]/scratchpad-msg", "0");
} else if (btn == "PLUSMINUS") {
setprop("/MCDU[0]/scratchpad", scratchpad ~ "-");
setprop("/MCDU[0]/scratchpad-msg", "0");
}
}
var screenFlash = func(time) {
var page = getprop("/MCDU[0]/page");
setprop("/MCDU[0]/page", "NONE");
settimer(func {
setprop("/MCDU[0]/page", page);
}, time);
}