From 6f0114457d0d1866b1ff1eb2bb7f8d62c280ea17 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 19 Sep 2020 14:43:44 +0100 Subject: [PATCH] Accept MCDU input in KG --- AircraftConfig/main.xml | 4 ++-- Models/Instruments/MCDU/MCDU.nas | 2 +- Nasal/MCDU/FUELPRED.nas | 21 +++++++++++++++++++ Nasal/MCDU/INITB.nas | 35 ++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/AircraftConfig/main.xml b/AircraftConfig/main.xml index d7edd304..c97e3d27 100644 --- a/AircraftConfig/main.xml +++ b/AircraftConfig/main.xml @@ -243,7 +243,7 @@ - + diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 353397db..0b15f0ff 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -159,7 +159,7 @@ var active = [props.globals.getNode("/MCDU[0]/active", 1), props.globals.getNode var activeAtsu = [props.globals.getNode("/MCDU[0]/atsu-active", 1), props.globals.getNode("/MCDU[1]/atsu-active", 1)]; # Conversion factor pounds to kilogram -LBS2KGS = 0.4535924; +var LBS2KGS = 0.4535924; # Create Nodes: diff --git a/Nasal/MCDU/FUELPRED.nas b/Nasal/MCDU/FUELPRED.nas index 59646a87..a899e351 100644 --- a/Nasal/MCDU/FUELPRED.nas +++ b/Nasal/MCDU/FUELPRED.nas @@ -15,6 +15,9 @@ var fuelPredInput = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (fmgc.FMGCInternal.tripFuel != 0) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 2 and tfs <= 5 and find("/", scratchpad) == 0) { var perc = num(split("/", scratchpad)[1]); @@ -52,6 +55,9 @@ var fuelPredInput = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) { fmgc.FMGCInternal.altFuel = tf; @@ -75,6 +81,9 @@ var fuelPredInput = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) { fmgc.FMGCInternal.finalFuel = tf; @@ -86,6 +95,9 @@ var fuelPredInput = func(key, i) { } } else { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs == 4 and tf != nil and ((tf >= 0 and tf <= 59) or (tf >= 100 and tf <= 130))) { fmgc.FMGCInternal.finalTime = scratchpad; @@ -104,6 +116,9 @@ var fuelPredInput = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 5 and tf != nil and tf >= 0 and tf <= 80.0) { fmgc.FMGCInternal.minDestFob = tf; @@ -142,6 +157,9 @@ var fuelPredInput = func(key, i) { } mcdu_scratchpad.scratchpads[i].empty(); } else if (find("/", scratchpad) != -1) { + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } var zfwi = split("/", scratchpad); var zfw = num(zfwi[0]); var zfwcg = num(zfwi[1]); @@ -180,6 +198,9 @@ var fuelPredInput = func(key, i) { mcdu_message(i, "NOT ALLOWED"); } } else if (num(scratchpad) != nil and size(scratchpad) > 0 and size(scratchpad) <= 5 and (find(".", scratchpad) == -1 or size(split(".", scratchpad)[1]) <= 1)) { + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } if (scratchpad >= zfw_min and scratchpad <= zfw_max) { fmgc.FMGCInternal.zfw = scratchpad; fmgc.FMGCInternal.zfwSet = 1; diff --git a/Nasal/MCDU/INITB.nas b/Nasal/MCDU/INITB.nas index 1694d1f4..2fc500c8 100644 --- a/Nasal/MCDU/INITB.nas +++ b/Nasal/MCDU/INITB.nas @@ -2,6 +2,10 @@ # Copyright (c) 2020 Matthew Maring (mattmaring) +var acconfig_weight_kgs = props.globals.getNode("/systems/acconfig/options/weight-kgs", 1); +# Conversion factor pounds to kilogram +var LBS2KGS = 0.4535924; + var initInputB = func(key, i) { var scratchpad = mcdu_scratchpad.scratchpads[i].scratchpad; if (key == "L1" and !getprop("/FMGC/internal/fuel-calculating")) { @@ -14,8 +18,11 @@ var initInputB = func(key, i) { setprop("/FMGC/internal/block-calculating", 1); } mcdu_scratchpad.scratchpads[i].empty(); - } else { + } else { var tfs = size(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } if (tfs >= 1 and tfs <= 4) { if (num(scratchpad) != nil and scratchpad >= 0.0 and scratchpad <= 9.9) { fmgc.FMGCInternal.taxiFuel = scratchpad; @@ -43,6 +50,9 @@ var initInputB = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (fmgc.FMGCInternal.tripFuel != 0) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 2 and tfs <= 5 and find("/", scratchpad) == 0) { var perc = num(split("/", scratchpad)[1]); @@ -80,6 +90,9 @@ var initInputB = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) { fmgc.FMGCInternal.altFuel = tf; @@ -103,6 +116,9 @@ var initInputB = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) { fmgc.FMGCInternal.finalFuel = tf; @@ -132,6 +148,9 @@ var initInputB = func(key, i) { mcdu_scratchpad.scratchpads[i].empty(); } else if (find(".", scratchpad) != -1) { var tf = num(scratchpad); + if (acconfig_weight_kgs.getValue() == 1) { + tf = tf / LBS2KGS; + } var tfs = size(scratchpad); if (tfs >= 3 and tfs <= 5 and tf != nil and tf >= 0 and tf <= 80.0) { fmgc.FMGCInternal.minDestFob = tf; @@ -153,6 +172,7 @@ var initInputB = func(key, i) { } else { var zfw_min = 80.6; #make based on performance var zfw_max = 134.5; #61,000 kg, make based on performance + if (size(scratchpad) == 0) { var zfw = getprop("/fdm/jsbsim/inertia/weight-lbs") - getprop("/consumables/fuel/total-fuel-lbs"); fmgc.FMGCInternal.zfw = sprintf("%3.1f", math.round(zfw / 1000, 0.1)); @@ -170,6 +190,9 @@ var initInputB = func(key, i) { } mcdu_scratchpad.scratchpads[i].empty(); } else if (find("/", scratchpad) != -1) { + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } var zfwi = split("/", scratchpad); var zfw = num(zfwi[0]); var zfwcg = num(zfwi[1]); @@ -208,6 +231,9 @@ var initInputB = func(key, i) { mcdu_message(i, "NOT ALLOWED"); } } else if (num(scratchpad) != nil and size(scratchpad) > 0 and size(scratchpad) <= 5 and (find(".", scratchpad) == -1 or size(split(".", scratchpad)[1]) <= 1)) { + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } if (scratchpad >= zfw_min and scratchpad <= zfw_max) { fmgc.FMGCInternal.zfw = scratchpad; fmgc.FMGCInternal.zfwSet = 1; @@ -274,7 +300,8 @@ var initInputB = func(key, i) { var tfs = size(scratchpad); var maxblock = getprop("/options/maxblock"); if (tfs == 0) { - fmgc.FMGCInternal.block = sprintf("%3.1f", math.round(getprop("/consumables/fuel/total-fuel-lbs") / 1000, 0.1)); + var block = math.round(getprop("/consumables/fuel/total-fuel-lbs") / 1000, 0.1); + fmgc.FMGCInternal.block = sprintf("%3.1f", block); fmgc.FMGCInternal.blockSet = 1; if (fmgc.FMGCInternal.zfwSet) { fmgc.FMGCInternal.tow = num(fmgc.FMGCInternal.zfw + fmgc.FMGCInternal.block - fmgc.FMGCInternal.taxiFuel); @@ -284,6 +311,10 @@ var initInputB = func(key, i) { setprop("/FMGC/internal/block-confirmed", 1); } } else if (tfs >= 1 and tfs <= 5) { + if (acconfig_weight_kgs.getValue() == 1) { + scratchpad = scratchpad / LBS2KGS; + } + if (num(scratchpad) != nil and scratchpad >= 1.0 and scratchpad <= maxblock) { fmgc.FMGCInternal.block = scratchpad; fmgc.FMGCInternal.blockSet = 1;