2020-04-27 13:58:38 +00:00
# A3XX FCU
2021-04-23 17:21:07 +00:00
# Copyright (c) 2021 Josh Davidson (Octal450), Jonathan Redpath (legoboyvdlp)
2019-10-27 20:54:00 +00:00
# Nodes
2020-07-09 01:12:02 +00:00
var fd1 = props.globals.getNode("/it-autoflight/output/fd1", 1);
var fd2 = props.globals.getNode("/it-autoflight/output/fd2", 1);
var ap1 = props.globals.getNode("/it-autoflight/output/ap1", 1);
var ap2 = props.globals.getNode("/it-autoflight/output/ap2", 1);
var athr = props.globals.getNode("/it-autoflight/output/athr", 1);
var fd1Input = props.globals.getNode("/it-autoflight/input/fd1", 1);
var fd2Input = props.globals.getNode("/it-autoflight/input/fd2", 1);
var ap1Input = props.globals.getNode("/it-autoflight/input/ap1", 1);
var ap2Input = props.globals.getNode("/it-autoflight/input/ap2", 1);
var athrInput = props.globals.getNode("/it-autoflight/input/athr", 1);
var ktsMach = props.globals.getNode("/it-autoflight/input/kts-mach", 1);
var iasSet = props.globals.getNode("/it-autoflight/input/kts", 1);
var machSet = props.globals.getNode("/it-autoflight/input/mach", 1);
var hdgSet = props.globals.getNode("/it-autoflight/input/hdg", 1);
var altSet = props.globals.getNode("/it-autoflight/input/alt", 1);
var altSetMode = props.globals.getNode("/it-autoflight/config/altitude-dial-mode", 1);
var vsSet = props.globals.getNode("/it-autoflight/input/vs", 1);
var fpaSet = props.globals.getNode("/it-autoflight/input/fpa", 1);
var iasNow = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-speed-kt", 1);
var machNow = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-mach", 1);
var spdManaged = props.globals.getNode("/it-autoflight/input/spd-managed", 1);
var showHDG = props.globals.getNode("/it-autoflight/custom/show-hdg", 1);
var trkFpaSW = props.globals.getNode("/it-autoflight/custom/trk-fpa", 1);
var latMode = props.globals.getNode("/it-autoflight/output/lat", 1);
var vertMode = props.globals.getNode("/it-autoflight/output/vert", 1);
var fpaModeInput = props.globals.getNode("/it-autoflight/input/fpa", 1);
var latModeInput = props.globals.getNode("/it-autoflight/input/lat", 1);
var vertModeInput = props.globals.getNode("/it-autoflight/input/vert", 1);
var vsModeInput = props.globals.getNode("/it-autoflight/input/vs", 1);
var locArm = props.globals.getNode("/it-autoflight/output/loc-armed", 1);
var apprArm = props.globals.getNode("/it-autoflight/output/appr-armed", 1);
2020-01-01 21:30:13 +00:00
var FCUworkingNode = props.globals.initNode("/FMGC/FCU-working", 0, "BOOL");
2021-04-29 21:18:20 +00:00
var SidestickPriorityPressedLast = 0;
2019-10-27 20:54:00 +00:00
var FCU = {
elecSupply: "",
failed: 0,
2019-10-29 14:03:36 +00:00
condition: 100,
2019-10-27 20:54:00 +00:00
new: func(elecNode) {
var f = { parents:[FCU] };
f.elecSupply = elecNode;
return f;
},
loop: func() {
2019-10-29 14:03:36 +00:00
me.failed = (me.elecSupply.getValue() < 25 or me.condition == 0) ? 1 : 0;
},
setFail: func() {
me.condition = 0;
},
restore: func() {
me.condition = 100;
2019-10-27 20:54:00 +00:00
},
};
var FCUController = {
FCU1: nil,
FCU2: nil,
2020-11-28 17:33:44 +00:00
activeFMGC: props.globals.getNode("/FMGC/active-fmgc-channel"),
2019-10-27 20:54:00 +00:00
FCUworking: 0,
2019-10-29 14:03:36 +00:00
_init: 0,
2019-10-27 20:54:00 +00:00
init: func() {
2019-12-28 17:38:20 +00:00
me.FCU1 = FCU.new(systems.ELEC.Bus.dcEss);
2019-10-27 20:54:00 +00:00
me.FCU2 = FCU.new(systems.ELEC.Bus.dc2);
2019-10-29 14:03:36 +00:00
me._init = 1;
2019-10-27 20:54:00 +00:00
},
2021-02-08 15:45:57 +00:00
loop: func(notification) {
2019-10-29 14:03:36 +00:00
if (me._init == 0) { return; }
2019-10-27 20:54:00 +00:00
# Update FCU Power
me.FCU1.loop();
me.FCU2.loop();
2020-01-01 21:30:13 +00:00
if (!me.FCU1.failed or !me.FCU2.failed) {
2019-10-27 20:54:00 +00:00
me.FCUworking = 1;
2020-01-01 21:30:13 +00:00
FCUworkingNode.setValue(1);
2019-10-27 20:54:00 +00:00
} else {
me.FCUworking = 0;
2020-01-01 21:30:13 +00:00
FCUworkingNode.setValue(0);
2019-10-27 20:54:00 +00:00
}
2019-11-30 13:39:53 +00:00
foreach (var update_item; me.update_items) {
2021-02-08 15:45:57 +00:00
update_item.update(notification);
2019-11-30 13:39:53 +00:00
}
2019-10-27 20:54:00 +00:00
},
2019-11-30 13:39:53 +00:00
update_items: [
2021-02-08 15:45:57 +00:00
props.UpdateManager.FromPropertyHashList(["/it-autoflight/output/fd1","/it-autoflight/output/fd2", "/it-autoflight/output/ap1", "/it-autoflight/output/ap2"], nil, func(notification)
2019-11-30 13:39:53 +00:00
{
updateActiveFMGC();
}
),
],
2019-10-29 14:03:36 +00:00
resetFail: func() {
if (me._init == 0) { return; }
me.FCU1.restore();
me.FCU2.restore();
},
2019-10-27 20:54:00 +00:00
AP1: func() {
2020-11-28 17:33:44 +00:00
if (me.FCUworking) {
if (!ap1.getBoolValue() and fbw.FBW.apOff == 0) {
2019-10-27 20:54:00 +00:00
ap1Input.setValue(1);
2020-05-16 20:04:03 +00:00
ecam.apWarnNode.setValue(0);
2020-07-16 18:50:01 +00:00
pts.Controls.Flight.rudderTrim.setValue(0);
2019-10-27 20:54:00 +00:00
} else {
apOff("hard", 1);
}
}
},
AP2: func() {
2020-11-28 17:33:44 +00:00
if (me.FCUworking) {
if (!ap2.getBoolValue() and fbw.FBW.apOff == 0) {
2019-10-27 20:54:00 +00:00
ap2Input.setValue(1);
2020-11-28 17:33:44 +00:00
ecam.apWarnNode.setValue(0);
2020-07-16 18:50:01 +00:00
pts.Controls.Flight.rudderTrim.setValue(0);
2019-10-27 20:54:00 +00:00
} else {
apOff("hard", 2);
}
}
},
ATHR: func() {
2020-11-28 17:33:44 +00:00
if (me.FCUworking) {
if (!athr.getBoolValue() and !pts.FMGC.CasCompare.casRejectAll.getBoolValue() and fbw.FBW.apOff == 0) {
2019-10-27 20:54:00 +00:00
athrInput.setValue(1);
} else {
athrOff("hard");
}
}
},
FD1: func() {
if (me.FCUworking) {
if (!fd1.getBoolValue()) {
fd1Input.setValue(1);
} else {
fd1Input.setValue(0);
}
}
},
FD2: func() {
if (me.FCUworking) {
if (!fd2.getBoolValue()) {
fd2Input.setValue(1);
} else {
fd2Input.setValue(0);
}
}
},
2021-04-29 21:18:20 +00:00
APDisc: func(side = 0, press = 0) {
# side: 0 = none, 1 = capt, 2 = fo
2020-04-18 15:39:55 +00:00
# physical button sound - so put it outside here as you get a sound even if it doesn't work!
setprop("/sim/sounde/apdiscbtn", 1);
settimer(func {
setprop("/sim/sounde/apdiscbtn", 0);
}, 0.5);
2019-10-27 20:54:00 +00:00
if (me.FCUworking) {
if (ap1.getBoolValue() or ap2.getBoolValue()) {
apOff("soft", 0);
2021-04-29 21:18:20 +00:00
} else if (getprop("/it-autoflight/sound/apoffsound") == 1 or getprop("/it-autoflight/sound/apoffsound2") == 1 or getprop("/it-autoflight/output/ap-warning") != 0) {
2021-04-30 12:32:41 +00:00
if (press == 1) {
if (getprop("/it-autoflight/sound/apoffsound") == 1 or getprop("/it-autoflight/sound/apoffsound2") == 1) {
setprop("/it-autoflight/sound/apoffsound", 0);
setprop("/it-autoflight/sound/apoffsound2", 0);
}
if (getprop("/it-autoflight/output/ap-warning") != 0) {
setprop("/it-autoflight/output/ap-warning", 0);
ecam.lights[0].setValue(0);
}
2019-12-28 15:53:17 +00:00
}
2021-04-29 21:18:20 +00:00
} else if (side != 0) {
if (press == 1) {
setprop("/fdm/jsbsim/fbw/sidestick/active[" ~ (2 - side) ~ "]", 0);
setprop("/fdm/jsbsim/fbw/sidestick/active[" ~ (side - 1) ~ "]", 1);
SidestickPriorityPressedLast = side;
2021-04-30 15:38:58 +00:00
if (side == 1) {
setprop("/sim/sound/priority-left", 1);
settimer(func {
setprop("/sim/sound/priority-left", 0);
}, 1.5);
} else {
setprop("/sim/sound/priority-right", 1);
settimer(func {
setprop("/sim/sound/priority-right", 0);
}, 1.5);
}
2021-04-29 21:18:20 +00:00
} else {
# Only release, if this side has pressed the button last
# to avoide the first pressed side getting activated again
# when released.
if (SidestickPriorityPressedLast == side) {
setprop("/fdm/jsbsim/fbw/sidestick/active[0]", 1);
setprop("/fdm/jsbsim/fbw/sidestick/active[1]", 1);
}
}
2019-10-27 20:54:00 +00:00
}
}
},
ATDisc: func() {
2020-04-18 15:39:55 +00:00
# physical button sound - so put it outside here as you get a sound even if it doesn't work!
setprop("/sim/sounde/apdiscbtn", 1);
settimer(func {
setprop("/sim/sounde/apdiscbtn", 0);
}, 0.5);
2019-10-27 20:54:00 +00:00
if (me.FCUworking) {
if (athr.getBoolValue()) {
athrOff("soft");
2020-09-15 17:41:40 +00:00
ecam.lights[1].setValue(1);
2019-10-27 20:54:00 +00:00
} else {
2020-09-15 17:41:40 +00:00
if (getprop("/it-autoflight/output/athr-warning") == 1) {
setprop("/it-autoflight/output/athr-warning", 0);
ecam.lights[1].setValue(0);
2019-10-27 20:54:00 +00:00
}
}
}
},
IASMach: func() {
if (me.FCUworking) {
if (ktsMach.getBoolValue()) {
ktsMach.setBoolValue(0);
} else {
ktsMach.setBoolValue(1);
}
}
},
SPDPush: func() {
if (me.FCUworking) {
2020-07-10 19:54:13 +00:00
if (fmgc.FMGCInternal.crzSet and fmgc.FMGCInternal.costIndexSet) {
2019-10-27 20:54:00 +00:00
spdManaged.setBoolValue(1);
fmgc.ManagedSPD.start();
}
}
},
SPDPull: func() {
if (me.FCUworking) {
spdManaged.setBoolValue(0);
fmgc.ManagedSPD.stop();
var ias = iasNow.getValue();
var mach = machNow.getValue();
if (!ktsMach.getBoolValue()) {
if (ias >= 100 and ias <= 350) {
iasSet.setValue(math.round(ias));
} else if (ias < 100) {
iasSet.setValue(100);
} else if (ias > 350) {
iasSet.setValue(350);
}
} else if (ktsMach.getBoolValue()) {
if (mach >= 0.50 and mach <= 0.82) {
machSet.setValue(math.round(mach, 0.001));
} else if (mach < 0.50) {
machSet.setValue(0.50);
} else if (mach > 0.82) {
machSet.setValue(0.82);
}
}
}
},
SPDAdjust: func(d) {
if (me.FCUworking) {
if (!spdManaged.getBoolValue()) {
if (ktsMach.getBoolValue()) {
var machTemp = machSet.getValue();
if (d == 1) {
machTemp = math.round(machTemp + 0.001, 0.001); # Kill floating point error
} else if (d == -1) {
machTemp = math.round(machTemp - 0.001, 0.001); # Kill floating point error
} else if (d == 10) {
machTemp = math.round(machTemp + 0.01, 0.01); # Kill floating point error
} else if (d == -10) {
machTemp = math.round(machTemp - 0.01, 0.01); # Kill floating point error
}
if (machTemp < 0.50) {
machSet.setValue(0.50);
} else if (machTemp > 0.82) {
machSet.setValue(0.82);
} else {
machSet.setValue(machTemp);
}
} else {
var iasTemp = iasSet.getValue();
if (d == 1) {
iasTemp = iasTemp + 1;
} else if (d == -1) {
iasTemp = iasTemp - 1;
} else if (d == 10) {
iasTemp = iasTemp + 10;
} else if (d == -10) {
iasTemp = iasTemp - 10;
}
if (iasTemp < 100) {
iasSet.setValue(100);
} else if (iasTemp > 350) {
iasSet.setValue(350);
} else {
iasSet.setValue(iasTemp);
}
}
}
}
},
HDGPush: func() {
if (me.FCUworking) {
if (fd1.getBoolValue() or fd2.getBoolValue() or ap1.getBoolValue() or ap2.getBoolValue()) {
latModeInput.setValue(1);
}
}
},
HDGPull: func() {
if (me.FCUworking) {
if (fd1.getBoolValue() or fd2.getBoolValue() or ap1.getBoolValue() or ap2.getBoolValue()) {
if (latMode.getValue() == 0 or !showHDG.getBoolValue()) {
latModeInput.setValue(3);
} else {
latModeInput.setValue(0);
}
}
}
},
HDGAdjust: func(d) {
if (me.FCUworking) {
if (latMode.getValue() != 0) {
hdgInput();
}
if (showHDG.getBoolValue()) {
var hdgTemp = hdgSet.getValue();
if (d == 1) {
hdgTemp = hdgTemp + 1;
} else if (d == -1) {
hdgTemp = hdgTemp - 1;
} else if (d == 10) {
hdgTemp = hdgTemp + 10;
} else if (d == -10) {
hdgTemp = hdgTemp - 10;
}
if (hdgTemp < 0.5) {
hdgSet.setValue(hdgTemp + 360);
} else if (hdgTemp >= 360.5) {
hdgSet.setValue(hdgTemp - 360);
} else {
hdgSet.setValue(hdgTemp);
}
}
}
},
LOCButton: func() {
if (me.FCUworking) {
var vertTemp = vertMode.getValue();
if ((locArm.getBoolValue() or latMode.getValue() == 2) and !apprArm.getBoolValue() and vertTemp != 2 and vertTemp != 6) {
if (latMode.getValue() == 2) {
latModeInput.setValue(0);
} else {
2020-12-22 18:41:07 +00:00
fmgc.ITAF.disarmLoc();
2019-10-27 20:54:00 +00:00
}
if (vertTemp == 2 or vertTemp == 6) {
me.VSPull();
} else {
2020-12-22 18:41:07 +00:00
fmgc.ITAF.disarmAppr();
2019-10-27 20:54:00 +00:00
}
} else {
2020-07-16 00:05:41 +00:00
if (pts.Position.gearAglFt.getValue() >= 400 and vertTemp != 7) {
latModeInput.setValue(2);
if (vertTemp == 2 or vertTemp == 6) {
me.VSPull();
} else {
2020-12-22 18:41:07 +00:00
fmgc.ITAF.disarmAppr();
2020-07-16 00:05:41 +00:00
}
2019-10-27 20:54:00 +00:00
}
}
}
},
TRKFPA: func() {
if (me.FCUworking) {
fmgc.ITAF.toggleTrkFpa();
}
},
ALTPush: func() {
if (me.FCUworking) {
2020-09-15 17:41:40 +00:00
# setprop("/it-autoflight/input/vert", 8); # He don't work yet m8
2019-10-27 20:54:00 +00:00
}
},
ALTPull: func() {
if (me.FCUworking) {
vertModeInput.setValue(4);
}
},
ALTAdjust: func(d) {
if (me.FCUworking) {
var altTemp = altSet.getValue();
if (d == 1) {
if (altSetMode.getBoolValue()) {
altTemp = altTemp + 1000;
} else {
altTemp = altTemp + 100;
}
} else if (d == -1) {
if (altSetMode.getBoolValue()) {
altTemp = altTemp - 1000;
} else {
altTemp = altTemp - 100;
}
} else if (d == 2) {
altTemp = altTemp + 100;
} else if (d == -2) {
altTemp = altTemp - 100;
} else if (d == 10) {
altTemp = altTemp + 1000;
} else if (d == -10) {
altTemp = altTemp - 1000;
}
2020-11-21 20:54:28 +00:00
if (altTemp < 100) {
altSet.setValue(100);
} else if (altTemp > 49000) {
altSet.setValue(49000);
2019-10-27 20:54:00 +00:00
} else {
altSet.setValue(altTemp);
}
}
},
VSPush: func() {
if (me.FCUworking) {
if (trkFpaSW.getBoolValue()) {
vertModeInput.setValue(5);
fpaModeInput.setValue(0);
} else {
vertModeInput.setValue(1);
vsModeInput.setValue(0);
}
}
},
VSPull: func() {
if (me.FCUworking) {
if (trkFpaSW.getBoolValue()) {
vertModeInput.setValue(5);
} else {
vertModeInput.setValue(1);
}
}
},
VSAdjust: func(d) {
if (me.FCUworking) {
if (vertMode.getValue() == 1) {
var vsTemp = vsSet.getValue();
if (d == 1) {
vsTemp = vsTemp + 100;
} else if (d == -1) {
vsTemp = vsTemp - 100;
} else if (d == 10) {
vsTemp = vsTemp + 1000;
} else if (d == -10) {
vsTemp = vsTemp - 1000;
}
if (vsTemp < -6000) {
vsSet.setValue(-6000);
} else if (vsTemp > 6000) {
vsSet.setValue(6000);
} else {
vsSet.setValue(vsTemp);
}
} else if (vertMode.getValue() == 5) {
var fpaTemp = fpaSet.getValue();
if (d == 1) {
fpaTemp = math.round(fpaTemp + 0.1, 0.1);
} else if (d == -1) {
fpaTemp = math.round(fpaTemp - 0.1, 0.1);
} else if (d == 10) {
fpaTemp = fpaTemp + 1;
} else if (d == -10) {
fpaTemp = fpaTemp - 1;
}
if (fpaTemp < -9.9) {
fpaSet.setValue(-9.9);
} else if (fpaTemp > 9.9) {
fpaSet.setValue(9.9);
} else {
fpaSet.setValue(fpaTemp);
}
}
if ((vertMode.getValue() != 1 and !trkFpaSW.getBoolValue()) or (vertMode.getValue() != 5 and trkFpaSW.getBoolValue())) {
me.VSPull();
}
}
},
APPRButton: func() {
if (me.FCUworking) {
var vertTemp = vertMode.getValue();
if ((locArm.getBoolValue() or latMode.getValue() == 2) and (apprArm.getBoolValue() or vertTemp == 2 or vertTemp == 6)) {
if (latMode.getValue() == 2) {
latModeInput.setValue(0);
} else {
2020-12-22 18:41:07 +00:00
fmgc.ITAF.disarmLoc();
2019-10-27 20:54:00 +00:00
}
if (vertTemp == 2 or vertTemp == 6) {
me.VSPull();
} else {
2020-12-22 18:41:07 +00:00
fmgc.ITAF.disarmAppr();
2019-10-27 20:54:00 +00:00
}
} else {
2020-07-16 11:32:26 +00:00
if (pts.Position.gearAglFt.getValue() >= 400 and vertTemp != 7) {
vertModeInput.setValue(2);
}
2019-10-27 20:54:00 +00:00
}
}
},
};
2019-11-30 13:39:53 +00:00
# Master / slave principle of operation depending on the autopilot / flight director engagement
var updateActiveFMGC = func {
if (ap1.getBoolValue()) {
FCUController.activeFMGC.setValue(1);
} elsif (ap2.getBoolValue()) {
FCUController.activeFMGC.setValue(2);
} elsif (fd1.getBoolValue()) {
FCUController.activeFMGC.setValue(1);
} elsif (fd2.getBoolValue()) {
FCUController.activeFMGC.setValue(2);
} else {
FCUController.activeFMGC.setValue(1);
}
}
2019-10-27 20:54:00 +00:00
# Autopilot Disconnection
var apOff = func(type, side) {
2020-01-02 21:13:18 +00:00
if ((ap1Input.getValue() and (side == 1 or side == 0)) or (ap2Input.getValue() and (side == 2 or side == 0))) {
2020-05-16 20:04:03 +00:00
ecam.doApWarn(type);
2020-01-02 21:13:18 +00:00
}
2019-10-27 20:54:00 +00:00
if (side == 0) {
ap1Input.setValue(0);
ap2Input.setValue(0);
} elsif (side == 1) {
ap1Input.setValue(0);
} elsif (side == 2) {
ap2Input.setValue(0);
}
}
# Autothrust Disconnection
var athrOff = func(type) {
2020-01-02 21:13:18 +00:00
if (athrInput.getValue() == 1) {
if (type == "hard") {
2021-04-27 12:34:07 +00:00
systems.lockThr();
2020-01-02 21:13:18 +00:00
}
athrInput.setValue(0);
2020-05-16 20:04:03 +00:00
ecam.doAthrWarn(type);
2019-10-27 20:54:00 +00:00
}
}
# If the heading knob is turned while in nav mode, it will display heading for a period of time
var hdgInput = func {
if (latMode.getValue() != 0) {
showHDG.setBoolValue(1);
2020-09-27 18:00:46 +00:00
var hdgnow = fmgc.Input.hdg.getValue();
fmgc.Custom.hdgTime.setValue(pts.Sim.Time.elapsedSec.getValue());
2019-10-27 20:54:00 +00:00
}
2020-04-27 13:58:38 +00:00
}