1
0
Fork 0
A320-family/Nasal/MCDU/INITB.nas

70 lines
2.4 KiB
Text
Raw Normal View History

2019-10-14 16:48:35 +00:00
# A3XX mCDU by Joshua Davidson (Octal450) and Jonathan Redpath
# Copyright (c) 2019 Joshua Davidson (Octal450)
var initInputB = func(key, i) {
2020-02-07 16:10:54 +00:00
var scratchpad = getprop("MCDU[" ~ i ~ "]/scratchpad");
2019-10-14 16:48:35 +00:00
if (key == "R1") {
if (scratchpad == "CLR") {
notAllowed(i);
} else {
var tfs = size(scratchpad);
if (tfs == 0) {
2020-02-07 16:10:54 +00:00
var zfw = getprop("fdm/jsbsim/inertia/weight-lbs") - getprop("consumables/fuel/total-fuel-lbs");
setprop("MCDU[" ~ i ~ "]/scratchpad", "/" ~ sprintf("%3.1f", math.round(zfw / 1000, 0.1)));
2019-10-14 16:48:35 +00:00
} else if (tfs >= 2 and tfs <= 11 and find("/", scratchpad) != -1) {
var zfwi = split("/", scratchpad);
var zfwcg = size(zfwi[0]);
var zfw = size(zfwi[1]);
if (zfwcg >= 1 and zfwcg <= 5 and zfwi[0] > 0 and zfwi[0] <= 99.9) {
2020-02-07 16:10:54 +00:00
setprop("FMGC/internal/zfwcg", zfwi[0]);
setprop("FMGC/internal/zfwcg-set", 1);
2019-10-14 16:48:35 +00:00
}
if (zfw >= 1 and zfw <= 5 and zfwi[1] > 0 and zfwi[1] <= 999.9) {
2020-02-07 16:10:54 +00:00
setprop("FMGC/internal/zfw", zfwi[1]);
setprop("FMGC/internal/zfw-set", 1);
2019-10-14 16:48:35 +00:00
}
if ((zfwcg >= 1 and zfwcg <= 5 and zfwi[0] > 0 and zfwi[0] <= 99.9) or (zfw >= 1 and zfw <= 5 and zfwi[1] > 0 and zfwi[1] <= 999.9)) {
2020-02-07 16:10:54 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
2019-10-14 16:48:35 +00:00
} else {
notAllowed(i);
}
} else if (tfs >= 1 and tfs <= 5) {
var zfwcg = size(scratchpad);
if (zfwcg >= 1 and zfwcg <= 5 and scratchpad > 0 and scratchpad <= 99.9) {
2020-02-07 16:10:54 +00:00
setprop("FMGC/internal/zfwcg", scratchpad);
setprop("FMGC/internal/zfwcg-set", 1);
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
2019-10-14 16:48:35 +00:00
} else {
notAllowed(i);
}
} else {
notAllowed(i);
}
}
} else if (key == "R2") {
if (scratchpad == "CLR") {
2020-02-07 16:10:54 +00:00
setprop("FMGC/internal/block", 0.0);
setprop("FMGC/internal/block-set", 0);
setprop("MCDU[" ~ i ~ "]/scratchpad-msg", 0);
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
2019-10-14 16:48:35 +00:00
} else {
var tfs = size(scratchpad);
2020-02-07 16:10:54 +00:00
var maxblock = getprop("options/maxblock");
2019-10-14 16:48:35 +00:00
if (tfs == 0) {
2020-02-07 16:10:54 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad", sprintf("%3.1f", math.round(getprop("consumables/fuel/total-fuel-lbs") / 1000, 0.1)));
2019-10-14 16:48:35 +00:00
} else if (tfs >= 1 and tfs <= 5) {
if (scratchpad >= 1.0 and scratchpad <= maxblock) {
2020-02-07 16:10:54 +00:00
setprop("FMGC/internal/block", scratchpad);
setprop("FMGC/internal/block-set", 1);
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
2019-10-14 16:48:35 +00:00
} else {
notAllowed(i);
}
} else {
notAllowed(i);
}
}
}
}