2017-06-09 16:53:49 +00:00
# A3XX Pneumatics System
2017-05-12 14:18:16 +00:00
# Joshua Davidson (it0uchpods) and Jonathan Redpath (legoboyvdlp)
2017-04-24 12:46:44 +00:00
2017-04-25 17:13:15 +00:00
#############
# Init Vars #
#############
2017-04-24 12:46:44 +00:00
2017-05-03 00:54:39 +00:00
var pneu_init = func {
2017-06-10 13:53:57 +00:00
setprop("/controls/pneumatic/switches/bleed1", 1);
setprop("/controls/pneumatic/switches/bleed2", 1);
2017-04-28 22:27:21 +00:00
setprop("/controls/pneumatic/switches/bleedapu", 0);
2017-05-12 14:18:16 +00:00
setprop("/controls/pneumatic/switches/groundair", 0);
2017-06-10 13:53:57 +00:00
setprop("/controls/pneumatic/switches/pack1", 1);
setprop("/controls/pneumatic/switches/pack2", 1);
setprop("/controls/pneumatic/switches/hot-air", 1);
2017-04-28 22:27:21 +00:00
setprop("/controls/pneumatic/switches/ram-air", 0);
2017-05-01 20:56:33 +00:00
setprop("/controls/pneumatic/switches/pack-flo", 9); # LO: 7, NORM: 9, HI: 11.
setprop("/controls/pneumatic/switches/xbleed", 1); # SHUT: 0, AUTO: 1, OPEN: 2. # I will simulate later, once I get the knob animated. -JD
2017-06-10 14:56:11 +00:00
setprop("/controls/pressurization/auto", 1);
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleed1", 0);
setprop("/systems/pneumatic/bleed2", 0);
setprop("/systems/pneumatic/bleedapu", 0);
2017-05-12 14:18:16 +00:00
setprop("/systems/pneumatic/groundair", 0);
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/total-psi", 0);
setprop("/systems/pneumatic/start-psi", 0);
2017-05-01 20:56:33 +00:00
setprop("/systems/pneumatic/pack-psi", 0);
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/pack1", 0);
setprop("/systems/pneumatic/pack2", 0);
setprop("/systems/pneumatic/startpsir", 0);
2017-05-03 15:16:20 +00:00
setprop("/systems/pneumatic/eng1-starter", 0);
setprop("/systems/pneumatic/eng2-starter", 0);
2017-06-02 14:31:17 +00:00
setprop("/FMGC/internal/dep-arpt", "");
setprop("/systems/pressurization/mode", "GN");
setprop("/systems/pressurization/vs", "0");
2017-06-06 15:54:41 +00:00
setprop("/systems/pressurization/targetvs", "0");
setprop("/systems/pressurization/vs-norm", "0");
2017-06-02 14:31:17 +00:00
setprop("/systems/pressurization/auto", 1);
setprop("/systems/pressurization/deltap", "0");
setprop("/systems/pressurization/outflowpos", "0");
2017-06-06 15:54:41 +00:00
setprop("/systems/pressurization/deltap-norm", "0");
setprop("/systems/pressurization/outflowpos-norm", "0");
2017-06-10 18:28:22 +00:00
var altitude = getprop("/instrumentation/altimeter/indicated-altitude-ft");
2017-06-06 15:54:41 +00:00
setprop("/systems/pressurization/cabinalt", altitude);
setprop("/systems/pressurization/targetalt", altitude);
setprop("/systems/pressurization/diff-to-target", "0");
2017-06-10 18:28:22 +00:00
setprop("/systems/pressurization/ditchingpb", 0);
2017-06-10 19:51:50 +00:00
setprop("/systems/pressurization/targetvs", "0");
2017-06-10 18:28:22 +00:00
pneu_timer.start();
2017-06-02 14:31:17 +00:00
}
2017-06-10 14:56:11 +00:00
#######################
# Main Pneumatic Loop #
#######################
2017-04-24 12:46:44 +00:00
2017-04-25 17:13:15 +00:00
var master_pneu = func {
2017-04-28 22:27:21 +00:00
var bleed1_sw = getprop("/controls/pneumatic/switches/bleed1");
var bleed2_sw = getprop("/controls/pneumatic/switches/bleed2");
var bleedapu_sw = getprop("/controls/pneumatic/switches/bleedapu");
var pack1_sw = getprop("/controls/pneumatic/switches/pack1");
var pack2_sw = getprop("/controls/pneumatic/switches/pack2");
var hot_air_sw = getprop("/controls/pneumatic/switches/hot-air");
var ram_air_sw = getprop("/controls/pneumatic/switches/ram-air");
2017-05-03 00:54:39 +00:00
var pack_flo_sw = getprop("/controls/pneumatic/switches/pack-flo");
2017-04-28 22:27:21 +00:00
var xbleed_sw = getprop("/controls/pneumatic/switches/xbleed");
2017-05-03 15:16:20 +00:00
var eng1_starter = getprop("/systems/pneumatic/eng1-starter");
var eng2_starter = getprop("/systems/pneumatic/eng2-starter");
2017-05-12 14:18:16 +00:00
var groundair = getprop("/systems/pneumatic/groundair");
var groundair_supp = getprop("/controls/pneumatic/switches/groundair");
2017-04-28 22:27:21 +00:00
var rpmapu = getprop("/systems/apu/rpm");
var stateL = getprop("/engines/engine[0]/state");
var stateR = getprop("/engines/engine[1]/state");
2017-06-01 03:55:43 +00:00
var bleedapu_fail = getprop("/systems/failures/bleed-apu");
var bleedext_fail = getprop("/systems/failures/bleed-ext");
var bleedeng1_fail = getprop("/systems/failures/bleed-eng1");
var bleedeng2_fail = getprop("/systems/failures/bleed-eng2");
var pack1_fail = getprop("/systems/failures/pack1");
var pack2_fail = getprop("/systems/failures/pack2");
2017-04-25 17:13:15 +00:00
2017-04-28 22:27:21 +00:00
# Air Sources/PSI
2017-06-01 03:55:43 +00:00
if (rpmapu >= 94.9 and bleedapu_sw and !bleedapu_fail) {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleedapu", 34);
2017-04-25 17:13:15 +00:00
} else {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleedapu", 0);
2017-04-24 12:46:44 +00:00
}
2017-04-28 22:27:21 +00:00
2017-06-01 03:55:43 +00:00
if (stateL == 3 and bleed1_sw and !bleedeng1_fail) {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleed1", 31);
2017-04-25 17:13:15 +00:00
} else {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleed1", 0);
2017-04-24 12:46:44 +00:00
}
2017-04-28 22:27:21 +00:00
2017-06-01 03:55:43 +00:00
if (stateR == 3 and bleed2_sw and !bleedeng2_fail) {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/bleed2", 32);
} else {
setprop("/systems/pneumatic/bleed2", 0);
2017-04-25 17:13:15 +00:00
}
2017-04-28 22:27:21 +00:00
var bleed1 = getprop("/systems/pneumatic/bleed1");
var bleed2 = getprop("/systems/pneumatic/bleed2");
var bleedapu = getprop("/systems/pneumatic/bleedapu");
2017-05-12 14:18:16 +00:00
var ground = getprop("/systems/pneumatic/groundair");
2017-04-28 22:27:21 +00:00
2017-05-01 20:56:33 +00:00
if (stateL == 1 or stateR == 1) {
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/start-psi", 18);
} else {
setprop("/systems/pneumatic/start-psi", 0);
2017-04-25 17:13:15 +00:00
}
2017-04-28 22:27:21 +00:00
2017-06-01 03:55:43 +00:00
if (pack1_sw == 1 and (bleed1 >= 20 or bleedapu >= 20 or ground >= 20) and eng1_starter == 0 and eng2_starter == 0 and !pack1_fail) {
2017-05-03 00:54:39 +00:00
setprop("/systems/pneumatic/pack1", pack_flo_sw);
2017-05-01 20:56:33 +00:00
} else {
setprop("/systems/pneumatic/pack1", 0);
}
2017-06-10 13:53:57 +00:00
if (pack2_sw == 1 and (bleed2 >= 20 or bleedapu >= 20) and eng1_starter == 0 and eng2_starter == 0 and !pack2_fail) {
2017-05-03 00:54:39 +00:00
setprop("/systems/pneumatic/pack2", pack_flo_sw);
2017-05-01 20:56:33 +00:00
} else {
setprop("/systems/pneumatic/pack2", 0);
}
var pack1 = getprop("/systems/pneumatic/pack1");
var pack2 = getprop("/systems/pneumatic/pack2");
if (pack1_sw == 1 and pack2_sw == 1) {
setprop("/systems/pneumatic/pack-psi", pack1 + pack2);
} else if (pack1_sw == 0 and pack2_sw == 0) {
setprop("/systems/pneumatic/pack-psi", 0);
} else {
setprop("/systems/pneumatic/pack-psi", pack1 + pack2 + 5);
}
var pack_psi = getprop("/systems/pneumatic/pack-psi");
2017-04-28 22:27:21 +00:00
var start_psi = getprop("/systems/pneumatic/start-psi");
if ((bleed1 + bleed2 + bleedapu) > 42) {
setprop("/systems/pneumatic/total-psi", 42);
2017-04-25 17:13:15 +00:00
} else {
2017-05-18 14:04:29 +00:00
var total_psi_calc = ((bleed1 + bleed2 + bleedapu + ground) - start_psi - pack_psi);
2017-04-28 22:27:21 +00:00
setprop("/systems/pneumatic/total-psi", total_psi_calc);
2017-04-25 17:13:15 +00:00
}
2017-04-28 22:27:21 +00:00
2017-06-01 03:55:43 +00:00
if (groundair_supp) {
2017-05-12 14:18:16 +00:00
setprop("/systems/pneumatic/groundair", 39);
} else {
setprop("/systems/pneumatic/groundair", 0);
}
2017-04-28 22:27:21 +00:00
var total_psi = getprop("/systems/pneumatic/total-psi");
2017-06-10 14:56:11 +00:00
var phase = getprop("/FMGC/status/phase");
var pressmode = getprop("/systems/pressurization/mode");
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
var wowl = getprop("/gear/gear[1]/wow");
var wowr = getprop("/gear/gear[2]/wow");
var deltap = getprop("/systems/pressurization/deltap");
var outflow = getprop("/systems/pressurization/outflowpos");
var speed = getprop("/velocities/groundspeed-kt");
2017-06-10 18:28:22 +00:00
var altitude = getprop("/instrumentation/altimeter/indicated-altitude-ft");
2017-06-10 14:56:11 +00:00
var airport_arr_elev_ft = getprop("autopilot/route-manager/destination/field-elevation-ft");
var vs = getprop("/systems/pressurization/vs-norm");
2017-06-10 18:28:22 +00:00
var ditch = getprop("/systems/pressurization/ditchingpb");
2017-06-10 14:56:11 +00:00
var outflowpos = getprop("/systems/pressurization/outflowpos");
var cabinalt = getprop("/systems/pressurization/cabinalt");
var targetalt = getprop("/systems/pressurization/targetalt");
var targetvs = getprop("/systems/pressurization/targetvs");
var ambient = getprop("/systems/pressurization/ambientpsi");
var cabinpsi = getprop("/systems/pressurization/cabinpsi");
2017-06-10 18:28:22 +00:00
var pause = getprop("/sim/freeze/master");
var auto = getprop("/systems/pressurization/auto");
2017-06-10 14:56:11 +00:00
setprop("/systems/pressurization/diff-to-target", targetalt - cabinalt);
setprop("/systems/pressurization/deltap", cabinpsi - ambient);
if ((pressmode == "GN") and (pressmode != "CL") and (wowl and wowr) and ((state1 == "MCT") or (state1 == "TOGA")) and ((state2 == "MCT") or (state2 == "TOGA"))) {
setprop("/systems/pressurization/mode", "TO");
2017-06-10 18:28:22 +00:00
} else if (((!wowl) or (!wowr)) and (speed > 100) and (pressmode == "TO")) {
2017-06-10 14:56:11 +00:00
setprop("/systems/pressurization/mode", "CL");
}
if (vs != targetvs and !wowl and !wowr) {
setprop("/systems/pressurization/vs", targetvs);
}
2017-06-10 18:28:22 +00:00
if (cabinalt != targetalt and !wowl and !wowr and !pause) {
2017-06-10 14:56:11 +00:00
setprop("/systems/pressurization/cabinalt", cabinalt + vs);
}
2017-06-10 18:28:22 +00:00
if (ditch and auto) {
setprop("/systems/pressurization/outflowpos", "1");
}
2017-04-24 12:46:44 +00:00
}
2017-04-25 17:13:15 +00:00
###################
# Update Function #
###################
var update_pneumatic = func {
master_pneu();
2017-04-24 12:46:44 +00:00
}
2017-04-25 17:13:15 +00:00
2017-04-28 22:27:21 +00:00
var pneu_timer = maketimer(0.2, update_pneumatic);
2017-06-02 14:31:17 +00:00