2019-10-14 16:48:35 +00:00
# A320 Main Libraries
# Joshua Davidson (Octal450)
2020-04-18 05:36:46 +00:00
# Copyright (c) 2020 Josh Davidson (Octal450)
2019-10-14 16:48:35 +00:00
2020-04-27 13:58:38 +00:00
print("------------------------------------------------");
print("Copyright (c) 2016-2020 Josh Davidson (Octal450)");
print("------------------------------------------------");
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
setprop("sim/replay/was-active", 0);
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
setprop("sim/menubar/default/menu[0]/item[0]/enabled", 0);
setprop("sim/menubar/default/menu[2]/item[0]/enabled", 0);
setprop("sim/menubar/default/menu[2]/item[2]/enabled", 0);
setprop("sim/menubar/default/menu[3]/enabled", 0);
setprop("sim/menubar/default/menu[5]/item[9]/enabled", 0);
setprop("sim/menubar/default/menu[5]/item[10]/enabled", 0);
setprop("sim/menubar/default/menu[5]/item[11]/enabled", 0);
2019-10-14 16:48:35 +00:00
# Dimmers
2020-02-07 16:10:54 +00:00
setprop("controls/lighting/ndl-norm", 1);
setprop("controls/lighting/ndr-norm", 1);
setprop("controls/lighting/upper-norm", 1);
2019-10-14 16:48:35 +00:00
# Lights
2020-02-07 16:10:54 +00:00
setprop("sim/model/lights/nose-lights", 0);
setprop("sim/model/lights/turnoffsw", 0);
setprop("controls/lighting/turnoff-light-switch", 0);
setprop("controls/lighting/leftturnoff", 0);
setprop("controls/lighting/rightturnoff", 0);
2019-10-14 16:48:35 +00:00
# Oil Qty
var qty1 = math.round((rand() * 5 ) + 20, 0.1);
var qty2 = math.round((rand() * 5 ) + 20, 0.1);
2020-02-07 16:10:54 +00:00
setprop("engines/engine[0]/oil-qt-actual", qty1);
setprop("engines/engine[1]/oil-qt-actual", qty2);
2019-10-14 16:48:35 +00:00
##########
# Lights #
##########
2020-02-07 16:10:54 +00:00
var beacon_switch = props.globals.getNode("controls/switches/beacon", 1);
var beacon_ctl = props.globals.getNode("controls/lighting/beacon", 1);
2019-10-14 16:48:35 +00:00
var beacon = aircraft.light.new("/sim/model/lights/beacon", [0.1, 1], "/controls/lighting/beacon");
2020-02-07 16:10:54 +00:00
var strobe_switch = props.globals.getNode("controls/switches/strobe", 1);
var strobe_light = props.globals.getNode("controls/lighting/strobe", 1);
2019-10-14 16:48:35 +00:00
var strobe = aircraft.light.new("/sim/model/lights/strobe", [0.05, 0.06, 0.05, 1], "/controls/lighting/strobe");
var tail_strobe = aircraft.light.new("/sim/model/lights/tailstrobe", [0.1, 1], "/controls/lighting/strobe");
2020-02-07 16:10:54 +00:00
var logo_lights = getprop("sim/model/lights/logo-lights");
var nav_lights = props.globals.getNode("sim/model/lights/nav-lights");
var wing_switch = props.globals.getNode("controls/switches/wing-lights", 1);
var wing_ctl = props.globals.getNode("controls/lighting/wing-lights", 1);
2019-10-14 16:48:35 +00:00
var dome_light = props.globals.initNode("/sim/model/lights/dome-light", 0.0, "DOUBLE");
2020-02-07 16:10:54 +00:00
var wow = getprop("gear/gear[2]/wow");
var slats = getprop("controls/flight/slats");
var gear = getprop("gear/gear[0]/position-norm");
var nose_lights = getprop("sim/model/lights/nose-lights");
var left_turnoff_light = props.globals.getNode("controls/lighting/leftturnoff");
var right_turnoff_light = props.globals.getNode("controls/lighting/rightturnoff");
var settingT = getprop("controls/lighting/taxi-light-switch");
var settingTurnoff = getprop("controls/lighting/turnoff-light-switch");
var setting = getprop("controls/lighting/nav-lights-switch");
var domeSetting = getprop("controls/lighting/dome-norm");
2019-10-14 16:48:35 +00:00
var landL = props.globals.getNode("controls/lighting/landing-lights[1]", 1);
var landR = props.globals.getNode("controls/lighting/landing-lights[2]", 1);
2020-02-07 16:10:54 +00:00
var landlSw = props.globals.getNode("controls/switches/landing-lights-l", 1);
var landrSw = props.globals.getNode("controls/switches/landing-lights-r", 1);
2019-10-14 16:48:35 +00:00
###################
# Tire Smoke/Rain #
###################
var tiresmoke_system = aircraft.tyresmoke_system.new(0, 1, 2);
aircraft.rain.init();
##########
# Sounds #
##########
setlistener("/sim/sounde/btn1", func {
2020-02-07 16:10:54 +00:00
if (!getprop("sim/sounde/btn1")) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/btn1").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.05);
});
setlistener("/sim/sounde/oh-btn", func {
2020-02-07 16:10:54 +00:00
if (!getprop("sim/sounde/oh-btn")) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/oh-btn").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.05);
});
setlistener("/sim/sounde/btn3", func {
2020-02-07 16:10:54 +00:00
if (!getprop("sim/sounde/btn3")) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/btn3").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.05);
});
setlistener("/sim/sounde/knb1", func {
2020-02-07 16:10:54 +00:00
if (!getprop("sim/sounde/knb1")) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/knb1").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.05);
});
setlistener("/sim/sounde/switch1", func {
2020-02-07 16:10:54 +00:00
if (!getprop("sim/sounde/switch1")) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/switch1").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.05);
});
setlistener("/controls/lighting/seatbelt-sign", func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/seatbelt-sign").setBoolValue(1);
2019-10-14 16:48:35 +00:00
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/seatbelt-sign").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 2);
}, 0, 0);
setlistener("/controls/lighting/no-smoking-sign", func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/no-smoking-sign").setBoolValue(1);
2019-10-14 16:48:35 +00:00
settimer(func {
2020-02-07 16:10:54 +00:00
props.globals.getNode("sim/sounde/no-smoking-sign").setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 1);
}, 0, 0);
2020-05-11 17:01:44 +00:00
var flaps_click = props.globals.getNode("/sim/sounde/flaps-click");
2019-10-14 16:48:35 +00:00
setlistener("/controls/flight/flap-lever", func {
2020-05-11 17:01:44 +00:00
flaps_click.setBoolValue(1);
2019-10-14 16:48:35 +00:00
}, 0, 0);
setlistener("/sim/sounde/flaps-click", func {
2020-05-11 17:01:44 +00:00
if (!flaps_click.getValue()) {
return;
}
settimer(func {
flaps_click.setBoolValue(0);
}, 0.4);
});
var spdbrk_click = props.globals.getNode("/sim/sounde/spdbrk-click");
setlistener("/controls/flight/speedbrake", func {
spdbrk_click.setBoolValue(1);
}, 0, 0);
setlistener("/sim/sounde/spdbrk-click", func {
if (!spdbrk_click.getValue()) {
2019-10-14 16:48:35 +00:00
return;
}
settimer(func {
2020-05-11 17:01:44 +00:00
spdbrk_click.setBoolValue(0);
2019-10-14 16:48:35 +00:00
}, 0.4);
});
2020-05-11 17:01:44 +00:00
2019-10-14 16:48:35 +00:00
#########
# Doors #
#########
# Front doors
var doorl1 = aircraft.door.new("/sim/model/door-positions/doorl1", 4);
var doorr1 = aircraft.door.new("/sim/model/door-positions/doorr1", 4);
# Middle doors (A321 only)
var doorl2 = aircraft.door.new("/sim/model/door-positions/doorl2", 4);
var doorr2 = aircraft.door.new("/sim/model/door-positions/doorr2", 4);
var doorl3 = aircraft.door.new("/sim/model/door-positions/doorl3", 4);
var doorr3 = aircraft.door.new("/sim/model/door-positions/doorr3", 4);
# Rear doors
var doorl4 = aircraft.door.new("/sim/model/door-positions/doorl4", 4);
var doorr4 = aircraft.door.new("/sim/model/door-positions/doorr4", 4);
# Cargo holds
var cargobulk = aircraft.door.new("/sim/model/door-positions/cargobulk", 3);
var cargoaft = aircraft.door.new("/sim/model/door-positions/cargoaft", 10);
var cargofwd = aircraft.door.new("/sim/model/door-positions/cargofwd", 10);
# Seat armrests in the flight deck (unused)
var armrests = aircraft.door.new("/sim/model/door-positions/armrests", 2);
# door opener/closer
var triggerDoor = func(door, doorName, doorDesc) {
2020-02-07 16:10:54 +00:00
if (getprop("sim/model/door-positions/" ~ doorName ~ "/position-norm") > 0) {
2019-10-14 16:48:35 +00:00
gui.popupTip("Closing " ~ doorDesc ~ " door");
door.toggle();
} else {
2020-02-07 16:10:54 +00:00
if (getprop("velocities/groundspeed-kt") > 5) {
2019-10-14 16:48:35 +00:00
gui.popupTip("You cannot open the doors while the aircraft is moving!");
} else {
gui.popupTip("Opening " ~ doorDesc ~ " door");
door.toggle();
}
}
};
#######################
# Various Other Stuff #
#######################
var systemsInit = func {
2019-11-30 13:39:53 +00:00
fbw.FBW.init();
2020-05-05 18:12:14 +00:00
effects.light_manager.init();
2019-10-14 16:48:35 +00:00
systems.ELEC.init();
systems.PNEU.init();
systems.HYD.init();
systems.FUEL.init();
systems.ADIRS.init();
systems.eng_init();
2020-04-14 17:07:01 +00:00
systems.APUController.init();
2019-10-14 16:48:35 +00:00
systems.fire_init();
systems.autobrake_init();
2020-01-07 20:48:27 +00:00
fmgc.flightPlanController.reset();
2019-10-14 16:48:35 +00:00
fadec.FADEC.init();
fmgc.ITAF.init();
fmgc.FMGCinit();
mcdu.MCDU_init(0);
mcdu.MCDU_init(1);
systemsLoop.start();
2020-05-05 18:12:14 +00:00
effects.icingInit();
2019-10-14 16:48:35 +00:00
lightsLoop.start();
libraries.ECAM.init();
libraries.variousReset();
rmp.init();
acp.init();
ecam.ECAM_controller.init();
atc.init();
2019-10-27 20:54:00 +00:00
fcu.FCUController.init();
2019-11-06 19:09:42 +00:00
dmc.DMController.init();
2019-10-14 16:48:35 +00:00
}
setlistener("/sim/signals/fdm-initialized", func {
systemsInit();
2020-01-07 20:48:27 +00:00
fmgc.flightPlanTimer.start();
2019-10-14 16:48:35 +00:00
});
var systemsLoop = maketimer(0.1, func {
systems.ELEC.loop();
systems.PNEU.loop();
systems.HYD.loop();
systems.FUEL.loop();
2020-05-01 08:41:39 +00:00
systems.ADIRS.loop();
2019-10-14 16:48:35 +00:00
libraries.ECAM.loop();
libraries.BUTTONS.update();
fadec.FADEC.loop();
rmp.rmpUpdate();
2019-10-27 20:54:00 +00:00
fcu.FCUController.loop();
2019-11-06 19:09:42 +00:00
dmc.DMController.loop();
2020-04-18 18:57:59 +00:00
systems.APUController.loop();
2020-04-21 15:35:11 +00:00
systems.HFLoop();
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
if ((getprop("controls/pneumatic/switches/groundair") or getprop("controls/electrical/ground-cart")) and ((getprop("velocities/groundspeed-kt") > 2) or (getprop("controls/gear/brake-parking") == 0 and getprop("services/chocks/nose") == 0 and getprop("services/chocks/left") == 0 and getprop("services/chocks/right") == 0))) {
setprop("controls/electrical/ground-cart", 0);
setprop("controls/pneumatic/switches/groundair", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if (getprop("velocities/groundspeed-kt") > 15) {
setprop("systems/shake/effect", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/shake/effect", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if (getprop("instrumentation/mk-viii/inputs/discretes/momentary-flap-all-override") == 1 or (getprop("instrumentation/mk-viii/inputs/discretes/momentary-flap-3-override") == 1 and getprop("controls/flight/flap-pos") >= 4)) {
setprop("instrumentation/mk-viii/inputs/discretes/momentary-flap-override", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("instrumentation/mk-viii/inputs/discretes/momentary-flap-override", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if (getprop("instrumentation/mk-viii/inputs/discretes/gpws-inhibit") == 1) {
setprop("instrumentation/mk-viii/speaker/volume", 0);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("instrumentation/mk-viii/speaker/volume", 2);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if (getprop("engines/engine[0]/state") == 3 and getprop("engines/engine[1]/state") == 3) {
setprop("engines/ready", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("engines/ready", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if ((getprop("engines/engine[0]/state") == 2 or getprop("engines/engine[0]/state") == 3) and getprop("fdm/jsbsim/propulsion/tank[5]/contents-lbs") < 1) {
2019-10-14 16:48:35 +00:00
systems.cutoff_one();
}
2020-02-07 16:10:54 +00:00
if ((getprop("engines/engine[1]/state") == 2 or getprop("engines/engine[1]/state") == 3) and getprop("fdm/jsbsim/propulsion/tank[6]/contents-lbs") < 1) {
2019-10-14 16:48:35 +00:00
systems.cutoff_two();
}
2020-02-07 16:10:54 +00:00
if (getprop("sim/replay/replay-state") == 1) {
setprop("sim/replay/was-active", 1);
} else if (getprop("sim/replay/replay-state") == 0 and getprop("sim/replay/was-active") == 1) {
setprop("sim/replay/was-active", 0);
2019-10-14 16:48:35 +00:00
acconfig.colddark();
gui.popupTip("Replay Ended: Setting Cold and Dark state...");
}
});
setlistener("/options/steep-ils", func {
2020-02-07 16:10:54 +00:00
if (getprop("options/steep-ils") == 1) {
setprop("instrumentation/mk-viii/inputs/discretes/steep-approach", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("instrumentation/mk-viii/inputs/discretes/steep-approach", 0);
2019-10-14 16:48:35 +00:00
}
});
canvas.Text._lastText = canvas.Text["_lastText"];
canvas.Text.setText = func(text) {
if (text == me._lastText and text != nil and size(text) == size(me._lastText)) {return me;}
me._lastText = text;
me.set("text", typeof(text) == 'scalar' ? text : "");
};
canvas.Element._lastVisible = nil;
canvas.Element.show = func {
if (1 == me._lastVisible) {return me;}
me._lastVisible = 1;
me.setBool("visible", 1);
};
canvas.Element.hide = func {
if (0 == me._lastVisible) {return me;}
me._lastVisible = 0;
me.setBool("visible", 0);
};
canvas.Element.setVisible = func(vis) {
if (vis == me._lastVisible) {return me;}
me._lastVisible = vis;
me.setBool("visible", vis);
};
2019-11-01 10:59:18 +00:00
2019-10-14 16:48:35 +00:00
# In air, flaps 1 is slats only. On ground, it is slats and flaps.
2020-02-07 16:10:54 +00:00
setprop("controls/flight/flap-lever", 0);
setprop("controls/flight/flap-pos", 0);
setprop("controls/flight/flap-txt", " ");
2019-10-14 16:48:35 +00:00
controls.flapsDown = func(step) {
if (step == 1) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/flap-lever") == 0) {
if (getprop("velocities/airspeed-kt") <= 100) {
setprop("controls/flight/flaps", 0.2857);
setprop("controls/flight/slats", 0.6666);
setprop("controls/flight/flap-lever", 1);
setprop("controls/flight/flap-pos", 2);
setprop("controls/flight/flap-txt", "1+F");
2019-10-14 16:48:35 +00:00
flaptimer.start();
return;
} else {
2020-02-07 16:10:54 +00:00
setprop("controls/flight/flaps", 0.000);
setprop("controls/flight/slats", 0.6666);
setprop("controls/flight/flap-lever", 1);
setprop("controls/flight/flap-pos", 1);
setprop("controls/flight/flap-txt", "1");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
}
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 1) {
setprop("controls/flight/flaps", 0.4286);
setprop("controls/flight/slats", 0.8148);
setprop("controls/flight/flap-lever", 2);
setprop("controls/flight/flap-pos", 3);
setprop("controls/flight/flap-txt", "2");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 2) {
setprop("controls/flight/flaps", 0.5714);
setprop("controls/flight/slats", 0.8148);
setprop("controls/flight/flap-lever", 3);
setprop("controls/flight/flap-pos", 4);
setprop("controls/flight/flap-txt", "3");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 3) {
setprop("controls/flight/flaps", 1.000);
setprop("controls/flight/slats", 1.000);
setprop("controls/flight/flap-lever", 4);
setprop("controls/flight/flap-pos", 5);
setprop("controls/flight/flap-txt", "FULL");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
}
} else if (step == -1) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/flap-lever") == 4) {
setprop("controls/flight/flaps", 0.5714);
setprop("controls/flight/slats", 0.8148);
setprop("controls/flight/flap-lever", 3);
setprop("controls/flight/flap-pos", 4);
setprop("controls/flight/flap-txt", "3");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 3) {
setprop("controls/flight/flaps", 0.4286);
setprop("controls/flight/slats", 0.8148);
setprop("controls/flight/flap-lever", 2);
setprop("controls/flight/flap-pos", 3);
setprop("controls/flight/flap-txt", "2");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 2) {
if (getprop("velocities/airspeed-kt") <= 100) {
setprop("controls/flight/flaps", 0.2857);
setprop("controls/flight/slats", 0.6666);
setprop("controls/flight/flap-lever", 1);
setprop("controls/flight/flap-pos", 2);
setprop("controls/flight/flap-txt", "1+F");
2019-10-14 16:48:35 +00:00
flaptimer.start();
return;
} else {
2020-02-07 16:10:54 +00:00
setprop("controls/flight/flaps", 0.000);
setprop("controls/flight/slats", 0.6666);
setprop("controls/flight/flap-lever", 1);
setprop("controls/flight/flap-pos", 1);
setprop("controls/flight/flap-txt", "1");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
}
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/flight/flap-lever") == 1) {
setprop("controls/flight/flaps", 0.000);
setprop("controls/flight/slats", 0.000);
setprop("controls/flight/flap-lever", 0);
setprop("controls/flight/flap-pos", 0);
setprop("controls/flight/flap-txt", " ");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
return;
}
} else {
return 0;
}
}
var flaptimer = maketimer(0.5, func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/flap-pos") == 2 and getprop("velocities/airspeed-kt") >= 208) {
setprop("controls/flight/flaps", 0.000);
setprop("controls/flight/slats", 0.666);
setprop("controls/flight/flap-lever", 1);
setprop("controls/flight/flap-pos", 1);
setprop("controls/flight/flap-txt", "1");
2019-10-14 16:48:35 +00:00
flaptimer.stop();
}
});
controls.stepSpoilers = func(step) {
2020-02-07 16:10:54 +00:00
setprop("controls/flight/speedbrake-arm", 0);
2019-10-14 16:48:35 +00:00
if (step == 1) {
deploySpeedbrake();
} else if (step == -1) {
retractSpeedbrake();
}
}
var deploySpeedbrake = func {
2020-02-07 16:10:54 +00:00
if (getprop("gear/gear[1]/wow") == 1 or getprop("gear/gear[2]/wow") == 1) {
if (getprop("controls/flight/speedbrake") < 1.0) {
setprop("controls/flight/speedbrake", 1.0);
2019-10-14 16:48:35 +00:00
}
} else {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/speedbrake") < 0.5) {
setprop("controls/flight/speedbrake", 0.5);
} else if (getprop("controls/flight/speedbrake") < 1.0) {
setprop("controls/flight/speedbrake", 1.0);
2019-10-14 16:48:35 +00:00
}
}
}
var retractSpeedbrake = func {
2020-02-07 16:10:54 +00:00
if (getprop("gear/gear[1]/wow") == 1 or getprop("gear/gear[2]/wow") == 1) {
if (getprop("controls/flight/speedbrake") > 0.0) {
setprop("controls/flight/speedbrake", 0.0);
2019-10-14 16:48:35 +00:00
}
} else {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/speedbrake") > 0.5) {
setprop("controls/flight/speedbrake", 0.5);
} else if (getprop("controls/flight/speedbrake") > 0.0) {
setprop("controls/flight/speedbrake", 0.0);
2019-10-14 16:48:35 +00:00
}
}
}
var slewProp = func(prop, delta) {
2020-02-07 16:10:54 +00:00
delta *= getprop("sim/time/delta-realtime-sec");
2019-10-14 16:48:35 +00:00
setprop(prop, getprop(prop) + delta);
return getprop(prop);
}
controls.elevatorTrim = func(speed) {
2020-02-07 16:10:54 +00:00
if (getprop("systems/hydraulic/green-psi") >= 1500) {
2019-10-14 16:48:35 +00:00
slewProp("/controls/flight/elevator-trim", speed * 0.045);
}
}
setlistener("/controls/flight/elevator-trim", func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/elevator-trim") > 0.32) {
setprop("controls/flight/elevator-trim", 0.32);
2019-10-14 16:48:35 +00:00
}
});
var lightsLoop = maketimer(0.2, func {
2020-02-07 16:10:54 +00:00
gear = getprop("gear/gear[0]/position-norm");
nose_lights = getprop("sim/model/lights/nose-lights");
settingT = getprop("controls/lighting/taxi-light-switch");
domeSetting = getprop("controls/lighting/dome-norm");
2019-10-14 16:48:35 +00:00
# nose lights
2020-02-07 16:10:54 +00:00
if (settingT == 0.5 and gear > 0.9 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0)) {
setprop("sim/model/lights/nose-lights", 0.85);
} else if (settingT == 1 and gear > 0.9 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0)) {
setprop("sim/model/lights/nose-lights", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("sim/model/lights/nose-lights", 0);
2019-10-14 16:48:35 +00:00
}
# turnoff lights
2020-02-07 16:10:54 +00:00
settingTurnoff = getprop("controls/lighting/turnoff-light-switch");
left_turnoff_light = props.globals.getNode("controls/lighting/leftturnoff");
right_turnoff_light = props.globals.getNode("controls/lighting/rightturnoff");
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
if (settingTurnoff == 1 and gear > 0.9 and getprop("systems/electrical/bus/ac-1") > 0) {
2019-10-14 16:48:35 +00:00
left_turnoff_light.setBoolValue(1);
} else {
left_turnoff_light.setBoolValue(0);
}
2020-02-07 16:10:54 +00:00
if (settingTurnoff == 1 and gear > 0.9 and getprop("systems/electrical/bus/ac-2") > 0) {
2019-10-14 16:48:35 +00:00
right_turnoff_light.setBoolValue(1);
} else {
right_turnoff_light.setBoolValue(0);
}
# logo and navigation lights
2020-02-07 16:10:54 +00:00
setting = getprop("controls/lighting/nav-lights-switch");
nav_lights = props.globals.getNode("sim/model/lights/nav-lights");
logo_lights = props.globals.getNode("sim/model/lights/logo-lights");
wow = getprop("gear/gear[2]/wow");
slats = getprop("controls/flight/slats");
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
if (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0 or getprop("systems/electrical/bus/dc-1") > 0 or getprop("systems/electrical/bus/dc-2") > 0) {
setprop("systems/electrical/nav-lights-power", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/electrical/nav-lights-power", 0);
2019-10-14 16:48:35 +00:00
}
if (setting == 0 and logo_lights == 1) {
logo_lights.setBoolValue(0);
2020-02-07 16:10:54 +00:00
} else if (setting == 1 or setting == 2 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0)) {
2019-10-14 16:48:35 +00:00
if ((wow) or (!wow and slats > 0)) {
logo_lights.setBoolValue(1);
} else {
logo_lights.setBoolValue(0);
}
} else {
logo_lights.setBoolValue(0);
}
2020-02-07 16:10:54 +00:00
if (setting == 1 or setting == 2 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0 or getprop("systems/electrical/bus/dc-1") > 0 or getprop("systems/electrical/bus/dc-2") > 0)) {
2019-10-14 16:48:35 +00:00
nav_lights.setBoolValue(1);
} else {
nav_lights.setBoolValue(0);
}
2020-02-07 16:10:54 +00:00
if (domeSetting == 0.5 and getprop("systems/electrical/bus/dc-ess") > 0) {
2019-10-14 16:48:35 +00:00
dome_light.setValue(0.5);
2020-02-07 16:10:54 +00:00
} elsif (domeSetting == 1 and getprop("systems/electrical/bus/dc-ess") > 0) {
2019-10-14 16:48:35 +00:00
dome_light.setValue(1);
} else {
dome_light.setValue(0);
}
# strobe
strobe_sw = strobe_switch.getValue();
2020-02-07 16:10:54 +00:00
if (strobe_sw == 1 and getprop("systems/electrical/bus/ac-2") > 0) {
2019-10-14 16:48:35 +00:00
strobe_light.setValue(1);
2020-02-07 16:10:54 +00:00
} elsif (strobe_sw == 0.5 and getprop("gear/gear[1]/wow") == 0 and getprop("gear/gear[2]/wow") == 0 and getprop("systems/electrical/bus/ac-2") > 0) {
2019-10-14 16:48:35 +00:00
# todo: use lgciu output 5
strobe_light.setValue(1);
} else {
strobe_light.setValue(0);
}
# beacon
2020-02-07 16:10:54 +00:00
if (beacon_switch.getValue() == 1 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0)) {
2019-10-14 16:48:35 +00:00
beacon_ctl.setValue(1);
} else {
beacon_ctl.setValue(0);
}
# wing
2020-02-07 16:10:54 +00:00
if (wing_switch.getValue() == 1 and (getprop("systems/electrical/bus/ac-1") > 0 or getprop("systems/electrical/bus/ac-2") > 0)) {
2019-10-14 16:48:35 +00:00
wing_ctl.setValue(1);
} else {
wing_ctl.setValue(0);
}
# landL
2020-02-07 16:10:54 +00:00
if (landlSw.getValue() == 1 and getprop("systems/electrical/bus/ac-1") > 0) {
2019-10-14 16:48:35 +00:00
landL.setValue(1);
} else {
landL.setValue(0);
}
2020-02-07 16:10:54 +00:00
if (landrSw.getValue() == 1 and getprop("systems/electrical/bus/ac-2") > 0) {
2019-10-14 16:48:35 +00:00
landR.setValue(1);
} else {
landR.setValue(0);
}
# signs
2020-02-07 16:10:54 +00:00
if (getprop("systems/pressurization/cabinalt-norm") > 11300) {
setprop("controls/lighting/seatbelt-sign", 1);
setprop("controls/lighting/no-smoking-sign", 1);
2019-10-14 16:48:35 +00:00
} else {
if (getprop("controls/switches/seatbelt-sign") == 1) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/lighting/seatbelt-sign") == 0) {
setprop("controls/lighting/seatbelt-sign", 1);
2019-10-14 16:48:35 +00:00
}
} elsif (getprop("controls/switches/seatbelt-sign") == 0) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/lighting/seatbelt-sign") == 1) {
setprop("controls/lighting/seatbelt-sign", 0);
2019-10-14 16:48:35 +00:00
}
}
if (getprop("controls/switches/no-smoking-sign") == 1) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/lighting/no-smoking-sign") == 0) {
setprop("controls/lighting/no-smoking-sign", 1);
2019-10-14 16:48:35 +00:00
}
} elsif (getprop("controls/switches/no-smoking-sign") == 0.5 and getprop("gear/gear[0]/position-norm") != 0) { # todo: should be when uplocks not engaged
2020-02-07 16:10:54 +00:00
if (getprop("controls/lighting/no-smoking-sign") == 0) {
setprop("controls/lighting/no-smoking-sign", 1);
2019-10-14 16:48:35 +00:00
}
} else {
2020-02-07 16:10:54 +00:00
setprop("controls/lighting/no-smoking-sign", 0); # sign stays on in cabin but sound still occurs
2019-10-14 16:48:35 +00:00
}
}
if (getprop("controls/lighting/landing-lights[1]") >= 0.5) {
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/rubbish/landL", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/rubbish/landL", 0);
2019-10-14 16:48:35 +00:00
}
if (getprop("controls/lighting/landing-lights[2]") >= 0.5) {
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/rubbish/landR", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/rubbish/landR", 0);
2019-10-14 16:48:35 +00:00
}
});
var lTray = func {
2020-02-07 16:10:54 +00:00
var lTrayCMD = getprop("controls/tray/lefttrayext");
2019-10-14 16:48:35 +00:00
if (lTrayCMD < 0.5) {
interpolate("/controls/tray/lefttrayext", 0.5, 0.5);
} else if (lTrayCMD == 0.5) {
interpolate("/controls/tray/lefttrayext", 1.0, 0.5);
} else {
interpolate("/controls/tray/lefttrayext", 0.0, 1.0);
}
}
var rTray = func {
2020-02-07 16:10:54 +00:00
var rTrayCMD = getprop("controls/tray/righttrayext");
2019-10-14 16:48:35 +00:00
if (rTrayCMD < 0.5) {
interpolate("/controls/tray/righttrayext", 0.5, 0.5);
} else if (rTrayCMD == 0.5) {
interpolate("/controls/tray/righttrayext", 1.0, 0.5);
} else {
interpolate("/controls/tray/righttrayext", 0.0, 1.0);
}
}
var l1Pedal = func {
2020-02-07 16:10:54 +00:00
var lPedalCMD = getprop("controls/footrest-cpt[0]");
2019-10-14 16:48:35 +00:00
if (lPedalCMD < 1.0) {
interpolate("/controls/footrest-cpt[0]", 1.0, 0.5);
} else {
interpolate("/controls/footrest-cpt[0]", 0.0, 0.5);
}
}
var l2Pedal = func {
2020-02-07 16:10:54 +00:00
var l2PedalCMD = getprop("controls/footrest-cpt[1]");
2019-10-14 16:48:35 +00:00
if (l2PedalCMD < 1.0) {
interpolate("/controls/footrest-cpt[1]", 1.0, 0.5);
} else {
interpolate("/controls/footrest-cpt[1]", 0.0, 0.5);
}
}
var r1Pedal = func {
2020-02-07 16:10:54 +00:00
var rPedalCMD = getprop("controls/footrest-fo[0]");
2019-10-14 16:48:35 +00:00
if (rPedalCMD < 1.0) {
interpolate("/controls/footrest-fo[0]", 1.0, 0.5);
} else {
interpolate("/controls/footrest-fo[0]", 0.0, 0.5);
}
}
var r2Pedal = func {
2020-02-07 16:10:54 +00:00
var r2PedalCMD = getprop("controls/footrest-fo[1]");
2019-10-14 16:48:35 +00:00
if (r2PedalCMD < 1.0) {
interpolate("/controls/footrest-fo[1]", 1.0, 0.5);
} else {
interpolate("/controls/footrest-fo[1]", 0.0, 0.5);
}
}
2020-02-07 16:10:54 +00:00
if (getprop("controls/flight/auto-coordination") == 1) {
setprop("controls/flight/auto-coordination", 0);
2019-11-09 16:29:57 +00:00
print("System: Auto Coordination has been turned off as it is not compatible with the fly-by-wire of this aircraft.");
screen.log.write("Auto Coordination has been disabled as it is not compatible with the fly-by-wire of this aircraft", 1, 0, 0);
}
2020-02-07 16:10:54 +00:00
setprop("controls/flight/aileron-drives-tiller", 0);
2019-10-14 16:48:35 +00:00
2019-10-27 20:54:00 +00:00
var APPanel = {
APDisc: func() {
fcu.FCUController.APDisc();
},
ATDisc: func() {
fcu.FCUController.ATDisc();
},
};
2020-01-05 20:22:41 +00:00
var resetView = func() {
if (getprop("sim/current-view/view-number") == 0) {
2020-02-07 16:10:54 +00:00
if (getprop("sim/rendering/headshake/enabled")) {
2020-01-05 20:22:41 +00:00
var _shakeFlag = 1;
2020-02-07 16:10:54 +00:00
setprop("sim/rendering/headshake/enabled", 0);
2020-01-05 20:22:41 +00:00
} else {
var _shakeFlag = 0;
}
var hd = getprop("sim/current-view/heading-offset-deg");
var hd_t = 360;
if (hd < 180) {
hd_t = hd_t - 360;
}
interpolate("sim/current-view/field-of-view", 63, 0.66);
2020-03-16 03:08:02 +00:00
interpolate("sim/current-view/heading-offset-deg", hd_t, 0.66);
interpolate("sim/current-view/pitch-offset-deg", -14.6, 0.66);
interpolate("sim/current-view/roll-offset-deg", 0, 0.66);
interpolate("sim/current-view/x-offset-m", -0.45, 0.66);
interpolate("sim/current-view/y-offset-m", 2.34, 0.66);
interpolate("sim/current-view/z-offset-m", -13.75, 0.66);
if (_shakeFlag) {
setprop("sim/rendering/headshake/enabled", 1);
}
}
}
var autopilotView = func() {
if (getprop("sim/current-view/view-number") == 0) {
if (getprop("sim/rendering/headshake/enabled")) {
var _shakeFlag = 1;
setprop("sim/rendering/headshake/enabled", 0);
} else {
var _shakeFlag = 0;
}
var hd = getprop("sim/current-view/heading-offset-deg");
var hd_t = 341.7;
if (hd < 180) {
hd_t = hd_t - 360;
}
interpolate("sim/current-view/field-of-view", 63, 0.66);
interpolate("sim/current-view/heading-offset-deg", hd_t, 0.66);
interpolate("sim/current-view/pitch-offset-deg", -16.4, 0.66);
interpolate("sim/current-view/roll-offset-deg", 0, 0.66);
interpolate("sim/current-view/x-offset-m", -0.45, 0.66);
interpolate("sim/current-view/y-offset-m", 2.34, 0.66);
interpolate("sim/current-view/z-offset-m", -13.75, 0.66);
if (_shakeFlag) {
setprop("sim/rendering/headshake/enabled", 1);
}
}
}
var overheadView = func() {
if (getprop("sim/current-view/view-number") == 0) {
if (getprop("sim/rendering/headshake/enabled")) {
var _shakeFlag = 1;
setprop("sim/rendering/headshake/enabled", 0);
} else {
var _shakeFlag = 0;
}
var hd = getprop("sim/current-view/heading-offset-deg");
var hd_t = 348;
if (hd < 180) {
hd_t = hd_t - 360;
}
interpolate("sim/current-view/field-of-view", 105.8, 0.66);
interpolate("sim/current-view/heading-offset-deg", hd_t, 0.66);
interpolate("sim/current-view/pitch-offset-deg", 65.25, 0.66);
2020-01-05 20:22:41 +00:00
interpolate("sim/current-view/roll-offset-deg", 0,0.66);
2020-03-16 03:08:02 +00:00
interpolate("sim/current-view/x-offset-m", -0.12, 0.66);
interpolate("sim/current-view/y-offset-m", 2.34, 0.66);
interpolate("sim/current-view/z-offset-m", -13.75, 0.66);
if (_shakeFlag) {
setprop("sim/rendering/headshake/enabled", 1);
}
}
}
var pedestalView = func() {
if (getprop("sim/current-view/view-number") == 0) {
if (getprop("sim/rendering/headshake/enabled")) {
var _shakeFlag = 1;
setprop("sim/rendering/headshake/enabled", 0);
} else {
var _shakeFlag = 0;
}
var hd = getprop("sim/current-view/heading-offset-deg");
var hd_t = 315;
if (hd < 180) {
hd_t = hd_t - 360;
}
interpolate("sim/current-view/field-of-view", 63, 0.66);
interpolate("sim/current-view/heading-offset-deg", hd_t, 0.66);
interpolate("sim/current-view/pitch-offset-deg", -46.3, 0.66);
interpolate("sim/current-view/roll-offset-deg", 0, 0.66);
interpolate("sim/current-view/x-offset-m", -0.45, 0.66);
interpolate("sim/current-view/y-offset-m", 2.34, 0.66);
interpolate("sim/current-view/z-offset-m", -13.75, 0.66);
if (_shakeFlag) {
setprop("sim/rendering/headshake/enabled", 1);
}
}
}
var lightsView = func() {
if (getprop("sim/current-view/view-number") == 0) {
if (getprop("sim/rendering/headshake/enabled")) {
var _shakeFlag = 1;
setprop("sim/rendering/headshake/enabled", 0);
} else {
var _shakeFlag = 0;
}
var hd = getprop("sim/current-view/heading-offset-deg");
2020-03-17 13:41:38 +00:00
var hd_t = 329;
2020-03-16 03:08:02 +00:00
if (hd < 180) {
hd_t = hd_t - 360;
}
interpolate("sim/current-view/field-of-view", 63, 0.66);
interpolate("sim/current-view/heading-offset-deg", hd_t, 0.66);
2020-03-17 13:41:38 +00:00
interpolate("sim/current-view/pitch-offset-deg", 17.533, 0.66);
2020-03-16 03:08:02 +00:00
interpolate("sim/current-view/roll-offset-deg", 0, 0.66);
2020-01-05 20:22:41 +00:00
interpolate("sim/current-view/x-offset-m", -0.45, 0.66);
interpolate("sim/current-view/y-offset-m", 2.34, 0.66);
interpolate("sim/current-view/z-offset-m", -13.75, 0.66);
if (_shakeFlag) {
2020-02-07 16:10:54 +00:00
setprop("sim/rendering/headshake/enabled", 1);
2020-01-05 20:22:41 +00:00
}
}
}
2020-02-07 16:10:54 +00:00
setprop("systems/acconfig/libraries-loaded", 1);