From 0933ca4f4751110c10a02beed37cea233bf74129 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Fri, 4 Sep 2020 20:56:22 +0100 Subject: [PATCH 1/4] Allow MCDU display in KGS --- Models/Instruments/MCDU/MCDU.nas | 158 +++++++++++++++++++++++++------ 1 file changed, 130 insertions(+), 28 deletions(-) diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 08ace4a8..353397db 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -72,6 +72,7 @@ var MAGENTA = [0.6902,0.3333,0.7541]; # Fetch nodes: var mcdu_keyboard_left = props.globals.getNode("/FMGC/keyboard-left", 0); var mcdu_keyboard_right = props.globals.getNode("/FMGC/keyboard-right", 0); +var acconfig_weight_kgs = props.globals.getNode("/systems/acconfig/options/weight-kgs", 1); #ACCONFIG var mcdu1_lgt = props.globals.getNode("/controls/lighting/DU/mcdu1", 1); @@ -157,6 +158,10 @@ var pageProp = [props.globals.getNode("/MCDU[0]/page", 1), props.globals.getNode var active = [props.globals.getNode("/MCDU[0]/active", 1), props.globals.getNode("/MCDU[1]/active", 1)]; 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; + + # Create Nodes: var pageSwitch = [props.globals.initNode("/MCDU[0]/internal/switch", 0, "BOOL"), props.globals.initNode("/MCDU[1]/internal/switch", 0, "BOOL")]; @@ -1454,7 +1459,7 @@ var canvas_MCDU_base = { me["Simple_L5"].setText("[ ]"); - me["Simple_L6"].setText("+4.0/+0.0"); + me["Simple_L6"].setText("+0.0/+1.0"); me["Simple_L1S"].setText(" ENG"); me["Simple_L2S"].setText(" ACTIVE NAV DATA BASE"); me["Simple_L3S"].setText(" SECOND NAV DATA BASE"); @@ -2252,7 +2257,11 @@ var canvas_MCDU_base = { } me["Simple_L1S"].setText("TAXI"); - me["Simple_L1"].setText(sprintf("%2.1f", fmgc.FMGCInternal.taxiFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L1"].setText(sprintf("%2.1f", fmgc.FMGCInternal.taxiFuel * LBS2KGS)); + } else { + me["Simple_L1"].setText(sprintf("%2.1f", fmgc.FMGCInternal.taxiFuel)); + } me["Simple_L2S"].setText("TRIP/TIME"); me["Simple_L3S"].setText("RTE RSV/PCT"); me["Simple_L4S"].setText("ALTN/TIME"); @@ -2278,7 +2287,11 @@ var canvas_MCDU_base = { if (fmgc.FMGCInternal.blockSet) { me["Simple_R2"].show(); me["INITB_Block"].hide(); - me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block * LBS2KGS)); + } else { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + } } else { me["Simple_R2"].hide(); me["INITB_Block"].show(); @@ -2346,7 +2359,11 @@ var canvas_MCDU_base = { me["Simple_L6"].setText("---.-"); me["Simple_R2"].show(); me["INITB_Block"].hide(); - me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block * LBS2KGS)); + } else { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + } me["Simple_R3S"].show(); me["Simple_R3"].show(); me["Simple_R3S"].setText("BLOCK"); @@ -2355,9 +2372,17 @@ var canvas_MCDU_base = { me["Simple_R3_Arrow"].setColor(AMBER); me["Simple_C4B"].show(); if (num(fmgc.FMGCInternal.tow) >= 100.0) { - me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow * LBS2KGS)); + } else { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + } } else { - me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow * LBS2KGS)); + } else { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + } } me["Simple_R4"].setText("---.-"); me["Simple_R6"].setText("---.-/----"); @@ -2391,15 +2416,27 @@ var canvas_MCDU_base = { me["Simple_L6"].setText("---.-"); me["Simple_R2"].show(); me["INITB_Block"].hide(); - me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block * LBS2KGS)); + } else { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + } me["Simple_R3S"].hide(); me["Simple_R3"].hide(); me["Simple_R3_Arrow"].hide(); me["Simple_C4B"].show(); if (num(fmgc.FMGCInternal.tow) >= 100.0) { - me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow * LBS2KGS)); + } else { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + } } else { - me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow * LBS2KGS)); + } else { + me["Simple_C4B"].setText(sprintf(" %4.1f/", fmgc.FMGCInternal.tow)); + } } me["Simple_R4"].setText("---.-"); me["Simple_R6"].setText("---.-/----"); @@ -2407,8 +2444,16 @@ var canvas_MCDU_base = { me.colorLeft("ack", "wht", "wht", "wht", "wht", "wht"); me.colorRight("ack", "blu", "ack", "wht", "ack", "wht"); } else { - me["Simple_L2"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.tripTime, fmgc.FMGCInternal.tripFuel)); - me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L2"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.tripTime, fmgc.FMGCInternal.tripFuel * LBS2KGS)); + } else { + me["Simple_L2"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.tripTime, fmgc.FMGCInternal.tripFuel)); + } + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv * LBS2KGS)); + } else { + me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv)); + } if (fmgc.FMGCInternal.rteRsvSet) { if (num(fmgc.FMGCInternal.rteRsv) > 9.9 and num(fmgc.FMGCInternal.rtePercent) > 9.9) { me["Simple_C3"].setText(sprintf("/%.1f ", fmgc.FMGCInternal.rtePercent)); @@ -2441,7 +2486,11 @@ var canvas_MCDU_base = { } } if (fmgc.FMGCInternal.altAirportSet) { - me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel * LBS2KGS)); + } else { + me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel)); + } me["Simple_L4"].setColor(BLUE); me["Simple_C4"].show(); if (fmgc.FMGCInternal.altFuelSet) { @@ -2462,7 +2511,11 @@ var canvas_MCDU_base = { me["Simple_L4"].setColor(WHITE); me["Simple_C4"].hide(); } - me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel * LBS2KGS)); + } else { + me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel)); + } if (fmgc.FMGCInternal.finalTimeSet and fmgc.FMGCInternal.finalFuelSet) { if (num(fmgc.FMGCInternal.finalFuel) > 9.9) { me["Simple_C5"].setText(sprintf("/%s ", fmgc.FMGCInternal.finalTime)); @@ -2488,16 +2541,30 @@ var canvas_MCDU_base = { me["Simple_C5"].setText(sprintf("/%s ", fmgc.FMGCInternal.finalTime)); } } - me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob * LBS2KGS)); + } else { + me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob)); + } me["Simple_R2"].show(); me["INITB_Block"].hide(); - me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block * LBS2KGS)); + } else { + me["Simple_R2"].setText(sprintf("%3.1f", fmgc.FMGCInternal.block)); + } me["Simple_R3S"].hide(); me["Simple_R3"].hide(); me["Simple_R3_Arrow"].hide(); me["Simple_C4B"].hide(); - me["Simple_R4"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.tow) ~ sprintf("%4.1f", fmgc.FMGCInternal.lw)); - me["Simple_R6"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel)); + + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_R4"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.tow * LBS2KGS) ~ sprintf("%4.1f", fmgc.FMGCInternal.lw * LBS2KGS)); + me["Simple_R6"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel * LBS2KGS)); + } else { + me["Simple_R4"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.tow) ~ sprintf("%4.1f", fmgc.FMGCInternal.lw)); + me["Simple_R6"].setText(sprintf("%.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel)); + } me.colorLeft("ack", "grn", "blu", "ack", "blu", "blu"); me.colorRight("ack", "blu", "ack", "grn", "ack", "grn"); @@ -2519,9 +2586,17 @@ var canvas_MCDU_base = { if (fmgc.FMGCInternal.zfwSet) { if (fmgc.FMGCInternal.zfw < 100) { - me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw * LBS2KGS)); + } else { + me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + } } else { - me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw * LBS2KGS)); + } else { + me["Simple_C1"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + } } me["Simple_C1"].show(); me["INITB_ZFW"].hide(); @@ -2688,7 +2763,11 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "wht", "wht", "wht", "wht"); me.colorRight("ack", "ack", "ack", "wht", "wht", "wht"); } else { - me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv * LBS2KGS)); + } else { + me["Simple_L3"].setText(sprintf("%.1f", fmgc.FMGCInternal.rteRsv)); + } if (fmgc.FMGCInternal.rteRsvSet) { if (num(fmgc.FMGCInternal.rteRsv) > 9.9 and num(fmgc.FMGCInternal.rtePercent) > 9.9) { me["Simple_C3B"].setText(sprintf("/%.1f ", fmgc.FMGCInternal.rtePercent)); @@ -2721,7 +2800,11 @@ var canvas_MCDU_base = { } } if (fmgc.FMGCInternal.altAirportSet) { - me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel * LBS2KGS)); + } else { + me["Simple_L4"].setText(sprintf("%.1f", fmgc.FMGCInternal.altFuel)); + } me["Simple_L4"].setColor(BLUE); me["Simple_C4"].show(); if (fmgc.FMGCInternal.altFuelSet) { @@ -2742,7 +2825,11 @@ var canvas_MCDU_base = { me["Simple_L4"].setColor(WHITE); me["Simple_C4"].hide(); } - me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel * LBS2KGS)); + } else { + me["Simple_L5"].setText(sprintf("%.1f", fmgc.FMGCInternal.finalFuel)); + } if (fmgc.FMGCInternal.finalTimeSet and fmgc.FMGCInternal.finalFuelSet) { if (num(fmgc.FMGCInternal.finalFuel) > 9.9) { me["Simple_C5"].setText(sprintf("/%s ", fmgc.FMGCInternal.finalTime)); @@ -2768,10 +2855,17 @@ var canvas_MCDU_base = { me["Simple_C5"].setText(sprintf("/%s ", fmgc.FMGCInternal.finalTime)); } } - me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob)); - me["Simple_R4"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.fffqSensor, fmgc.FMGCInternal.fob)); - me["Simple_R5"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.fuelPredGw) ~ sprintf("%4.1f", fmgc.FMGCInternal.cg)); - me["Simple_R6"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob * LBS2KGS)); + me["Simple_R4"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.fffqSensor, fmgc.FMGCInternal.fob * LBS2KGS)); + me["Simple_R5"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.fuelPredGw * LBS2KGS) ~ sprintf("%4.1f", fmgc.FMGCInternal.cg)); + me["Simple_R6"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel * LBS2KGS)); + } else { + me["Simple_L6"].setText(sprintf("%.1f", fmgc.FMGCInternal.minDestFob)); + me["Simple_R4"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.fffqSensor, fmgc.FMGCInternal.fob)); + me["Simple_R5"].setText(sprintf("%4.1f/", fmgc.FMGCInternal.fuelPredGw) ~ sprintf("%4.1f", fmgc.FMGCInternal.cg)); + me["Simple_R6"].setText(sprintf("%4.1f/" ~ fmgc.FMGCInternal.extraTime, fmgc.FMGCInternal.extraFuel)); + } me.colorLeft("ack", "ack", "blu", "ack", "blu", "blu"); me.colorRight("ack", "ack", "blu", "grn", "grn", "grn"); @@ -2790,9 +2884,17 @@ var canvas_MCDU_base = { if (fmgc.FMGCInternal.zfwSet) { if (fmgc.FMGCInternal.zfw < 100) { - me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw * LBS2KGS)); + } else { + me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + } } else { - me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + if (acconfig_weight_kgs.getValue() == 1) { + me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw * LBS2KGS)); + } else { + me["Simple_C3"].setText(" " ~ sprintf("%3.1f", fmgc.FMGCInternal.zfw)); + } } me["Simple_C3"].show(); me["FUELPRED_ZFW"].hide(); From 6f0114457d0d1866b1ff1eb2bb7f8d62c280ea17 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 19 Sep 2020 14:43:44 +0100 Subject: [PATCH 2/4] 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; From 4e13f3fa0582df990bf1365dfa16a82331ab8e47 Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 24 Sep 2020 15:48:16 +1000 Subject: [PATCH 3/4] Fix Refuel panel Signed-off-by: fly --- gui/dialogs/refuel.nas | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/gui/dialogs/refuel.nas b/gui/dialogs/refuel.nas index 0085ebc6..63495a6e 100644 --- a/gui/dialogs/refuel.nas +++ b/gui/dialogs/refuel.nas @@ -6,7 +6,7 @@ # Distribute under the terms of GPLv2. # Conversion factor pounds to kilogram -LBS2KGS = 0.4535924; +var LBS2KGS = 0.4535924; if (pts.Sim.aero.getValue() == "A320-200-CFM") { max_fuel = 42.8; @@ -590,25 +590,45 @@ var refuelClass = { _fuelAdjustDn: func() { target = amount.getValue(); if (target > 0) { - amount.setValue(target - 0.1); - if (target - 0.1 >= 10.0) { - me._FQI_pre.setText(sprintf("%2.1f", target - 0.1)); + if (acconfig_weight_kgs.getValue() == 1) { + amount.setValue(target - 0.1 * LBS2KGS); + if ((target - 0.1) * LBS2KGS >= 10.0) { + me._FQI_pre.setText(sprintf("%2.1f", (target - 0.1) * LBS2KGS)); + } else { + me._FQI_pre.setText(sprintf("%2.2f", (target - 0.1) * LBS2KGS)); + } + systems.fuelSvc.Nodes.requestLbs.setValue((((target - 0.1) * LBS2KGS) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } else { - me._FQI_pre.setText(sprintf("%2.2f", target - 0.1)); + amount.setValue(target - 0.1); + if (target - 0.1 >= 10.0) { + me._FQI_pre.setText(sprintf("%2.1f", target - 0.1)); + } else { + me._FQI_pre.setText(sprintf("%2.2f", target - 0.1)); + } + systems.fuelSvc.Nodes.requestLbs.setValue(((target - 0.1) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } - systems.fuelSvc.Nodes.requestLbs.setValue(((target - 0.1) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } }, _fuelAdjustUp: func() { target = amount.getValue(); if (target < max_fuel) { - amount.setValue(target + 0.1); - if (target + 0.1 >= 10.0) { - me._FQI_pre.setText(sprintf("%2.1f", target + 0.1)); + if (acconfig_weight_kgs.getValue() == 1) { + amount.setValue(target + 0.1); + if ((target + 0.1) * LBS2KGS >= 10.0) { + me._FQI_pre.setText(sprintf("%2.1f", (target + 0.1) * LBS2KGS)); + } else { + me._FQI_pre.setText(sprintf("%2.2f", (target + 0.1) * LBS2KGS)); + } + systems.fuelSvc.Nodes.requestLbs.setValue((((target + 0.1) * LBS2KGS) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } else { - me._FQI_pre.setText(sprintf("%2.2f", target + 0.1)); + amount.setValue(target + 0.1); + if (target + 0.1 >= 10.0) { + me._FQI_pre.setText(sprintf("%2.1f", target + 0.1)); + } else { + me._FQI_pre.setText(sprintf("%2.2f", target + 0.1)); + } + systems.fuelSvc.Nodes.requestLbs.setValue(((target + 0.1) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } - systems.fuelSvc.Nodes.requestLbs.setValue(((target + 0.1) - math.round(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000, 0.1)) * 1000); } }, _onClose: func() { From 8793cdda358187c5b5f795b80dffa19ec6e4d36e Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 3 Oct 2020 16:48:31 +0100 Subject: [PATCH 4/4] Fix Simbrief parser to respect Simbrief weight option --- Nasal/FMGC/SimbriefParser.nas | 62 +++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/Nasal/FMGC/SimbriefParser.nas b/Nasal/FMGC/SimbriefParser.nas index f75a56e6..5454566c 100644 --- a/Nasal/FMGC/SimbriefParser.nas +++ b/Nasal/FMGC/SimbriefParser.nas @@ -1,6 +1,8 @@ # A3XX Simbrief Parser # Copyright (c) 2020 Jonathan Redpath (legoboyvdlp) +var LBS2KGS = 0.4535924; + var SimbriefParser = { node: nil, OFP: nil, @@ -37,6 +39,9 @@ var SimbriefParser = { me.store1 = nil; me.store2 = nil; + me.store1 = me.OFP.getChild("params"); + var units = me.store1.getChild("units").getValue(); + me.store1 = me.OFP.getChild("general"); me.store2 = me.OFP.getChild("alternate"); fmgc.FMGCInternal.flightNum = (me.store1.getChild("icao_airline").getValue() or "") ~ (me.store1.getChild("flight_number").getValue() or ""); @@ -154,29 +159,50 @@ var SimbriefParser = { # INITB me.store1 = me.OFP.getChild("fuel"); me.store2 = me.OFP.getChild("weights"); - fmgc.FMGCInternal.taxiFuel = me.store1.getChild("taxi").getValue() / 1000; - fmgc.FMGCInternal.taxiFuelSet = 1; - fmgc.FMGCInternal.altFuel = me.store1.getChild("alternate_burn").getValue() / 1000; - fmgc.FMGCInternal.altFuelSet = 1; - fmgc.FMGCInternal.finalFuel = me.store1.getChild("reserve").getValue() / 1000; - fmgc.FMGCInternal.finalFuelSet = 1; - fmgc.FMGCInternal.rteRsv = me.store1.getChild("contingency").getValue() / 1000; - fmgc.FMGCInternal.rteRsvSet = 1; - if ((me.store1.getChild("contingency").getValue() / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100 <= 15.0) { - fmgc.FMGCInternal.rtePercent = (me.store1.getChild("contingency").getValue() / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100; + if (units == "lbs") { + fmgc.FMGCInternal.taxiFuel = me.store1.getChild("taxi").getValue() / 1000; + fmgc.FMGCInternal.taxiFuelSet = 1; + fmgc.FMGCInternal.altFuel = me.store1.getChild("alternate_burn").getValue() / 1000; + fmgc.FMGCInternal.altFuelSet = 1; + fmgc.FMGCInternal.finalFuel = me.store1.getChild("reserve").getValue() / 1000; + fmgc.FMGCInternal.finalFuelSet = 1; + fmgc.FMGCInternal.rteRsv = me.store1.getChild("contingency").getValue() / 1000; + fmgc.FMGCInternal.rteRsvSet = 1; + if ((me.store1.getChild("contingency").getValue() / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100 <= 15.0) { + fmgc.FMGCInternal.rtePercent = (me.store1.getChild("contingency").getValue() / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100; + } else { + fmgc.FMGCInternal.rtePercent = 15.0 + } + fmgc.FMGCInternal.rtePercentSet = 0; + fmgc.FMGCInternal.block = me.store1.getChild("plan_ramp").getValue() / 1000; + fmgc.FMGCInternal.blockSet = 1; + fmgc.FMGCInternal.zfw = me.store2.getChild("est_zfw").getValue() / 1000; + fmgc.FMGCInternal.zfwSet = 1; + fmgc.FMGCInternal.tow = fmgc.FMGCInternal.zfw + fmgc.FMGCInternal.block - fmgc.FMGCInternal.taxiFuel; } else { - fmgc.FMGCInternal.rtePercent = 15.0 + fmgc.FMGCInternal.taxiFuel = (me.store1.getChild("taxi").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.taxiFuelSet = 1; + fmgc.FMGCInternal.altFuel = (me.store1.getChild("alternate_burn").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.altFuelSet = 1; + fmgc.FMGCInternal.finalFuel = (me.store1.getChild("reserve").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.finalFuelSet = 1; + fmgc.FMGCInternal.rteRsv = (me.store1.getChild("contingency").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.rteRsvSet = 1; + if (((me.store1.getChild("contingency").getValue() / LBS2KGS) / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100 <= 15.0) { + fmgc.FMGCInternal.rtePercent = ((me.store1.getChild("contingency").getValue() / LBS2KGS) / 1000) / num(fmgc.FMGCInternal.tripFuel) * 100; + } else { + fmgc.FMGCInternal.rtePercent = 15.0 + } + fmgc.FMGCInternal.rtePercentSet = 0; + fmgc.FMGCInternal.block = (me.store1.getChild("plan_ramp").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.blockSet = 1; + fmgc.FMGCInternal.zfw = (me.store2.getChild("est_zfw").getValue() / LBS2KGS) / 1000; + fmgc.FMGCInternal.zfwSet = 1; + fmgc.FMGCInternal.tow = fmgc.FMGCInternal.zfw + fmgc.FMGCInternal.block - fmgc.FMGCInternal.taxiFuel; } - fmgc.FMGCInternal.rtePercentSet = 0; - fmgc.FMGCInternal.block = me.store1.getChild("plan_ramp").getValue() / 1000; - fmgc.FMGCInternal.blockSet = 1; - fmgc.FMGCInternal.zfw = me.store2.getChild("est_zfw").getValue() / 1000; - fmgc.FMGCInternal.zfwSet = 1; - fmgc.FMGCInternal.tow = fmgc.FMGCInternal.zfw + fmgc.FMGCInternal.block - fmgc.FMGCInternal.taxiFuel; setprop("/FMGC/internal/fuel-request-set", 1); setprop("/FMGC/internal/fuel-calculating", 1); setprop("/FMGC/internal/block-calculating", 0); setprop("/FMGC/internal/block-confirmed", 1); - }, }; \ No newline at end of file