diff --git a/fbw-a32nx/src/systems/instruments/src/EWD/PseudoFWC.ts b/fbw-a32nx/src/systems/instruments/src/EWD/PseudoFWC.ts new file mode 100644 index 00000000000..c5cd2d4cf5e --- /dev/null +++ b/fbw-a32nx/src/systems/instruments/src/EWD/PseudoFWC.ts @@ -0,0 +1,2197 @@ +import { Subject, Subscribable, MappedSubject, ArraySubject } from 'msfssdk'; + +import { Arinc429Word } from '@shared/arinc429'; +import { NXLogicClockNode, NXLogicConfirmNode, NXLogicMemoryNode } from '@instruments/common/NXLogic'; +import { NXDataStore } from '@shared/persistence'; + +interface EWDItem { + flightPhaseInhib: number[], + simVarIsActive: Subscribable, + whichCodeToReturn: () => any[], + codesToReturn: string[], + memoInhibit: () => boolean, + failure: number, + sysPage: number, + side: string +} + +interface EWDMessageDict { + [key: string] : EWDItem +} + +export class PseudoFWC { + /* PSEUDO FWC VARIABLES */ + + private readonly allCurrentFailures: string[] = []; + + private readonly failuresLeft: string[] = []; + + private readonly failuresRight: string[] = []; + + private memoMessageLeft: ArraySubject = ArraySubject.create([]); + + private memoMessageRight: ArraySubject = ArraySubject.create([]); + + private recallFailures: string[] = []; + + /* PRESSURIZATION */ + + private readonly apuBleedValveOpen = Subject.create(false); + + private readonly cabAltSetReset1 = new NXLogicMemoryNode(); + + private readonly cabAltSetReset2 = new NXLogicMemoryNode(); + + private readonly cabAltSetResetState1 = Subject.create(false); + + private readonly cabAltSetResetState2 = Subject.create(false); + + private readonly excessPressure = Subject.create(false); + + private readonly packOffBleedAvailable1 = new NXLogicConfirmNode(5, false); + + private readonly packOffBleedAvailable2 = new NXLogicConfirmNode(5, false); + + private readonly packOffNotFailed1 = new NXLogicConfirmNode(60); + + private readonly packOffNotFailed1Status = Subject.create(false); + + private readonly packOffNotFailed2 = new NXLogicConfirmNode(60); + + private readonly packOffNotFailed2Status = Subject.create(false); + + /* ELECTRICAL */ + + private readonly ac1BusPowered = Subject.create(false); + + private readonly ac2BusPowered = Subject.create(false); + + private readonly acESSBusPowered = Subject.create(false); + + private readonly dcESSBusPowered = Subject.create(false); + + private readonly dc2BusPowered = Subject.create(false); + + /* FLIGHT CONTROLS */ + + private readonly altn1LawConfirmNode = new NXLogicConfirmNode(0.3, true); + + private readonly altn1LawConfirmNodeOutput = Subject.create(false); + + private readonly altn2LawConfirmNode = new NXLogicConfirmNode(0.3, true); + + private readonly altn2LawConfirmNodeOutput = Subject.create(false); + + private readonly directLawCondition = Subject.create(false); + + private readonly elac1HydConfirmNode = new NXLogicConfirmNode(3, false); + + private readonly elac1FaultConfirmNode = new NXLogicConfirmNode(0.6, true); + + private readonly elac1FaultConfirmNodeOutput = Subject.create(false); + + private readonly elac1FaultLine123Display = Subject.create(false); + + private readonly elac1FaultLine45Display = Subject.create(false); + + private readonly elac1HydConfirmNodeOutput = Subject.create(false); + + private readonly elac2FaultConfirmNode = new NXLogicConfirmNode(0.6, true); + + private readonly elac2FaultConfirmNodeOutput = Subject.create(false); + + private readonly elac2FaultLine123Display = Subject.create(false); + + private readonly elac2FaultLine45Display = Subject.create(false); + + private readonly elac2HydConfirmNode = new NXLogicConfirmNode(3, false); + + private readonly elac2HydConfirmNodeOutput = Subject.create(false); + + private readonly fcdc1FaultCondition = Subject.create(false); + + private readonly fcdc12FaultCondition = Subject.create(false); + + private readonly fcdc2FaultCondition = Subject.create(false); + + private readonly flapsAngle = Subject.create(0); + + private readonly flapsHandle = Subject.create(0); + + private readonly flapsMcdu = Subject.create(0); + + private readonly flapsMcduEntered = Subject.create(false); + + private readonly lrElevFaultCondition = Subject.create(false); + + private readonly sec1FaultCondition = Subject.create(false); + + private readonly sec2FaultCondition = Subject.create(false); + + private readonly sec3FaultCondition = Subject.create(false); + + private readonly sec1FaultLine123Display = Subject.create(false); + + private readonly sec1FaultLine45Display = Subject.create(false); + + private readonly sec2FaultLine123Display = Subject.create(false); + + private readonly sec3FaultLine123Display = Subject.create(false); + + private readonly showLandingInhibit = Subject.create(false); + + private readonly showTakeoffInhibit = Subject.create(false); + + private readonly slatsAngle = Subject.create(0); + + private readonly speedBrakeCommand = Subject.create(false); + + private readonly spoilersArmed = Subject.create(false); + + private readonly toConfigFail = Subject.create(false); + + /* FUEL */ + + private readonly fuelXFeedPBOn = Subject.create(false); + + private readonly leftOuterInnerValve = Subject.create(0); + + private readonly rightOuterInnerValve = Subject.create(0); + + /* HYDRAULICS */ + + private readonly blueElecPumpPBAuto = Subject.create(false); + + private readonly blueLP = Subject.create(false); + + private readonly blueRvrLow = Subject.create(false); + + private readonly blueRvrOvht = Subject.create(false); + + private readonly eng1pumpPBisAuto = Subject.create(false); + + private readonly eng2pumpPBisAuto = Subject.create(false); + + private readonly greenHydEng1PBAuto = Subject.create(false); + + private readonly greenLP = Subject.create(false); + + private readonly greenRvrOvht = Subject.create(false); + + private readonly hydPTU = Subject.create(false); + + private readonly ptuAuto = Subject.create(false); + + private readonly ratDeployed = Subject.create(0); + + private readonly yellowLP = Subject.create(false); + + private readonly yellowRvrOvht = Subject.create(false); + + private readonly yepumpPBisAuto = Subject.create(false); + + /* FWS */ + + private readonly fwcFlightPhase = Subject.create(-1); + + private readonly ldgInhibitTimer = new NXLogicConfirmNode(3); + + private readonly toInhibitTimer = new NXLogicConfirmNode(3); + + /* LANDING GEAR AND LIGHTS */ + + private readonly aircraftOnGround = Subject.create(0); + + private readonly antiskidActive = Subject.create(false); + + private readonly brakeFan = Subject.create(false); + + private readonly brakesHot = Subject.create(false); + + private readonly landingLight2Retracted = Subject.create(false); + + private readonly landingLight3Retracted = Subject.create(false); + + private readonly lgciu1Fault = Subject.create(false); + + private readonly lgciu2Fault = Subject.create(false); + + private readonly nwSteeringDisc = Subject.create(false); + + private readonly parkBrake = Subject.create(false); + + /* NAVIGATION */ + + private readonly adirsRemainingAlignTime = Subject.create(0); + + private readonly adiru1State = Subject.create(0); + + private readonly adiru2State = Subject.create(0); + + private readonly adiru3State = Subject.create(0); + + private readonly computedAirSpeed = Subject.create(Arinc429Word.empty()); + + private readonly computedAirSpeedToNearest2 = this.computedAirSpeed.map((it) => Math.round(it.value / 2) * 2); + + private readonly height1Failed = Subject.create(false); + + private readonly height2Failed = Subject.create(false); + + private readonly flapsIndex = Subject.create(0); + + /** ENGINE AND THROTTLE */ + + private readonly engine1State = Subject.create(0); + + private readonly engine2State = Subject.create(0); + + private readonly N1Eng1 = Subject.create(0); + + private readonly N1Eng2 = Subject.create(0); + + private readonly N1IdleEng1 = Subject.create(0); + + private readonly N1IdleEng2 = Subject.create(0); + + private readonly N1AboveIdle = MappedSubject.create(([n1, idleN1]) => Math.floor(n1) > idleN1, this.N1Eng1, this.N1IdleEng1); + + private readonly N2AboveIdle = MappedSubject.create(([n1, idleN1]) => Math.floor(n1) > idleN1, this.N1Eng2, this.N1IdleEng2); + + private readonly engDualFault = Subject.create(false); + + private readonly engine1Generator = Subject.create(false); + + private readonly engine2Generator = Subject.create(false); + + private readonly emergencyElectricGeneratorPotential = Subject.create(0); + + private readonly emergencyGeneratorOn = this.emergencyElectricGeneratorPotential.map((it) => it > 0); + + private readonly apuMasterSwitch = Subject.create(0); + + private readonly apuAvail = Subject.create(0); + + private readonly radioAlt = Subject.create(0); + + private readonly fac1Failed = Subject.create(0); + + private readonly toMemo = Subject.create(0); + + private readonly ldgMemo = Subject.create(0); + + private readonly autoBrake = Subject.create(0); + + private readonly fuel = Subject.create(0); + + private readonly usrStartRefueling = Subject.create(0); + + private readonly engSelectorPosition = Subject.create(0); + + private readonly eng1AntiIce = Subject.create(false); + + private readonly eng2AntiIce = Subject.create(false); + + private readonly throttle1Position = Subject.create(0); + + private readonly throttle2Position = Subject.create(0); + + private readonly engine1ValueSwitch = Subject.create(false); + + private readonly engine2ValueSwitch = Subject.create(false); + + private readonly autoThrustStatus = Subject.create(0); + + private readonly autothrustLeverWarningFlex = Subject.create(false); + + private readonly autothrustLeverWarningToga = Subject.create(false); + + private readonly thrustLeverNotSet = Subject.create(false); + + /* FIRE */ + + private readonly agent1Eng1Discharge = Subject.create(0); + + private readonly agent1Eng1DischargeTimer = new NXLogicClockNode(10, 0); + + private readonly agent2Eng1Discharge = Subject.create(0); + + private readonly agent2Eng1DischargeTimer = new NXLogicClockNode(30, 0); + + private readonly agent1Eng2Discharge = Subject.create(0); + + private readonly agent1Eng2DischargeTimer = new NXLogicClockNode(10, 0); + + private readonly agent2Eng2Discharge = Subject.create(0); + + private readonly agent2Eng2DischargeTimer = new NXLogicClockNode(30, 0); + + private readonly agentAPUDischarge = Subject.create(0); + + private readonly agentAPUDischargeTimer = new NXLogicClockNode(10, 0); + + private readonly apuAgentPB = Subject.create(false); + + private readonly apuFireTest = Subject.create(false); + + private readonly cargoFireAgentDisch = Subject.create(false); + + private readonly cargoFireTest = Subject.create(false); + + private readonly eng1Agent1PB = Subject.create(false); + + private readonly eng1Agent2PB = Subject.create(false); + + private readonly eng1FireTest = Subject.create(false); + + private readonly eng2Agent1PB = Subject.create(false); + + private readonly eng2Agent2PB = Subject.create(false); + + private readonly eng2FireTest = Subject.create(false); + + private readonly fireButton1 = Subject.create(false); + + private readonly fireButton2 = Subject.create(false); + + private readonly fireButtonAPU = Subject.create(false); + + /* ICE */ + + private readonly iceDetectedTimer1 = new NXLogicConfirmNode(40, false); + + private readonly iceDetectedTimer2 = new NXLogicConfirmNode(5); + + private readonly iceDetectedTimer2Status = Subject.create(false); + + private readonly iceNotDetTimer1 = new NXLogicConfirmNode(60); + + private readonly iceNotDetTimer2 = new NXLogicConfirmNode(130); + + private readonly iceNotDetTimer2Status = Subject.create(false); + + private readonly iceSevereDetectedTimer = new NXLogicConfirmNode(40, false); + + private readonly iceSevereDetectedTimerStatus = Subject.create(false); + + /* OTHER STUFF */ + + private readonly airKnob = Subject.create(0); + + private readonly attKnob = Subject.create(0); + + private readonly compMesgCount = Subject.create(0); + + private readonly dmcSwitchingKnob = Subject.create(0); + + private readonly gpwsFlaps3 = Subject.create(false); + + private readonly gpwsFlapMode = Subject.create(0); + + private readonly gpwsTerrOff = Subject.create(false); + + private readonly landAsapRed = Subject.create(false); + + private readonly ndXfrKnob = Subject.create(0); + + private readonly manLandingElevation = Subject.create(0); + + private readonly noSmoking = Subject.create(0); + + private readonly noSmokingSwitchPosition = Subject.create(0); + + private readonly predWSOn = Subject.create(false); + + private readonly seatBelt = Subject.create(0); + + private readonly strobeLightsOn = Subject.create(0); + + private readonly tcasFault = Subject.create(false); + + private readonly tcasSensitivity = Subject.create(0); + + private readonly toConfigNormal = Subject.create(false); + + private readonly wingAntiIce = Subject.create(false); + + private readonly voiceVhf3 = Subject.create(0); + + /* SETTINGS */ + + private readonly configPortableDevices = Subject.create(false); + + constructor() { + this.memoMessageLeft.sub((_i, _t, _v) => { + [1, 2, 3, 4, 5, 6, 7].forEach((value) => { + SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_LEFT_LINE_${value}`, 'string', ''); + }); + this.memoMessageLeft.getArray().forEach((value, index) => { + SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_LEFT_LINE_${index + 1}`, 'string', value); + }); + }); + + this.memoMessageRight.sub((_i, _t, _v) => { + [1, 2, 3, 4, 5, 6, 7].forEach((value) => { + SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_RIGHT_LINE_${value}`, 'string', ''); + }); + this.memoMessageRight.getArray().forEach((value, index) => { + SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_RIGHT_LINE_${index + 1}`, 'string', value); + }); + }); + + SimVar.SetSimVarValue('L:A32NX_STATUS_LEFT_LINE_8', 'string', '000000001'); + } + + masterWarning(toggle: number) { + SimVar.SetSimVarValue('L:A32NX_MASTER_WARNING', 'Bool', toggle); + SimVar.SetSimVarValue('L:Generic_Master_Warning_Active', 'Bool', toggle); + } + + masterCaution(toggle: number) { + SimVar.SetSimVarValue('L:A32NX_MASTER_CAUTION', 'Bool', toggle); + SimVar.SetSimVarValue('L:Generic_Master_Caution_Active', 'Bool', toggle); + } + + mapOrder(array, order): [] { + array.sort((a, b) => { + if (order.indexOf(a) > order.indexOf(b)) { + return 1; + } + return -1; + }); + return array; + } + + private adirsMessage1(adirs, engineRunning) { + let rowChoice = 0; + + switch (true) { + case (Math.ceil(adirs / 60) >= 7 && !engineRunning): + rowChoice = 0; + break; + case (Math.ceil(adirs / 60) >= 7 && engineRunning): + rowChoice = 1; + break; + case (Math.ceil(adirs / 60) === 6 && !engineRunning): + rowChoice = 2; + break; + case (Math.ceil(adirs / 60) === 6 && engineRunning): + rowChoice = 3; + break; + case (Math.ceil(adirs / 60) === 5 && !engineRunning): + rowChoice = 4; + break; + case (Math.ceil(adirs / 60) === 5 && engineRunning): + rowChoice = 5; + break; + case (Math.ceil(adirs / 60) === 4 && !engineRunning): + rowChoice = 6; + break; + case (Math.ceil(adirs / 60) === 4 && engineRunning): + rowChoice = 7; + break; + default: + break; + } + + return rowChoice; + } + + private adirsMessage2(adirs, engineRunning) { + let rowChoice = 0; + + switch (true) { + case (Math.ceil(adirs / 60) === 3 && !engineRunning): + rowChoice = 0; + break; + case (Math.ceil(adirs / 60) === 3 && engineRunning): + rowChoice = 1; + break; + case (Math.ceil(adirs / 60) === 2 && !engineRunning): + rowChoice = 2; + break; + case (Math.ceil(adirs / 60) === 2 && engineRunning): + rowChoice = 3; + break; + case (Math.ceil(adirs / 60) === 1 && !engineRunning): + rowChoice = 4; + break; + case (Math.ceil(adirs / 60) === 1 && engineRunning): + rowChoice = 5; + break; + default: + break; + } + + return rowChoice; + } + + onUpdate(deltaTime) { + // Inputs update + + const flightPhaseInhibitOverride = SimVar.GetSimVarValue('L:A32NX_FWC_INHIBOVRD', 'bool'); + + this.fwcFlightPhase.set(SimVar.GetSimVarValue('L:A32NX_FWC_FLIGHT_PHASE', 'Enum')); + + this.showTakeoffInhibit.set(this.toInhibitTimer.write([3, 4, 5].includes(this.fwcFlightPhase.get()) && !flightPhaseInhibitOverride, deltaTime)); + this.showLandingInhibit.set(this.ldgInhibitTimer.write([7, 8].includes(this.fwcFlightPhase.get()) && !flightPhaseInhibitOverride, deltaTime)); + + this.flapsIndex.set(SimVar.GetSimVarValue('L:A32NX_FLAPS_CONF_INDEX', 'number')); + + this.computedAirSpeed.set(Arinc429Word.fromSimVarValue('L:A32NX_ADIRS_ADR_1_COMPUTED_AIRSPEED')); + + /* ENGINE AND THROTTLE */ + + this.engine1State.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_STATE:1', 'Enum')); + this.engine2State.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_STATE:2', 'Enum')); + this.N1Eng1.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_N1:1', 'number')); + this.N1Eng2.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_N1:2', 'number')); + this.N1IdleEng1.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_IDLE_N1:1', 'number')); + this.N1IdleEng2.set(SimVar.GetSimVarValue('L:A32NX_ENGINE_IDLE_N1:2', 'number')); + + this.engine1Generator.set(SimVar.GetSimVarValue('L:A32NX_ELEC_ENG_GEN_1_POTENTIAL_NORMAL', 'bool')); + this.engine2Generator.set(SimVar.GetSimVarValue('L:A32NX_ELEC_ENG_GEN_2_POTENTIAL_NORMAL', 'bool')); + this.emergencyElectricGeneratorPotential.set(SimVar.GetSimVarValue('L:A32NX_ELEC_EMER_GEN_POTENTIAL', 'number')); + + this.apuMasterSwitch.set(SimVar.GetSimVarValue('L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON', 'bool')); + + this.apuAvail.set(SimVar.GetSimVarValue('L:A32NX_OVHD_APU_START_PB_IS_AVAILABLE', 'bool')); + this.apuBleedValveOpen.set(SimVar.GetSimVarValue('L:A32NX_APU_BLEED_AIR_VALVE_OPEN', 'bool')); + + this.radioAlt.set(SimVar.GetSimVarValue('PLANE ALT ABOVE GROUND MINUS CG', 'feet')); + + this.fac1Failed.set(SimVar.GetSimVarValue('L:A32NX_FBW_FAC_FAILED:1', 'boost psi')); + + this.toMemo.set(SimVar.GetSimVarValue('L:A32NX_FWC_TOMEMO', 'bool')); + + this.autoBrake.set(SimVar.GetSimVarValue('L:A32NX_AUTOBRAKES_ARMED_MODE', 'enum')); + + this.ldgMemo.set(SimVar.GetSimVarValue('L:A32NX_FWC_LDGMEMO', 'bool')); + + this.fuel.set(SimVar.GetSimVarValue('A:INTERACTIVE POINT OPEN:9', 'percent')); + this.usrStartRefueling.set(SimVar.GetSimVarValue('L:A32NX_REFUEL_STARTED_BY_USR', 'bool')); + this.engSelectorPosition.set(SimVar.GetSimVarValue('L:XMLVAR_ENG_MODE_SEL', 'Enum')); + this.eng1AntiIce.set(SimVar.GetSimVarValue('ENG ANTI ICE:1', 'bool')); + this.eng2AntiIce.set(SimVar.GetSimVarValue('ENG ANTI ICE:2', 'bool')); + this.throttle1Position.set(SimVar.GetSimVarValue('L:A32NX_AUTOTHRUST_TLA:1', 'number')); + this.throttle2Position.set(SimVar.GetSimVarValue('L:A32NX_AUTOTHRUST_TLA:2', 'number')); + this.engine1ValueSwitch.set(SimVar.GetSimVarValue('FUELSYSTEM VALVE SWITCH:1', 'bool')); + this.engine2ValueSwitch.set(SimVar.GetSimVarValue('FUELSYSTEM VALVE SWITCH:2', 'bool')); + this.autoThrustStatus.set(SimVar.GetSimVarValue('L:A32NX_AUTOTHRUST_STATUS', 'enum')); + this.autothrustLeverWarningFlex.set(SimVar.GetSimVarValue('L:A32NX_AUTOTHRUST_THRUST_LEVER_WARNING_FLEX', 'bool')); + this.autothrustLeverWarningToga.set(SimVar.GetSimVarValue('L:A32NX_AUTOTHRUST_THRUST_LEVER_WARNING_TOGA', 'bool')); + this.thrustLeverNotSet.set(this.autothrustLeverWarningFlex.get() || this.autothrustLeverWarningToga.get()); + + this.engDualFault.set(!this.aircraftOnGround.get() && ( + (this.fireButton1.get() && this.fireButton2.get()) + || (!this.engine1ValueSwitch.get() && !this.engine2ValueSwitch.get()) + || (this.engine1State.get() === 0 && this.engine2State.get() === 0) + || (!this.N1AboveIdle.get() && !this.N2AboveIdle.get()) + )); + + /* HYDRAULICS */ + + this.blueElecPumpPBAuto.set(SimVar.GetSimVarValue('L:A32NX_OVHD_HYD_EPUMPB_PB_IS_AUTO', 'bool')); + this.blueLP.set(SimVar.GetSimVarValue('L:A32NX_HYD_BLUE_EDPUMP_LOW_PRESS', 'bool')); + this.blueRvrLow.set(SimVar.GetSimVarValue('L:A32NX_HYD_BLUE_RESERVOIR_LEVEL_IS_LOW', 'bool')); + this.blueRvrOvht.set(SimVar.GetSimVarValue('L:A32NX_HYD_BLUE_RESERVOIR_OVHT', 'bool')); + this.eng1pumpPBisAuto.set(SimVar.GetSimVarValue('L:A32NX_OVHD_HYD_ENG_1_PUMP_PB_IS_AUTO', 'bool')); + this.eng2pumpPBisAuto.set(SimVar.GetSimVarValue('L:A32NX_OVHD_HYD_ENG_2_PUMP_PB_IS_AUTO', 'bool')); + this.greenLP.set(SimVar.GetSimVarValue('L:A32NX_HYD_GREEN_EDPUMP_LOW_PRESS', 'bool')); + this.greenRvrOvht.set(SimVar.GetSimVarValue('L:A32NX_HYD_GREEN_RESERVOIR_OVHT', 'bool')); + this.hydPTU.set(SimVar.GetSimVarValue('L:A32NX_HYD_PTU_ON_ECAM_MEMO', 'Bool')); + this.ptuAuto.set(SimVar.GetSimVarValue('L:A32NX_OVHD_HYD_PTU_PB_IS_AUTO', 'bool')); + this.ratDeployed.set(SimVar.GetSimVarValue('L:A32NX_HYD_RAT_STOW_POSITION', 'percent over 100')); + this.yellowLP.set(SimVar.GetSimVarValue('L:A32NX_HYD_YELLOW_EDPUMP_LOW_PRESS', 'bool')); + this.yellowRvrOvht.set(SimVar.GetSimVarValue('L:A32NX_HYD_YELLOW_RESERVOIR_OVHT', 'bool')); + this.yepumpPBisAuto.set(SimVar.GetSimVarValue('L:A32NX_OVHD_HYD_EPUMPY_PB_IS_AUTO', 'bool')); + + const blueSysPressurised = SimVar.GetSimVarValue('L:A32NX_HYD_BLUE_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool'); + const greenSysPressurised = SimVar.GetSimVarValue('L:A32NX_HYD_GREEN_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool'); + const yellowSysPressurised = SimVar.GetSimVarValue('L:A32NX_HYD_YELLOW_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool'); + + /* ADIRS */ + + this.adirsRemainingAlignTime.set(SimVar.GetSimVarValue('L:A32NX_ADIRS_REMAINING_IR_ALIGNMENT_TIME', 'Seconds')); + + const adirsAlt: Arinc429Word = Arinc429Word.fromSimVarValue('L:A32NX_ADIRS_ADR_1_ALTITUDE'); + this.adiru1State.set(SimVar.GetSimVarValue('L:A32NX_ADIRS_ADIRU_1_STATE', 'enum')); + this.adiru2State.set(SimVar.GetSimVarValue('L:A32NX_ADIRS_ADIRU_2_STATE', 'enum')); + this.adiru3State.set(SimVar.GetSimVarValue('L:A32NX_ADIRS_ADIRU_3_STATE', 'enum')); + const height1: Arinc429Word = Arinc429Word.fromSimVarValue('L:A32NX_RA_1_RADIO_ALTITUDE'); + const height2: Arinc429Word = Arinc429Word.fromSimVarValue('L:A32NX_RA_2_RADIO_ALTITUDE'); + this.height1Failed.set(height1.isFailureWarning()); + this.height2Failed.set(height2.isFailureWarning()); + + /* LANDING GEAR AND LIGHTS */ + + // const [left1LandingGear] = useSimVar('L:A32NX_LGCIU_1_LEFT_GEAR_COMPRESSED', 'bool', 500); + // const [right1LandingGear] = useSimVar('L:A32NX_LGCIU_1_RIGHT_GEAR_COMPRESSED', 'bool', 500); + // const aircraftOnGround = left1LandingGear === 1 || right1LandingGear === 1; + // FIXME The landing gear triggers the dual engine failure on loading + this.aircraftOnGround.set(SimVar.GetSimVarValue('SIM ON GROUND', 'Bool')); + this.antiskidActive.set(SimVar.GetSimVarValue('ANTISKID BRAKES ACTIVE', 'bool')); + this.brakeFan.set(SimVar.GetSimVarValue('L:A32NX_BRAKE_FAN', 'bool')); + this.brakesHot.set(SimVar.GetSimVarValue('L:A32NX_BRAKES_HOT', 'bool')); + this.landingLight2Retracted.set(SimVar.GetSimVarValue('L:LANDING_2_Retracted', 'bool')); + this.landingLight3Retracted.set(SimVar.GetSimVarValue('L:LANDING_3_Retracted', 'bool')); + this.lgciu1Fault.set(SimVar.GetSimVarValue('L:A32NX_LGCIU_1_FAULT', 'bool')); + this.lgciu2Fault.set(SimVar.GetSimVarValue('L:A32NX_LGCIU_2_FAULT', 'bool')); + this.parkBrake.set(SimVar.GetSimVarValue('L:A32NX_PARK_BRAKE_LEVER_POS', 'Bool')); + this.nwSteeringDisc.set(SimVar.GetSimVarValue('L:A32NX_HYD_NW_STRG_DISC_ECAM_MEMO', 'Bool')); + + /* ELECTRICAL */ + + this.dcESSBusPowered.set(SimVar.GetSimVarValue('L:A32NX_ELEC_DC_ESS_BUS_IS_POWERED', 'bool')); + this.dc2BusPowered.set(SimVar.GetSimVarValue('L:A32NX_ELEC_DC_2_BUS_IS_POWERED', 'bool')); + this.ac1BusPowered.set(SimVar.GetSimVarValue('L:A32NX_ELEC_AC_1_BUS_IS_POWERED', 'bool')); + this.ac2BusPowered.set(SimVar.GetSimVarValue('L:A32NX_ELEC_AC_2_BUS_IS_POWERED', 'bool')); + this.acESSBusPowered.set(SimVar.GetSimVarValue('L:A32NX_ELEC_AC_ESS_BUS_IS_POWERED', 'bool')); + + /* AIR CONDITIONING */ + + const crossfeed = SimVar.GetSimVarValue('L:A32NX_PNEU_XBLEED_VALVE_OPEN', 'bool'); + const eng1Bleed = SimVar.GetSimVarValue('A:BLEED AIR ENGINE:1', 'bool'); + const eng1BleedPbFault = SimVar.GetSimVarValue('L:A32NX_OVHD_PNEU_ENG_1_BLEED_PB_HAS_FAULT', 'bool'); + const eng2Bleed = SimVar.GetSimVarValue('A:BLEED AIR ENGINE:2', 'bool'); + const eng2BleedPbFault = SimVar.GetSimVarValue('L:A32NX_OVHD_PNEU_ENG_2_BLEED_PB_HAS_FAULT', 'bool'); + const pack1Fault = SimVar.GetSimVarValue('L:A32NX_OVHD_COND_PACK_1_PB_HAS_FAULT', 'bool'); + const pack2Fault = SimVar.GetSimVarValue('L:A32NX_OVHD_COND_PACK_2_PB_HAS_FAULT', 'bool'); + const pack1On = SimVar.GetSimVarValue('L:A32NX_OVHD_COND_PACK_1_PB_IS_ON', 'bool'); + const pack2On = SimVar.GetSimVarValue('L:A32NX_OVHD_COND_PACK_2_PB_IS_ON', 'bool'); + + this.excessPressure.set(SimVar.GetSimVarValue('L:A32NX_PRESS_EXCESS_CAB_ALT', 'bool')); + this.cabAltSetResetState1.set( + this.cabAltSetReset1.write(adirsAlt.value > 10000 && this.excessPressure.get(), this.excessPressure.get() && [3, 10].includes(this.fwcFlightPhase.get())), + ); + this.cabAltSetResetState2.set( + this.cabAltSetReset2.write(adirsAlt.value > 16000 && this.excessPressure.get(), this.excessPressure.get() && [3, 10].includes(this.fwcFlightPhase.get())), + ); + this.packOffBleedAvailable1.write((eng1Bleed === 1 && !eng1BleedPbFault) || crossfeed === 1, deltaTime); + this.packOffBleedAvailable2.write((eng2Bleed === 1 && !eng2BleedPbFault) || crossfeed === 1, deltaTime); + this.packOffNotFailed1Status.set(this.packOffNotFailed1.write(!pack1On && !pack1Fault && this.packOffBleedAvailable1.read() && this.fwcFlightPhase.get() === 6, deltaTime)); + this.packOffNotFailed2Status.set(this.packOffNotFailed2.write(!pack2On && !pack2Fault && this.packOffBleedAvailable2.read() && this.fwcFlightPhase.get() === 6, deltaTime)); + + /* OTHER STUFF */ + + this.airKnob.set(SimVar.GetSimVarValue('L:A32NX_AIR_DATA_SWITCHING_KNOB', 'enum')); + this.attKnob.set(SimVar.GetSimVarValue('L:A32NX_ATT_HDG_SWITCHING_KNOB', 'enum')); + this.compMesgCount.set(SimVar.GetSimVarValue('L:A32NX_COMPANY_MSG_COUNT', 'number')); + this.dmcSwitchingKnob.set(SimVar.GetSimVarValue('L:A32NX_EIS_DMC_SWITCHING_KNOB', 'enum')); + this.manLandingElevation.set(SimVar.GetSimVarValue('L:XMLVAR_KNOB_OVHD_CABINPRESS_LDGELEV', 'number')); + this.seatBelt.set(SimVar.GetSimVarValue('A:CABIN SEATBELTS ALERT SWITCH', 'bool')); + this.ndXfrKnob.set(SimVar.GetSimVarValue('L:A32NX_ECAM_ND_XFR_SWITCHING_KNOB', 'enum')); + this.noSmoking.set(SimVar.GetSimVarValue('L:A32NX_NO_SMOKING_MEMO', 'bool')); + this.noSmokingSwitchPosition.set(SimVar.GetSimVarValue('L:XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position', 'Enum')); + this.strobeLightsOn.set(SimVar.GetSimVarValue('L:LIGHTING_STROBE_0', 'Bool')); + this.gpwsFlaps3.set(SimVar.GetSimVarValue('L:A32NX_GPWS_FLAPS3', 'Bool')); + this.gpwsFlapMode.set(SimVar.GetSimVarValue('L:A32NX_GPWS_FLAP_OFF', 'Bool')); + this.gpwsTerrOff.set(SimVar.GetSimVarValue('L:A32NX_GPWS_TERR_OFF', 'Bool')); + this.predWSOn.set(SimVar.GetSimVarValue('L:A32NX_SWITCH_RADAR_PWS_Position', 'Bool')); + this.tcasFault.set(SimVar.GetSimVarValue('L:A32NX_TCAS_FAULT', 'bool')); + this.tcasSensitivity.set(SimVar.GetSimVarValue('L:A32NX_TCAS_SENSITIVITY', 'Enum')); + this.wingAntiIce.set(SimVar.GetSimVarValue('L:A32NX_PNEU_WING_ANTI_ICE_SYSTEM_SELECTED', 'bool')); + this.voiceVhf3.set(SimVar.GetSimVarValue('A:COM ACTIVE FREQUENCY:3', 'number')); + + /* FUEL */ + this.leftOuterInnerValve.set(SimVar.GetSimVarValue('FUELSYSTEM VALVE OPEN:4', 'Bool')); + this.fuelXFeedPBOn.set(SimVar.GetSimVarValue('L:XMLVAR_Momentary_PUSH_OVHD_FUEL_XFEED_Pressed', 'bool')); + this.rightOuterInnerValve.set(SimVar.GetSimVarValue('FUELSYSTEM VALVE OPEN:5', 'Bool')); + + /* F/CTL */ + const fcdc1DiscreteWord1 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_1_DISCRETE_WORD_1'); + const fcdc2DiscreteWord1 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_2_DISCRETE_WORD_1'); + const fcdc1DiscreteWord2 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_1_DISCRETE_WORD_2'); + const fcdc2DiscreteWord2 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_2_DISCRETE_WORD_2'); + const fcdc1DiscreteWord3 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_1_DISCRETE_WORD_3'); + const fcdc2DiscreteWord3 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_2_DISCRETE_WORD_3'); + const fcdc1DiscreteWord4 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_1_DISCRETE_WORD_4'); + const fcdc2DiscreteWord4 = Arinc429Word.fromSimVarValue('L:A32NX_FCDC_2_DISCRETE_WORD_4'); + + // ELAC 1 FAULT computation + const se1f = (fcdc1DiscreteWord1.getBitValueOr(19, false) || fcdc2DiscreteWord1.getBitValueOr(19, false)) + && (fcdc1DiscreteWord1.getBitValueOr(20, false) || fcdc2DiscreteWord1.getBitValueOr(20, false)); + const elac1FaultCondition = !([1, 10].includes(this.fwcFlightPhase.get()) && (fcdc1DiscreteWord3.getBitValueOr(19, false) || fcdc2DiscreteWord3.getBitValueOr(19, false))) + && this.dcESSBusPowered.get() + && ((fcdc1DiscreteWord1.getBitValueOr(23, false) || fcdc2DiscreteWord1.getBitValueOr(23, false)) || (!this.elac1HydConfirmNodeOutput.get() && se1f)); + this.elac1FaultLine123Display.set(!(fcdc1DiscreteWord3.getBitValueOr(19, false) || fcdc2DiscreteWord3.getBitValueOr(19, false)) + && (fcdc1DiscreteWord1.getBitValueOr(23, false) || fcdc2DiscreteWord1.getBitValueOr(23, false))); + this.elac1HydConfirmNodeOutput.set(this.elac1HydConfirmNode.write(!greenSysPressurised && !blueSysPressurised, deltaTime)); + this.elac1FaultConfirmNodeOutput.set(this.elac1FaultConfirmNode.write(elac1FaultCondition, deltaTime)); + + // ELAC 2 FAULT computation + const se2f = (fcdc1DiscreteWord1.getBitValueOr(21, false) || fcdc2DiscreteWord1.getBitValueOr(21, false)) + && (fcdc1DiscreteWord1.getBitValueOr(22, false) || fcdc2DiscreteWord1.getBitValueOr(22, false)); + const elac2FaultCondition = !([1, 10].includes(this.fwcFlightPhase.get()) && (fcdc1DiscreteWord3.getBitValueOr(20, false) || fcdc2DiscreteWord3.getBitValueOr(20, false))) + && this.dc2BusPowered.get() + && ((fcdc1DiscreteWord1.getBitValueOr(24, false) || fcdc2DiscreteWord1.getBitValueOr(24, false)) + || (!this.elac2HydConfirmNodeOutput.get() && se2f)); + this.elac2FaultLine123Display.set(!(fcdc1DiscreteWord3.getBitValueOr(20, false) || fcdc2DiscreteWord3.getBitValueOr(20, false)) + && (fcdc1DiscreteWord1.getBitValueOr(24, false) || fcdc2DiscreteWord1.getBitValueOr(24, false))); + this.elac2HydConfirmNodeOutput.set(this.elac2HydConfirmNode.write((!greenSysPressurised || !yellowSysPressurised) && !blueSysPressurised, deltaTime)); + this.elac2FaultConfirmNodeOutput.set(this.elac2FaultConfirmNode.write(elac2FaultCondition, deltaTime)); + + // SEC 1 FAULT computation + const ss1f = fcdc1DiscreteWord1.getBitValueOr(25, false) || fcdc2DiscreteWord1.getBitValueOr(25, false); + this.sec1FaultCondition.set(!([1, 10].includes(this.fwcFlightPhase.get()) && (fcdc1DiscreteWord3.getBitValueOr(27, false) || fcdc2DiscreteWord3.getBitValueOr(27, false))) + && this.dcESSBusPowered.get() && ss1f); + this.sec1FaultLine123Display.set(!(fcdc1DiscreteWord3.getBitValueOr(27, false) || fcdc2DiscreteWord3.getBitValueOr(27, false))); + + // SEC 2 FAULT computation + const ss2f = fcdc1DiscreteWord1.getBitValueOr(26, false) || fcdc2DiscreteWord1.getBitValueOr(26, false); + this.sec2FaultCondition.set(!([1, 10].includes(this.fwcFlightPhase.get()) && (fcdc1DiscreteWord3.getBitValueOr(28, false) || fcdc2DiscreteWord3.getBitValueOr(28, false))) + && this.dc2BusPowered.get() && ss2f); + this.sec2FaultLine123Display.set(!(fcdc1DiscreteWord3.getBitValueOr(28, false) || fcdc2DiscreteWord3.getBitValueOr(28, false))); + + // SEC 3 FAULT computation + const ss3f = fcdc1DiscreteWord1.getBitValueOr(29, false) || fcdc2DiscreteWord1.getBitValueOr(29, false); + this.sec3FaultCondition.set(!([1, 10].includes(this.fwcFlightPhase.get()) && (fcdc1DiscreteWord3.getBitValueOr(29, false) || fcdc2DiscreteWord3.getBitValueOr(29, false))) + && this.dc2BusPowered.get() && ss3f); + this.sec3FaultLine123Display.set(!(fcdc1DiscreteWord3.getBitValueOr(29, false) || fcdc2DiscreteWord3.getBitValueOr(29, false))); + + // FCDC 1+2 FAULT computation + const SFCDC1FT = fcdc1DiscreteWord1.isFailureWarning() && fcdc1DiscreteWord2.isFailureWarning() && fcdc1DiscreteWord3.isFailureWarning(); + const SFCDC2FT = fcdc2DiscreteWord1.isFailureWarning() && fcdc2DiscreteWord2.isFailureWarning() && fcdc2DiscreteWord3.isFailureWarning(); + const SFCDC12FT = SFCDC1FT && SFCDC2FT; + this.fcdc12FaultCondition.set(SFCDC12FT && this.dc2BusPowered.get()); + this.fcdc1FaultCondition.set(SFCDC1FT && !SFCDC12FT); + this.fcdc2FaultCondition.set(SFCDC2FT && !(SFCDC12FT || !this.dc2BusPowered.get())); + + // ALTN LAW 2 computation + const SPA2 = fcdc1DiscreteWord1.getBitValueOr(13, false) || fcdc2DiscreteWord1.getBitValueOr(13, false); + this.altn2LawConfirmNodeOutput.set(this.altn2LawConfirmNode.write(SPA2 && ![1, 10].includes(this.fwcFlightPhase.get()), deltaTime)); + + // ALTN LAW 1 computation + const SPA1 = fcdc1DiscreteWord1.getBitValueOr(12, false) || fcdc2DiscreteWord1.getBitValueOr(12, false); + this.altn1LawConfirmNodeOutput.set(this.altn1LawConfirmNode.write(SPA1 && ![1, 10].includes(this.fwcFlightPhase.get()), deltaTime)); + + // DIRECT LAW computation + const SPBUL = (false && SFCDC12FT) || (fcdc1DiscreteWord1.getBitValueOr(15, false) || fcdc2DiscreteWord1.getBitValueOr(15, false)); + this.directLawCondition.set(SPBUL && ![1, 10].includes(this.fwcFlightPhase.get())); + + // L+R ELEV FAULT computation + const lhElevBlueFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(15, false)) + || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(15, false)); + const lhElevGreenFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(16, false)) + || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(16, false)); + const rhElevBlueFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(17, false)) + || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(17, false)); + const rhElevGreenFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(18, false)) + || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(18, false)); + this.lrElevFaultCondition.set(lhElevBlueFail && lhElevGreenFail && rhElevBlueFail && rhElevGreenFail && ![1, 10].includes(this.fwcFlightPhase.get())); + + this.spoilersArmed.set(fcdc1DiscreteWord4.getBitValueOr(27, false) || fcdc2DiscreteWord4.getBitValueOr(27, false)); + this.speedBrakeCommand.set(fcdc1DiscreteWord4.getBitValueOr(28, false) || fcdc2DiscreteWord4.getBitValueOr(28, false)); + this.flapsAngle.set(SimVar.GetSimVarValue('L:A32NX_LEFT_FLAPS_ANGLE', 'degrees')); + this.flapsMcdu.set(SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_FLAPS', 'number')); + this.flapsMcduEntered.set(SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_FLAPS_ENTERED', 'bool')); + this.flapsHandle.set(SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum')); + this.slatsAngle.set(SimVar.GetSimVarValue('L:A32NX_LEFT_SLATS_ANGLE', 'degrees')); + + /* FIRE */ + + this.fireButton1.set(SimVar.GetSimVarValue('L:A32NX_FIRE_BUTTON_ENG1', 'bool')); + this.fireButton2.set(SimVar.GetSimVarValue('L:A32NX_FIRE_BUTTON_ENG2', 'bool')); + this.fireButtonAPU.set(SimVar.GetSimVarValue('L:A32NX_FIRE_BUTTON_APU', 'bool')); + this.eng1FireTest.set(SimVar.GetSimVarValue('L:A32NX_FIRE_TEST_ENG1', 'bool')); + this.eng2FireTest.set(SimVar.GetSimVarValue('L:A32NX_FIRE_TEST_ENG2', 'bool')); + this.apuFireTest.set(SimVar.GetSimVarValue('L:A32NX_FIRE_TEST_APU', 'bool')); + this.eng1Agent1PB.set(SimVar.GetSimVarValue('L:A32NX_FIRE_ENG1_AGENT1_Discharge', 'bool')); + this.eng1Agent2PB.set(SimVar.GetSimVarValue('L:A32NX_FIRE_ENG1_AGENT2_Discharge', 'bool')); + this.eng2Agent1PB.set(SimVar.GetSimVarValue('L:A32NX_FIRE_ENG2_AGENT1_Discharge', 'bool')); + this.eng2Agent2PB.set(SimVar.GetSimVarValue('L:A32NX_FIRE_ENG2_AGENT2_Discharge', 'bool')); + this.apuAgentPB.set(SimVar.GetSimVarValue('L:A32NX_FIRE_APU_AGENT1_Discharge', 'bool')); + this.cargoFireTest.set(SimVar.GetSimVarValue('L:A32NX_FIRE_TEST_CARGO', 'bool')); + this.cargoFireAgentDisch.set(SimVar.GetSimVarValue('L:A32NX_CARGOSMOKE_FWD_DISCHARGED', 'bool')); + + this.agent1Eng1Discharge.set(this.agent1Eng1DischargeTimer.write(this.fireButton1.get(), deltaTime)); + this.agent2Eng1Discharge.set(this.agent2Eng1DischargeTimer.write(this.fireButton1.get() && this.eng1Agent1PB.get() && !this.aircraftOnGround.get(), deltaTime)); + this.agent1Eng2Discharge.set(this.agent1Eng2DischargeTimer.write(this.fireButton2.get() && !this.eng1Agent1PB.get(), deltaTime)); + this.agent2Eng2Discharge.set(this.agent2Eng2DischargeTimer.write(this.fireButton2.get() && this.eng1Agent1PB.get(), deltaTime)); + this.agentAPUDischarge.set(this.agentAPUDischargeTimer.write(this.fireButton2.get() && this.eng1Agent1PB.get(), deltaTime)); + + /* ANTI ICE */ + + const icePercentage = SimVar.GetSimVarValue('STRUCTURAL ICE PCT', 'percent over 100'); + const tat = SimVar.GetSimVarValue('TOTAL AIR TEMPERATURE', 'celsius'); + const inCloud = SimVar.GetSimVarValue('AMBIENT IN CLOUD', 'boolean'); + const iceDetected1 = this.iceDetectedTimer1.write(icePercentage >= 0.1 && tat < 10 && !this.aircraftOnGround.get(), deltaTime); + this.iceDetectedTimer2Status.set(this.iceDetectedTimer2.write(iceDetected1 && !(this.eng1AntiIce.get() && this.eng2AntiIce.get()), deltaTime)); + this.iceSevereDetectedTimerStatus.set(this.iceSevereDetectedTimer.write(icePercentage >= 0.5 && tat < 10 && !this.aircraftOnGround.get(), deltaTime)); + const iceNotDetected1 = this.iceNotDetTimer1.write(this.eng1AntiIce.get() || this.eng2AntiIce.get() || this.wingAntiIce.get(), deltaTime); + this.iceNotDetTimer2Status.set(this.iceNotDetTimer2.write(iceNotDetected1 && !(icePercentage >= 0.1 || (tat < 10 && inCloud === 1)), deltaTime)); + + /* SETTINGS */ + + this.configPortableDevices.set(NXDataStore.get('CONFIG_USING_PORTABLE_DEVICES', '0') !== '0'); + + /* CABIN READY */ + + const callPushAft = SimVar.GetSimVarValue('L:PUSH_OVHD_CALLS_AFT', 'bool'); + const callPushAll = SimVar.GetSimVarValue('L:PUSH_OVHD_CALLS_ALL', 'bool'); + const callPushFwd = SimVar.GetSimVarValue('L:PUSH_OVHD_CALLS_FWD', 'bool'); + if (callPushAft || callPushAll || callPushFwd) { + SimVar.SetSimVarValue('L:A32NX_CABIN_READY', 'bool', 1); + } + + /* MASTER CAUT/WARN BUTTONS */ + + const masterCautionButtonLeft = SimVar.GetSimVarValue('L:PUSH_AUTOPILOT_MASTERCAUT_L', 'bool'); + const masterCautionButtonRight = SimVar.GetSimVarValue('L:PUSH_AUTOPILOT_MASTERCAUT_R', 'bool'); + const masterWarningButtonLeft = SimVar.GetSimVarValue('L:PUSH_AUTOPILOT_MASTERAWARN_L', 'bool'); + const masterWarningButtonRight = SimVar.GetSimVarValue('L:PUSH_AUTOPILOT_MASTERAWARN_R', 'bool'); + if (masterCautionButtonLeft || masterCautionButtonRight) { + this.masterCaution(0); + } + if (masterWarningButtonLeft || masterWarningButtonRight) { + this.masterWarning(0); + } + + /* T.O. CONFIG CHECK */ + + const toConfigBtn = SimVar.GetSimVarValue('L:A32NX_BTN_TOCONFIG', 'bool'); + if (this.toMemo.get() && toConfigBtn === 1) { + // TODO Note that fuel tank low pressure and gravity feed warnings are not included + const systemStatus = this.engine1Generator.get() && this.engine2Generator.get() + && !this.greenLP.get() && !this.yellowLP.get() && !this.blueLP.get() + && this.eng1pumpPBisAuto.get() && this.eng2pumpPBisAuto.get(); + + const v1Speed = SimVar.GetSimVarValue('L:AIRLINER_V1_SPEED', 'knots'); + const vrSpeed = SimVar.GetSimVarValue('L:AIRLINER_VR_SPEED', 'knots'); + const v2Speed = SimVar.GetSimVarValue('L:AIRLINER_V2_SPEED', 'knots'); + const cabin = SimVar.GetSimVarValue('INTERACTIVE POINT OPEN:0', 'percent'); + const catering = SimVar.GetSimVarValue('INTERACTIVE POINT OPEN:3', 'percent'); + const cargofwdLocked = SimVar.GetSimVarValue('L:A32NX_FWD_DOOR_CARGO_LOCKED', 'bool'); + const cargoaftLocked = SimVar.GetSimVarValue('L:A32NX_AFT_DOOR_CARGO_LOCKED', 'bool'); + const brakesHot = SimVar.GetSimVarValue('L:A32NX_BRAKES_HOT', 'bool'); + + const speeds = !!(v1Speed <= vrSpeed && vrSpeed <= v2Speed); + const doors = !!(cabin === 0 && catering === 0 && cargoaftLocked && cargofwdLocked); + const flapsAgree = !this.flapsMcduEntered.get() || this.flapsHandle.get() === this.flapsMcdu.get(); + const sb = !this.speedBrakeCommand.get(); + + if (systemStatus && speeds && !brakesHot && doors && flapsAgree && sb) { + SimVar.SetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool', 1); + this.toConfigFail.set(false); + } else { + SimVar.SetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool', 0); + this.toConfigFail.set(true); + } + } + this.toConfigNormal.set(SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool')); + + /* CLEAR AND RECALL */ + + const clearButtonLeft = SimVar.GetSimVarValue('L:A32NX_BTN_CLR', 'bool'); + const clearButtonRight = SimVar.GetSimVarValue('L:A32NX_BTN_CLR2', 'bool'); + const recallButton = SimVar.GetSimVarValue('L:A32NX_BTN_RCL', 'bool'); + + if (clearButtonLeft === 1 || clearButtonRight === 1) { + this.failuresLeft.shift(); + this.recallFailures = this.allCurrentFailures.filter((item) => !this.failuresLeft.includes(item)); + SimVar.SetSimVarValue('L:A32NX_BTN_CLR', 'Bool', 0); + SimVar.SetSimVarValue('L:A32NX_BTN_CLR2', 'Bool', 0); + } + + if (recallButton === 1) { + if (this.recallFailures.length > 0) { + this.failuresLeft.push(this.recallFailures.shift()); + } + } + + // Output logic + + this.landAsapRed.set(!this.aircraftOnGround.get() + && ( + this.fireButton1.get() + || this.eng1FireTest.get() + || this.fireButton2.get() + || this.eng2FireTest.get() + || this.fireButtonAPU.get() + || this.apuFireTest.get() + || this.emergencyGeneratorOn.get() + || (this.engine1State.get() === 0 && this.engine2State.get() === 0) + || (this.greenLP.get() && this.yellowLP.get()) + || (this.yellowLP.get() && this.blueLP.get()) + || (this.greenLP.get() && this.blueLP.get()) + )); + + const flightPhase = this.fwcFlightPhase.get(); + let tempMemoArrayLeft:string[] = []; + let tempMemoArrayRight:string[] = []; + const allFailureKeys: string[] = []; + let tempFailureArrayLeft:string[] = []; + let failureKeysLeft: string[] = this.failuresLeft; + let recallFailureKeys: string[] = this.recallFailures; + let tempFailureArrayRight:string[] = []; + const failureKeysRight: string[] = this.failuresRight; + let leftFailureSystemCount = 0; + let rightFailureSystemCount = 0; + + // Update failuresLeft list in case failure has been resolved + for (const [key, value] of Object.entries(this.ewdMessageFailures)) { + if (!value.simVarIsActive.get() || value.flightPhaseInhib.some((e) => e === flightPhase)) { + failureKeysLeft = failureKeysLeft.filter((e) => e !== key); + recallFailureKeys = recallFailureKeys.filter((e) => e !== key); + } + } + + this.recallFailures.length = 0; + this.recallFailures.push(...recallFailureKeys); + + // Failures first + for (const [key, value] of Object.entries(this.ewdMessageFailures)) { + if (value.simVarIsActive.get() && !value.flightPhaseInhib.some((e) => e === flightPhase)) { + if (value.side === 'LEFT') { + allFailureKeys.push(key); + } + + if ((value.side === 'LEFT' && !this.failuresLeft.includes(key) && !recallFailureKeys.includes(key)) || (value.side === 'RIGHT' && !this.failuresRight.includes(key))) { + if (value.side === 'LEFT') { + failureKeysLeft.push(key); + } else { + failureKeysRight.push(key); + } + + if (value.failure === 3) { + this.masterWarning(1); + } + if (value.failure === 2) { + this.masterCaution(1); + } + } else if (![this.eng1FireTest.get(), this.eng2FireTest.get(), this.apuFireTest.get(), this.cargoFireTest.get()].every((e) => !e)) { + this.masterWarning(1); + } + + const newCode: string[] = []; + if (!recallFailureKeys.includes(key)) { + const codeIndex = value.whichCodeToReturn().filter((e) => e !== null); + + for (const e of codeIndex) { + newCode.push(value.codesToReturn[e]); + } + + if (value.sysPage > -1) { + if (value.side === 'LEFT') { + leftFailureSystemCount++; + } else { + rightFailureSystemCount++; + } + } + } + if (value.side === 'LEFT') { + tempFailureArrayLeft = tempFailureArrayLeft.concat(newCode); + } else { + tempFailureArrayRight = tempFailureArrayRight.concat(newCode); + } + + if (value.sysPage > -1) { + SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', value.sysPage); + } + } + } + + const failLeft = tempFailureArrayLeft.length > 0; + + const mesgFailOrderLeft: string[] = []; + const mesgFailOrderRight: string[] = []; + + for (const [, value] of Object.entries(this.ewdMessageFailures)) { + if (value.side === 'LEFT') { + mesgFailOrderLeft.push(...value.codesToReturn); + } else { + mesgFailOrderRight.push(...value.codesToReturn); + } + } + + const orderedFailureArrayLeft = this.mapOrder(tempFailureArrayLeft, mesgFailOrderLeft); + const orderedFailureArrayRight = this.mapOrder(tempFailureArrayRight, mesgFailOrderRight); + + this.allCurrentFailures.length = 0; + this.allCurrentFailures.push(...allFailureKeys); + + this.failuresLeft.length = 0; + this.failuresLeft.push(...failureKeysLeft); + + this.failuresRight.length = 0; + this.failuresRight.push(...failureKeysRight); + + if (tempFailureArrayLeft.length > 0) { + this.memoMessageLeft.set(orderedFailureArrayLeft); + } + + for (const [, value] of Object.entries(this.ewdMessageMemos)) { + if (value.simVarIsActive.get() && !(value.memoInhibit()) && !value.flightPhaseInhib.some((e) => e === flightPhase)) { + const newCode: string[] = []; + + const codeIndex = value.whichCodeToReturn().filter((e) => e !== null); + codeIndex.forEach((e: number) => { + newCode.push(value.codesToReturn[e]); + }); + + if (value.side === 'LEFT' && !failLeft) { + tempMemoArrayLeft = tempMemoArrayLeft.concat(newCode); + } + if (value.side === 'RIGHT') { + const tempArrayRight = tempMemoArrayRight.filter((e) => !value.codesToReturn.includes(e)); + tempMemoArrayRight = tempArrayRight.concat(newCode); + } + + if (value.sysPage > -1) { + SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', value.sysPage); + } + } + } + + const mesgOrderLeft: string[] = []; + const mesgOrderRight: string[] = []; + + for (const [, value] of Object.entries(this.ewdMessageMemos)) { + if (value.side === 'LEFT') { + mesgOrderLeft.push(...value.codesToReturn); + } else { + mesgOrderRight.push(...value.codesToReturn); + } + } + + const orderedMemoArrayLeft = this.mapOrder(tempMemoArrayLeft, mesgOrderLeft); + let orderedMemoArrayRight: string[] = this.mapOrder(tempMemoArrayRight, mesgOrderRight); + + if (!failLeft) { + this.memoMessageLeft.set(orderedMemoArrayLeft); + + if (orderedFailureArrayRight.length === 0) { + this.masterCaution(0); + this.masterWarning(0); + } + } + + if (leftFailureSystemCount + rightFailureSystemCount === 0) { + SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', -1); + } + + if (orderedFailureArrayRight.length > 0) { + // Right side failures need to be inserted between special lines + // and the rest of the memo + const specialLines = ['000014001', '000015001', '000035001', '000036001', '220001501', '220002101']; + const filteredMemo = orderedMemoArrayRight.filter((e) => !specialLines.includes(e)); + const specLinesInMemo = orderedMemoArrayRight.filter((e) => specialLines.includes(e)); + if (specLinesInMemo.length > 0) { + orderedMemoArrayRight = [...specLinesInMemo, ...orderedFailureArrayRight, ...filteredMemo]; + } else { + orderedMemoArrayRight = [...orderedFailureArrayRight, ...orderedMemoArrayRight]; + } + } + + this.memoMessageRight.set(orderedMemoArrayRight); + } + + ewdMessageFailures: EWDMessageDict = { + 3400210: { // OVERSPEED FLAPS FULL + flightPhaseInhib: [2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject + .create(([flapsIndex, computedAirSpeedToNearest2]) => flapsIndex === 5 && computedAirSpeedToNearest2 > 181, this.flapsIndex, this.computedAirSpeedToNearest2), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['340021001', '340021002'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 3400220: { // OVERSPEED FLAPS 3 + flightPhaseInhib: [2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject + .create(([flapsIndex, computedAirSpeedToNearest2]) => flapsIndex === 4 && computedAirSpeedToNearest2 > 189, this.flapsIndex, this.computedAirSpeedToNearest2), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['340022001', '340022002'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 3400230: { // OVERSPEED FLAPS 2 + flightPhaseInhib: [2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject.create( + ([flapsIndex, computedAirSpeedToNearest2]) => flapsIndex === 3 && computedAirSpeedToNearest2 > 203, this.flapsIndex, this.computedAirSpeedToNearest2, + ), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['340023001', '340023002'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 3400235: { // OVERSPEED FLAPS 1+F + flightPhaseInhib: [2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject.create( + ([flapsIndex, computedAirSpeedToNearest2]) => flapsIndex === 2 && computedAirSpeedToNearest2 > 219, this.flapsIndex, this.computedAirSpeedToNearest2, + ), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['340023501', '340023502'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 3400240: { // OVERSPEED FLAPS 1 + flightPhaseInhib: [2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject.create( + ([flapsIndex, computedAirSpeedToNearest2]) => flapsIndex === 1 && computedAirSpeedToNearest2 > 233, this.flapsIndex, this.computedAirSpeedToNearest2, + ), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['340024001', '340024002'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 7700027: { // DUAL ENGINE FAILURE + flightPhaseInhib: [], + simVarIsActive: this.engDualFault, + whichCodeToReturn: () => [ + 0, + !(this.emergencyGeneratorOn.get()) ? 1 : null, + 5, + !(this.apuMasterSwitch.get() === 1 || this.apuAvail.get() === 1) && this.radioAlt.get() < 2500 ? 6 : null, + (this.N1AboveIdle.get() || this.N2AboveIdle.get()) ? 7 : null, + this.fac1Failed.get() === 1 ? 8 : null, + 9, 10, 11, + ], + codesToReturn: ['770002701', '770002702', '770002703', '770002704', '770002705', '770002706', '770002707', '770002708', '770002709', '770002710', '770002711', '770002712'], + memoInhibit: () => false, + failure: 3, + sysPage: 0, + side: 'LEFT', + }, + 2600010: { // ENG 1 FIRE + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([eng1FireTest, fireButton1]) => eng1FireTest || fireButton1, this.eng1FireTest, this.fireButton1), + whichCodeToReturn: () => [ + 0, + this.throttle1Position.get() !== 0 && !this.aircraftOnGround.get() ? 1 : null, + (this.throttle1Position.get() !== 0 || this.throttle2Position.get() !== 0) && this.aircraftOnGround.get() ? 2 : null, + !this.parkBrake.get() && this.aircraftOnGround.get() ? 3 : null, + !this.parkBrake.get() && this.aircraftOnGround.get() ? 4 : null, + this.aircraftOnGround.get() ? 5 : null, + this.aircraftOnGround.get() ? 6 : null, + !this.engine1ValueSwitch.get() ? null : 7, + !this.fireButton1.get() ? 8 : null, + !this.aircraftOnGround.get() && this.agent1Eng1Discharge.get() === 1 && !this.eng1Agent1PB.get() ? 9 : null, + this.agent1Eng1Discharge.get() === 2 && !this.aircraftOnGround.get() && !this.eng1Agent1PB.get() ? 10 : null, + !this.eng1Agent1PB.get() && this.aircraftOnGround.get() ? 11 : null, + !this.eng1Agent2PB.get() && this.aircraftOnGround.get() ? 12 : null, + this.aircraftOnGround.get() ? 13 : null, + !this.aircraftOnGround.get() ? 14 : null, + this.agent2Eng1Discharge.get() === 1 && !this.eng1Agent2PB.get() ? 15 : null, + (this.agent2Eng1Discharge.get() === 1 && !this.eng1Agent2PB.get()) || (this.agent2Eng1Discharge.get() === 2 && !this.eng1Agent2PB.get()) ? 16 : null, + ], + codesToReturn: ['260001001', '260001002', '260001003', '260001004', '260001005', + '260001006', '260001007', '260001008', '260001009', '260001010', '260001011', + '260001012', '260001013', '260001014', '260001015', '260001016', '260001017'], + memoInhibit: () => false, + failure: 3, + sysPage: 0, + side: 'LEFT', + }, + 2600020: { // ENG 2 FIRE + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([eng2FireTest, fireButton2]) => eng2FireTest || fireButton2, this.eng2FireTest, this.fireButton2), + whichCodeToReturn: () => [ + 0, + this.throttle2Position.get() !== 0 && !this.aircraftOnGround.get() ? 1 : null, + (this.throttle1Position.get() !== 0 || this.throttle2Position.get() !== 0) && this.aircraftOnGround.get() ? 2 : null, + !this.parkBrake.get() && this.aircraftOnGround.get() ? 3 : null, + !this.parkBrake.get() && this.aircraftOnGround.get() ? 4 : null, + this.aircraftOnGround.get() ? 5 : null, + this.aircraftOnGround.get() ? 6 : null, + !this.engine2ValueSwitch.get() ? null : 7, + !this.fireButton2.get() ? 8 : null, + !this.aircraftOnGround.get() && this.agent1Eng2Discharge.get() === 1 && !this.eng2Agent1PB.get() ? 9 : null, + this.agent1Eng2Discharge.get() === 2 && !this.aircraftOnGround.get() && !this.eng2Agent1PB.get() ? 10 : null, + !this.eng2Agent1PB.get() && this.aircraftOnGround.get() ? 11 : null, + !this.eng2Agent2PB.get() && this.aircraftOnGround.get() ? 12 : null, + this.aircraftOnGround.get() ? 13 : null, + !this.aircraftOnGround.get() ? 14 : null, + this.agent2Eng2Discharge.get() === 1 && !this.eng2Agent2PB.get() ? 15 : null, + (this.agent2Eng2Discharge.get() === 1 && !this.eng2Agent2PB.get()) || (this.agent2Eng2Discharge.get() === 2 && !this.eng2Agent2PB.get()) ? 16 : null, + ], + codesToReturn: ['260002001', '260002002', '260002003', '260002004', '260002005', + '260002006', '260002007', '260002008', '260002009', '260002010', '260002011', + '260002012', '260002013', '260002014', '260002015', '260002016'], + memoInhibit: () => false, + failure: 3, + sysPage: 0, + side: 'LEFT', + }, + 2600030: { // APU FIRE + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([apuFireTest, fireButtonAPU]) => apuFireTest || fireButtonAPU, this.apuFireTest, this.fireButtonAPU), + whichCodeToReturn: () => [ + 0, + !this.fireButtonAPU.get() ? 1 : null, + this.agentAPUDischarge.get() === 1 && !this.apuAgentPB.get() ? 2 : null, + this.agentAPUDischarge.get() === 2 && !this.apuAgentPB.get() ? 3 : null, + this.apuMasterSwitch.get() === 1 ? 4 : null, + ], + codesToReturn: ['260003001', '260003002', '260003003', '260003004', '260003005'], + memoInhibit: () => false, + failure: 3, + sysPage: 6, + side: 'LEFT', + }, + 2700085: { // SLATS NOT IN TO CONFIG + flightPhaseInhib: [5, 6, 7, 8], + simVarIsActive: MappedSubject.create( + ([flapsMcdu, flapsMcduEntered, flapsHandle, fwcFlightPhase, toConfigFail, slatsAngle]) => ( + (flapsMcduEntered && flapsHandle !== flapsMcdu && [1, 2, 9].includes(fwcFlightPhase) && toConfigFail) + || ([3, 4, 5].includes(fwcFlightPhase) && (slatsAngle <= 17 || slatsAngle >= 25)) + ), this.flapsMcdu, this.flapsMcduEntered, this.flapsHandle, this.fwcFlightPhase, this.toConfigFail, this.slatsAngle, + ), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['270008501', '270008502'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 2700090: { // FLAPS NOT IN TO CONFIG + flightPhaseInhib: [5, 6, 7, 8], + simVarIsActive: MappedSubject.create( + ([flapsMcdu, flapsMcduEntered, flapsHandle, fwcFlightPhase, toConfigFail, flapsAngle]) => ( + (flapsMcduEntered && flapsHandle !== flapsMcdu && [1, 2, 9].includes(fwcFlightPhase) && toConfigFail) + || ([3, 4, 5].includes(fwcFlightPhase) && (flapsAngle <= 2 || flapsAngle >= 24)) + ), this.flapsMcdu, this.flapsMcduEntered, this.flapsHandle, this.fwcFlightPhase, this.toConfigFail, this.flapsAngle, + ), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['270009001', '270009002'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 2700110: { // ELAC 1 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.elac1FaultConfirmNodeOutput, + whichCodeToReturn: () => [ + 0, + this.elac1FaultLine123Display.get() ? 1 : null, + this.elac1FaultLine123Display.get() ? 2 : null, + this.elac1FaultLine123Display.get() ? 3 : null, + this.elac1FaultLine45Display.get() ? 4 : null, + this.elac1FaultLine45Display.get() ? 5 : null, + ], + codesToReturn: ['270011001', '270011002', '270011003', '270011004', '270011005', '270011006'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700120: { // ELAC 2 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.elac2FaultConfirmNodeOutput, + whichCodeToReturn: () => [ + 0, + this.elac2FaultLine123Display.get() ? 1 : null, + this.elac2FaultLine123Display.get() ? 2 : null, + this.elac2FaultLine123Display.get() ? 3 : null, + this.elac2FaultLine45Display.get() ? 4 : null, + this.elac2FaultLine45Display.get() ? 5 : null, + ], + codesToReturn: ['270012001', '270012002', '270012003', '270012004', '270012005', '270012006'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700210: { // SEC 1 FAULT + flightPhaseInhib: [3, 4, 5], + simVarIsActive: this.sec1FaultCondition, + whichCodeToReturn: () => [ + 0, + this.sec1FaultLine123Display.get() ? 1 : null, + this.sec1FaultLine123Display.get() ? 2 : null, + this.sec1FaultLine123Display.get() ? 3 : null, + this.sec1FaultLine45Display.get() ? 4 : null, + ], + codesToReturn: ['270021001', '270021002', '270021003', '270021004', '270021005'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700220: { // SEC 2 FAULT + flightPhaseInhib: [3, 4, 5], + simVarIsActive: this.sec2FaultCondition, + whichCodeToReturn: () => [ + 0, + this.sec2FaultLine123Display.get() ? 1 : null, + this.sec2FaultLine123Display.get() ? 2 : null, + this.sec2FaultLine123Display.get() ? 3 : null, + ], + codesToReturn: ['270022001', '270022002', '270022003', '270022004'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700230: { // SEC 3 FAULT + flightPhaseInhib: [3, 4, 5], + simVarIsActive: this.sec3FaultCondition, + whichCodeToReturn: () => [ + 0, + this.sec3FaultLine123Display.get() ? 1 : null, + this.sec3FaultLine123Display.get() ? 2 : null, + this.sec3FaultLine123Display.get() ? 3 : null, + ], + codesToReturn: ['270023001', '270023002', '270023003', '270023004'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700360: { // FCDC 1+2 FAULT + flightPhaseInhib: [3, 4, 5, 7], + simVarIsActive: this.fcdc12FaultCondition, + whichCodeToReturn: () => [0, 1], + codesToReturn: ['270036001', '270036002'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700365: { // DIRECT LAW + flightPhaseInhib: [4, 5, 7, 8], + simVarIsActive: this.directLawCondition, + whichCodeToReturn: () => [0, 1, 2, 3, 4, null, 6, 7], + codesToReturn: ['270036501', '270036502', '270036503', '270036504', '270036505', '270036506', '270036507', '270036508'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700375: { // ALTN 2 + flightPhaseInhib: [4, 5, 7, 8], + simVarIsActive: this.altn2LawConfirmNodeOutput, + whichCodeToReturn: () => [0, 1, null, 3, 4, null, 6], + codesToReturn: ['270037501', '270037502', '270037503', '270037504', '270037505', '270037506', '270037507'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700390: { // ALTN 1 + flightPhaseInhib: [4, 5, 7, 8], + simVarIsActive: this.altn1LawConfirmNodeOutput, + whichCodeToReturn: () => [0, 1, null, 3, 4, null, 6], + codesToReturn: ['270039001', '270039002', '270039003', '270039004', '270039005', '270039006', '270039007'], + memoInhibit: () => false, + failure: 2, + sysPage: 10, + side: 'LEFT', + }, + 2700400: { // L+R ELEV FAULT + flightPhaseInhib: [], + simVarIsActive: this.lrElevFaultCondition, + whichCodeToReturn: () => [0, 1, 2, null, null, 5], + codesToReturn: ['270040001', '270040002', '270040003', '270040004', '270040005', '270040006'], + memoInhibit: () => false, + failure: 3, + sysPage: 10, + side: 'LEFT', + }, + 2700555: { // FCDC 1 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.fcdc1FaultCondition, + whichCodeToReturn: () => [0], + codesToReturn: ['270055501'], + memoInhibit: () => false, + failure: 1, + sysPage: -1, + side: 'LEFT', + }, + 2700557: { // FCDC 2 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.fcdc2FaultCondition, + whichCodeToReturn: () => [0], + codesToReturn: ['270055701'], + memoInhibit: () => false, + failure: 1, + sysPage: -1, + side: 'LEFT', + }, + 3200050: { // PK BRK ON + flightPhaseInhib: [1, 4, 5, 6, 7, 8, 9, 10], + simVarIsActive: MappedSubject.create(([fwcFlightPhase, parkBrake]) => fwcFlightPhase === 3 && parkBrake, this.fwcFlightPhase, this.parkBrake), + // TODO no separate slats indication + whichCodeToReturn: () => [0], + codesToReturn: ['320005001'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 2131221: { // EXCESS CAB ALT + flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], + simVarIsActive: MappedSubject.create(([aircraftOnGround, excessPressure]) => !aircraftOnGround && excessPressure, this.aircraftOnGround, this.excessPressure), + // TODO no separate slats indication + whichCodeToReturn: () => [ + 0, + this.cabAltSetResetState1.get() ? 1 : null, + this.cabAltSetResetState2.get() && this.seatBelt.get() !== 1 ? 2 : null, + this.cabAltSetResetState2.get() ? 3 : null, + this.cabAltSetResetState1.get() ? 4 : null, + this.cabAltSetResetState2.get() && (this.throttle1Position.get() !== 0 || this.throttle2Position.get() !== 0) && this.autoThrustStatus.get() !== 2 ? 5 : null, + this.cabAltSetResetState2.get() && !this.speedBrakeCommand.get() ? 6 : null, + this.cabAltSetResetState2.get() ? 7 : null, + this.cabAltSetResetState2.get() && this.engSelectorPosition.get() !== 2 ? 8 : null, + this.cabAltSetResetState2.get() ? 9 : null, + this.cabAltSetResetState1.get() && !this.cabAltSetResetState2.get() ? 10 : null, + this.cabAltSetResetState2.get() ? 11 : null, + this.cabAltSetResetState2.get() ? 12 : null, + this.cabAltSetResetState2.get() ? 13 : null, + 14, + 15, + 16, + ], + codesToReturn: ['213122101', '213122102', '213122103', '213122104', '213122105', + '213122106', '213122107', '213122108', '213122109', '213122110', '213122111', '213122112', '213122113', '213122114', '213122115', '213122116'], + memoInhibit: () => false, + failure: 3, + sysPage: 2, + side: 'LEFT', + }, + 2600150: { // SMOKE FWD CARGO SMOKE + flightPhaseInhib: [4, 5, 7, 8], + simVarIsActive: this.cargoFireTest, + // TODO no separate slats indication + whichCodeToReturn: () => [ + 0, + SimVar.GetSimVarValue('L:A32NX_OVHD_VENT_CAB_FANS_PB_IS_ON', 'bool') === 1 ? 2 : null, + [1, 10].includes(this.fwcFlightPhase.get()) && !this.cargoFireAgentDisch.get() ? 3 : null, + !this.cargoFireAgentDisch.get() ? 4 : null, + !this.aircraftOnGround.get() ? 5 : null, + !this.aircraftOnGround.get() ? 6 : null, + this.aircraftOnGround.get() ? 7 : null, + this.aircraftOnGround.get() ? 8 : null, + ], + codesToReturn: ['260015001', '260015002', '260015003', '260015004', '260015005', '260015006', '260015007', '260015008', '260015009'], + memoInhibit: () => false, + failure: 3, + sysPage: -1, + side: 'LEFT', + }, + 7700647: { // THR LEVERS NOT SET (on ground) + flightPhaseInhib: [1, 4, 5, 6, 7, 8, 10], + simVarIsActive: MappedSubject.create( + ([throttle1Position, throttle2Position, thrustLeverNotSet]) => (throttle1Position !== 35 && thrustLeverNotSet) || (throttle2Position !== 35 && thrustLeverNotSet), + this.throttle1Position, this.throttle2Position, this.thrustLeverNotSet, + ), + whichCodeToReturn: () => [ + 0, + this.autothrustLeverWarningFlex.get() ? 1 : null, + this.autothrustLeverWarningToga.get() ? 2 : null, + ], + codesToReturn: ['770064701', '770064702', '770064703'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 2161207: { // PACK 1 ABNORMALLY OFF + flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], + simVarIsActive: this.packOffNotFailed1Status, + whichCodeToReturn: () => [0], + codesToReturn: ['216120701'], + memoInhibit: () => false, + failure: 2, + sysPage: 1, + side: 'LEFT', + }, + 2161208: { // PACK 2 ABNORMALLY OFF + flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], + simVarIsActive: this.packOffNotFailed2Status, + whichCodeToReturn: () => [0], + codesToReturn: ['216120801'], + memoInhibit: () => false, + failure: 2, + sysPage: 1, + side: 'LEFT', + }, + 3200060: { // NW ANTI SKID INACTIVE + flightPhaseInhib: [4, 5], + simVarIsActive: this.antiskidActive.map((v) => !v), + whichCodeToReturn: () => [0, 1], + codesToReturn: ['320006001', '320006002'], + memoInhibit: () => false, + failure: 2, + sysPage: 9, + side: 'LEFT', + }, + 3200180: { // LGCIU 1 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: MappedSubject.create( + ([lgciu1Fault, lgciu2Fault, dcESSBusPowered]) => lgciu1Fault && !(lgciu1Fault && lgciu2Fault) && dcESSBusPowered, + this.lgciu1Fault, this.lgciu2Fault, this.dcESSBusPowered, + ), + whichCodeToReturn: () => [0, !SimVar.GetSimVarValue('L:A32NX_GPWS_SYS_OFF', 'Bool') ? 1 : null], + codesToReturn: ['320018001', '320018002'], + memoInhibit: () => false, + failure: 1, + sysPage: -1, + side: 'LEFT', + }, + 3200190: { // LGCIU 2 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: MappedSubject.create( + ([lgciu1Fault, lgciu2Fault, dc2BusPowered]) => lgciu2Fault && !(lgciu1Fault && lgciu2Fault) && dc2BusPowered, + this.lgciu1Fault, this.lgciu2Fault, this.dc2BusPowered, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['320019001'], + memoInhibit: () => false, + failure: 1, + sysPage: -1, + side: 'LEFT', + }, + 3200195: { // LGCIU 1+2 FAULT + flightPhaseInhib: [4, 5, 7, 8], + simVarIsActive: MappedSubject.create( + ([lgciu1Fault, lgciu2Fault, dc2BusPowered, dcESSBusPowered]) => lgciu1Fault && lgciu2Fault && dc2BusPowered && dcESSBusPowered, + this.lgciu1Fault, this.lgciu2Fault, this.dc2BusPowered, this.dcESSBusPowered, + ), + whichCodeToReturn: () => [0, 1, !SimVar.GetSimVarValue('L:A32NX_GPWS_SYS_OFF', 'Bool') ? 2 : null], + codesToReturn: ['320019501', '320019502', '320019503'], + memoInhibit: () => false, + failure: 2, + sysPage: 9, + side: 'LEFT', + }, + 3400140: { // RA 1 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: MappedSubject.create(([height1Failed, ac1BusPowered]) => height1Failed && ac1BusPowered, this.height1Failed, this.ac1BusPowered), + whichCodeToReturn: () => [0], + codesToReturn: ['340014001'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 3400150: { // RA 2 FAULT + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: MappedSubject.create(([height2Failed, ac2BusPowered]) => height2Failed && ac2BusPowered, this.height2Failed, this.ac2BusPowered), + whichCodeToReturn: () => [0], + codesToReturn: ['340015001'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 3400500: { // TCAS FAULT + flightPhaseInhib: [1, 3, 4, 5, 7, 8, 10], + simVarIsActive: this.tcasFault, + whichCodeToReturn: () => [0], + codesToReturn: ['340050001'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 3400507: { // NAV TCAS STBY (in flight) + flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], + simVarIsActive: this.tcasSensitivity.map((v) => v === 1), + whichCodeToReturn: () => [0], + codesToReturn: ['340050701'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 3200010: { // L/G-BRAKES OVHT + flightPhaseInhib: [4, 8, 9, 10], + simVarIsActive: MappedSubject.create( + ([toConfigNormal, fwcFlightPhase, brakesHot]) => (toConfigNormal || fwcFlightPhase === 3) && brakesHot, + this.toConfigNormal, this.fwcFlightPhase, this.brakesHot, + ), + whichCodeToReturn: () => [ + 0, + !this.aircraftOnGround.get() ? 1 : null, + [1, 10].includes(this.fwcFlightPhase.get()) ? 2 : null, + !this.aircraftOnGround.get() ? 3 : null, + [1, 2].includes(this.fwcFlightPhase.get()) && !this.brakeFan.get() ? 4 : null, + this.aircraftOnGround.get() ? 5 : null, + !this.aircraftOnGround.get() ? 6 : null, + !this.aircraftOnGround.get() ? 7 : null, + !this.aircraftOnGround.get() ? 8 : null, + ], + codesToReturn: ['320001001', '320001002', '320001003', '320001004', '320001005', '320001006', '320001007', '320001008', '320001009'], + memoInhibit: () => false, + failure: 2, + sysPage: 9, + side: 'LEFT', + }, + 3081186: { // SEVERE ICE DETECTED + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.iceSevereDetectedTimerStatus, + whichCodeToReturn: () => [ + 0, + !this.wingAntiIce.get() ? 1 : null, + this.engSelectorPosition.get() !== 2 ? 2 : null, + ], + codesToReturn: ['308128001', '308128002', '308128003'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 3081280: { // ICE DETECTED + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.iceDetectedTimer2Status, + whichCodeToReturn: () => [ + 0, + !this.eng1AntiIce.get() ? 1 : null, + !this.eng2AntiIce.get() ? 2 : null, + ], + codesToReturn: ['308128001', '308128002', '308128003'], + memoInhibit: () => false, + failure: 2, + sysPage: -1, + side: 'LEFT', + }, + 2900126: { // *HYD - Blue reservoir overheat + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.blueRvrOvht, + whichCodeToReturn: () => [ + 0, + this.blueElecPumpPBAuto.get() ? 1 : null, + ], + codesToReturn: ['290012601', '290012602'], + memoInhibit: () => false, + failure: 2, + sysPage: 4, + side: 'LEFT', + }, + 2900127: { // *HYD - Yellow reservoir overheat + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.yellowRvrOvht, + whichCodeToReturn: () => [ + 0, + this.ptuAuto.get() ? 1 : null, + this.eng2pumpPBisAuto.get() ? 2 : null, + !this.yepumpPBisAuto.get() ? 3 : null, + ], + codesToReturn: ['290012701', '290012702', '290012703', '290012704'], + memoInhibit: () => false, + failure: 2, + sysPage: 4, + side: 'LEFT', + }, + 2900128: { // *HYD - Green reservoir overheat + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.greenRvrOvht, + whichCodeToReturn: () => [ + 0, + this.ptuAuto.get() ? 1 : null, + this.eng1pumpPBisAuto.get() ? 2 : null, + ], + codesToReturn: ['290012801', '290012802', '290012803'], + memoInhibit: () => false, + failure: 2, + sysPage: 4, + side: 'LEFT', + }, + 2900310: { // *HYD - Blue + flightPhaseInhib: [1, 4, 5, 10], + simVarIsActive: MappedSubject.create( + ([blueRvrOvht, blueRvrLow, blueElecPumpPBAuto, dcESSBusPowered, ac1BusPowered, blueLP, emergencyGeneratorOn]) => !(blueRvrOvht || blueRvrLow || !blueElecPumpPBAuto) + && (!dcESSBusPowered || !ac1BusPowered) && blueLP && !emergencyGeneratorOn, + this.blueRvrOvht, this.blueRvrLow, this.blueElecPumpPBAuto, this.dcESSBusPowered, this.ac1BusPowered, this.blueLP, this.emergencyGeneratorOn, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['290031001'], + memoInhibit: () => false, + failure: 2, + sysPage: 4, + side: 'RIGHT', + }, + 2900312: { // *HYD - Green Engine 1 // + flightPhaseInhib: [1, 2, 9, 10], + simVarIsActive: MappedSubject.create( + ([greenLP, eng1pumpPBisAuto, emergencyGeneratorOn]) => greenLP + // && ENG 1 OUT - not implemented + && eng1pumpPBisAuto && !emergencyGeneratorOn, + this.greenLP, this.eng1pumpPBisAuto, this.emergencyGeneratorOn, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['290031201'], + memoInhibit: () => false, + failure: 2, + sysPage: 4, + side: 'RIGHT', + }, + } + + ewdMessageMemos: EWDMessageDict = { + '0000010': { // T.O MEMO + flightPhaseInhib: [1, 3, 6, 10], + simVarIsActive: this.toMemo.map((t) => !!t), + whichCodeToReturn: () => [ + this.autoBrake.get() === 3 ? 1 : 0, + SimVar.GetSimVarValue('L:A32NX_NO_SMOKING_MEMO', 'bool') === 1 + && SimVar.GetSimVarValue('A:CABIN SEATBELTS ALERT SWITCH', 'bool') === 1 ? 3 : 2, + SimVar.GetSimVarValue('L:A32NX_CABIN_READY', 'bool') ? 5 : 4, + this.spoilersArmed.get() ? 7 : 6, + SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') >= 1 + && SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') <= 3 ? 9 : 8, + SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool') ? 11 : 10, + ], + codesToReturn: ['000001001', '000001002', '000001003', '000001004', '000001005', '000001006', '000001007', '000001008', '000001009', '000001010', '000001011', '000001012'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000020': { // LANDING MEMO + flightPhaseInhib: [1, 2, 3, 4, 5, 9, 10], + simVarIsActive: this.ldgMemo.map((t) => !!t), + whichCodeToReturn: () => [ + SimVar.GetSimVarValue('GEAR HANDLE POSITION', 'bool') ? 1 : 0, + SimVar.GetSimVarValue('L:XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position', 'enum') !== 2 + && SimVar.GetSimVarValue('A:CABIN SEATBELTS ALERT SWITCH', 'bool') === 1 ? 3 : 2, + SimVar.GetSimVarValue('L:A32NX_CABIN_READY', 'bool') ? 5 : 4, + this.spoilersArmed.get() ? 7 : 6, + !SimVar.GetSimVarValue('L:A32NX_GPWS_FLAPS3', 'bool') && SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') !== 4 ? 8 : null, + !SimVar.GetSimVarValue('L:A32NX_GPWS_FLAPS3', 'bool') && SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') === 4 ? 9 : null, + SimVar.GetSimVarValue('L:A32NX_GPWS_FLAPS3', 'bool') === 1 && SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') !== 3 ? 10 : null, + SimVar.GetSimVarValue('L:A32NX_GPWS_FLAPS3', 'bool') === 1 && SimVar.GetSimVarValue('L:A32NX_FLAPS_HANDLE_INDEX', 'enum') === 3 ? 11 : null, + ], + codesToReturn: ['000002001', '000002002', '000002003', '000002004', '000002005', '000002006', '000002007', '000002008', '000002009', '000002010', '000002011', '000002012'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000050': { // REFUELING + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([fuel, usrStartRefueling]) => !!(fuel === 100 || usrStartRefueling), + this.fuel, this.usrStartRefueling), + + whichCodeToReturn: () => [0], + codesToReturn: ['000005001'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000030': { // IR IN ALIGN + flightPhaseInhib: [3, 4, 5, 6, 7, 8, 9, 10], + simVarIsActive: MappedSubject.create(([adirsRemainingAlignTime, adiru1State, adiru2State, adiru3State]) => { + const remainingTimeAbove240 = adirsRemainingAlignTime >= 240; + const allInState1 = adiru1State === 1 && adiru2State === 1 && adiru3State === 1; + + return remainingTimeAbove240 && allInState1; + }, this.adirsRemainingAlignTime, this.adiru1State, this.adiru2State, this.adiru3State), + whichCodeToReturn: () => [ + this.adirsMessage1( + this.adirsRemainingAlignTime.get(), + (this.engine1State.get() > 0 && this.engine1State.get() < 4) || (this.engine2State.get() > 0 && this.engine2State.get() < 4), + ), + ], + codesToReturn: ['000003001', '000003002', '000003003', '000003004', '000003005', '000003006', '000003007', '000003008'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000031': { // IR IN ALIGN + flightPhaseInhib: [3, 4, 5, 6, 7, 8, 9, 10], + simVarIsActive: MappedSubject.create(([adirsRemainingAlignTime, adiru1State, adiru2State, adiru3State]) => { + const remainingTimeAbove0 = adirsRemainingAlignTime > 0; + const remainingTimeBelow240 = adirsRemainingAlignTime < 240; + const allInState1 = adiru1State === 1 && adiru2State === 1 && adiru3State === 1; + + return remainingTimeAbove0 && remainingTimeBelow240 && allInState1; + }, this.adirsRemainingAlignTime, this.adiru1State, this.adiru2State, this.adiru3State), + whichCodeToReturn: () => [ + this.adirsMessage2( + this.adirsRemainingAlignTime.get(), + (this.engine1State.get() > 0 && this.engine1State.get() < 4) || (this.engine2State.get() > 0 && this.engine2State.get() < 4), + ), + ], + codesToReturn: ['000003101', '000003102', '000003103', '000003104', '000003105', '000003106', '000003107', '000003108'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000055': { // SPOILERS ARMED + flightPhaseInhib: [], + simVarIsActive: this.spoilersArmed, + whichCodeToReturn: () => [0], + codesToReturn: ['000005501'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000080': { // SEAT BELTS + flightPhaseInhib: [], + simVarIsActive: this.seatBelt.map((v) => !!v), + whichCodeToReturn: () => [0], + codesToReturn: ['000008001'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000090': { // NO SMOKING + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([noSmoking, configPortableDevices]) => noSmoking === 1 && !configPortableDevices, this.noSmoking, this.configPortableDevices), + whichCodeToReturn: () => [0], + codesToReturn: ['000009001'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000095': { // PORTABLE DEVICES + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([noSmoking, configPortableDevices]) => noSmoking === 1 && !!configPortableDevices, this.noSmoking, this.configPortableDevices), + whichCodeToReturn: () => [0], + codesToReturn: ['000009501'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000100': { // STROBE LIGHT OFF + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([aircraftOnGround, strobeLightsOn]) => !!(!aircraftOnGround && strobeLightsOn === 2), this.aircraftOnGround, this.strobeLightsOn), + whichCodeToReturn: () => [0], + codesToReturn: ['000010001'], + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000105': { // OUTR TK FUEL XFRD + flightPhaseInhib: [], // Plus check that outer tanks not empty + simVarIsActive: MappedSubject.create( + ([leftOuterInnerValve, rightOuterInnerValve]) => !!leftOuterInnerValve || !!rightOuterInnerValve, this.leftOuterInnerValve, this.rightOuterInnerValve, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['000010501'], // config memo + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000305': { // GPWS FLAP MODE OFF + flightPhaseInhib: [], + simVarIsActive: this.gpwsFlapMode.map((v) => !!v), + whichCodeToReturn: () => [0], + codesToReturn: ['000030501'], // Not inhibited + memoInhibit: () => (this.toMemo.get() === 1 || this.ldgMemo.get() === 1), + failure: 0, + sysPage: -1, + side: 'LEFT', + }, + '0000140': { // T.O. INHIBIT + flightPhaseInhib: [], + simVarIsActive: this.showTakeoffInhibit, + whichCodeToReturn: () => [0], + codesToReturn: ['000014001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000150': { // LDG INHIBIT + flightPhaseInhib: [], + simVarIsActive: this.showLandingInhibit, + whichCodeToReturn: () => [0], + codesToReturn: ['000015001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000350': { // LAND ASAP RED + flightPhaseInhib: [], + simVarIsActive: this.landAsapRed, + whichCodeToReturn: () => [0], + codesToReturn: ['000035001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000360': { // LAND ASAP AMBER + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create( + ([landAsapRed, aircraftOnGround, engine1State, engine2State]) => (!landAsapRed && !aircraftOnGround && (engine1State === 0 || engine2State === 0)), + this.landAsapRed, this.aircraftOnGround, this.engine1State, this.engine2State, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['000036001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000060': { // SPEED BRK + flightPhaseInhib: [1, 8, 9, 10], + simVarIsActive: this.speedBrakeCommand, + whichCodeToReturn: () => [![6, 7].includes(this.fwcFlightPhase.get()) ? 1 : 0], + codesToReturn: ['000006001', '000006002'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000200': { // PARK BRK + flightPhaseInhib: [3, 4, 5, 6, 7, 8], + simVarIsActive: this.parkBrake, + whichCodeToReturn: () => [0], + codesToReturn: ['000020001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000040': { // NW STRG DISC + flightPhaseInhib: [], + simVarIsActive: this.nwSteeringDisc, + whichCodeToReturn: () => [this.engine1State.get() > 0 || this.engine2State.get() > 0 ? 1 : 0], + codesToReturn: ['000004001', '000004002'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000160': { // PTU ON + flightPhaseInhib: [], + simVarIsActive: this.hydPTU, + whichCodeToReturn: () => [0], + codesToReturn: ['000016001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000210': { // RAT OUT + flightPhaseInhib: [], + simVarIsActive: this.ratDeployed.map((v) => v > 0), + whichCodeToReturn: () => [[1, 2].includes(this.fwcFlightPhase.get()) ? 1 : 0], + codesToReturn: ['000021001', '000021002'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000070': { // IGNITION + flightPhaseInhib: [], + simVarIsActive: this.engSelectorPosition.map((v) => v === 2), + whichCodeToReturn: () => [0], + codesToReturn: ['000007001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000540': { // PRED W/S OFF + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([predWSOn, fwcFlightPhase]) => !predWSOn && ![1, 10].includes(fwcFlightPhase), this.predWSOn, this.fwcFlightPhase), + whichCodeToReturn: () => [[3, 4, 5, 7, 8, 9].includes(this.fwcFlightPhase.get()) || SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool') ? 1 : 0], + codesToReturn: ['000054001', '000054002'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000545': { // TERR OFF + flightPhaseInhib: [1, 10], + simVarIsActive: this.gpwsTerrOff, + whichCodeToReturn: () => [[3, 4, 5, 7, 8, 9].includes(this.fwcFlightPhase.get()) || SimVar.GetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool') ? 1 : 0], + codesToReturn: ['000054501', '000054502'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000320': { // TCAS STBY + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([tcasSensitivity, fwcFlightPhase]) => tcasSensitivity === 1 && fwcFlightPhase !== 6, this.tcasSensitivity, this.fwcFlightPhase), + whichCodeToReturn: () => [0], + codesToReturn: ['000032001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000325': { // TCAS STBY in flight + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([tcasSensitivity, fwcFlightPhase]) => tcasSensitivity === 1 && fwcFlightPhase === 6, this.tcasSensitivity, this.fwcFlightPhase), + whichCodeToReturn: () => [0], + codesToReturn: ['000032501'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000552': { // COMPANY MESSAGE + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.compMesgCount.map((v) => v > 0), + whichCodeToReturn: () => [0], + codesToReturn: ['000055201'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000260': { // ENG ANTI ICE + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: MappedSubject.create(([eng1AntiIce, eng2AntiIce]) => eng1AntiIce || eng2AntiIce, this.eng1AntiIce, this.eng2AntiIce), + whichCodeToReturn: () => [0], + codesToReturn: ['000026001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000270': { // WING ANTI ICE + flightPhaseInhib: [], + simVarIsActive: this.wingAntiIce, + whichCodeToReturn: () => [0], + codesToReturn: ['000027001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000275': { // ICE NOT DETECTED + flightPhaseInhib: [1, 2, 3, 4, 8, 9, 10], + simVarIsActive: MappedSubject.create( + ([iceNotDetTimer2Status, aircraftOnGround]) => iceNotDetTimer2Status && !aircraftOnGround, + this.iceNotDetTimer2Status, this.aircraftOnGround, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['000027501'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000170': { // APU AVAIL + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([apuAvail, apuBleedValveOpen]) => apuAvail === 1 && !apuBleedValveOpen, this.apuAvail, this.apuBleedValveOpen), + whichCodeToReturn: () => [0], + codesToReturn: ['000017001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000180': { // APU BLEED + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([apuAvail, apuBleedValveOpen]) => apuAvail === 1 && apuBleedValveOpen, this.apuAvail, this.apuBleedValveOpen), + whichCodeToReturn: () => [0], + codesToReturn: ['000018001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000190': { // LDG LT + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create( + ([landingLight2Retracted, landingLight3Retracted]) => !landingLight2Retracted || !landingLight3Retracted, this.landingLight2Retracted, this.landingLight3Retracted, + ), + whichCodeToReturn: () => [0], + codesToReturn: ['000019001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000220': { // BRAKE FAN + flightPhaseInhib: [], + simVarIsActive: this.brakeFan, + whichCodeToReturn: () => [0], + codesToReturn: ['000022001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000290': { // SWITCHING PNL + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([ndXfrKnob, dmcSwitchingKnob]) => ndXfrKnob !== 1 || dmcSwitchingKnob !== 1, this.ndXfrKnob, this.dmcSwitchingKnob), + whichCodeToReturn: () => [0], + codesToReturn: ['000029001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000300': { // GPWS FLAPS 3 + flightPhaseInhib: [], + simVarIsActive: this.gpwsFlaps3, + whichCodeToReturn: () => [0], + codesToReturn: ['000030001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000022': { // AUTOBRAKE + flightPhaseInhib: [], + simVarIsActive: this.fwcFlightPhase.map((v) => v === 7 || v === 8), + whichCodeToReturn: () => [this.autoBrake.get() - 1], + codesToReturn: ['000002201', '000002202', '000002203', '000002204'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000230': { // MAN LANDING ELEVATION + flightPhaseInhib: [], + simVarIsActive: this.manLandingElevation.map((v) => v > 0), + whichCodeToReturn: () => [0], + codesToReturn: ['000023001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000250': { // FUEL X FEED + flightPhaseInhib: [], + simVarIsActive: this.fuelXFeedPBOn, + whichCodeToReturn: () => [[3, 4, 5].includes(this.fwcFlightPhase.get()) ? 1 : 0], + codesToReturn: ['000025001', '000025002'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000680': { // ADIRS SWTG + flightPhaseInhib: [], + simVarIsActive: MappedSubject.create(([airKnob, attKnob]) => attKnob !== 1 || airKnob !== 1, this.airKnob, this.attKnob), + whichCodeToReturn: () => [0], + codesToReturn: ['000068001'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + '0000567': { // VHF3 VOICE + flightPhaseInhib: [3, 4, 5, 7, 8], + simVarIsActive: this.voiceVhf3.map((v) => v !== 0), + whichCodeToReturn: () => [0], + codesToReturn: ['000056701'], + memoInhibit: () => false, + failure: 0, + sysPage: -1, + side: 'RIGHT', + }, + }; +} diff --git a/fbw-a32nx/src/systems/instruments/src/EWD/elements/PseudoFWC.tsx b/fbw-a32nx/src/systems/instruments/src/EWD/elements/PseudoFWC.tsx deleted file mode 100644 index 452d413007d..00000000000 --- a/fbw-a32nx/src/systems/instruments/src/EWD/elements/PseudoFWC.tsx +++ /dev/null @@ -1,2100 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useSimVar } from '@instruments/common/simVars'; -import { NXDataStore } from '@shared/persistence'; -import { usePersistentProperty } from '@instruments/common/persistence'; -import { useUpdate } from '@instruments/common/hooks'; -import { NXLogicConfirmNode, NXLogicClockNode, NXLogicMemoryNode } from '@instruments/common/NXLogic'; -import { useArinc429Var } from '@instruments/common/arinc429'; -import { Arinc429Word } from '@shared/arinc429'; - -const mapOrder = (array, order) => { - array.sort((a, b) => { - if (order.indexOf(a) > order.indexOf(b)) { - return 1; - } - return -1; - }); - return array; -}; - -const adirsMessage1 = (adirs, engineRunning) => { - let rowChoice = 0; - switch (true) { - case (Math.ceil(adirs / 60) >= 7 && !engineRunning): - rowChoice = 0; - break; - case (Math.ceil(adirs / 60) >= 7 && engineRunning): - rowChoice = 1; - break; - case (Math.ceil(adirs / 60) === 6 && !engineRunning): - rowChoice = 2; - break; - case (Math.ceil(adirs / 60) === 6 && engineRunning): - rowChoice = 3; - break; - case (Math.ceil(adirs / 60) === 5 && !engineRunning): - rowChoice = 4; - break; - case (Math.ceil(adirs / 60) === 5 && engineRunning): - rowChoice = 5; - break; - case (Math.ceil(adirs / 60) === 4 && !engineRunning): - rowChoice = 6; - break; - case (Math.ceil(adirs / 60) === 4 && engineRunning): - rowChoice = 7; - break; - default: - break; - } - return rowChoice; -}; - -const adirsMessage2 = (adirs, engineRunning) => { - let rowChoice = 0; - switch (true) { - case (Math.ceil(adirs / 60) === 3 && !engineRunning): - rowChoice = 0; - break; - case (Math.ceil(adirs / 60) === 3 && engineRunning): - rowChoice = 1; - break; - case (Math.ceil(adirs / 60) === 2 && !engineRunning): - rowChoice = 2; - break; - case (Math.ceil(adirs / 60) === 2 && engineRunning): - rowChoice = 3; - break; - case (Math.ceil(adirs / 60) === 1 && !engineRunning): - rowChoice = 4; - break; - case (Math.ceil(adirs / 60) === 1 && engineRunning): - rowChoice = 5; - break; - default: - break; - } - return rowChoice; -}; - -const PseudoFWC: React.FC = () => { - const [toInhibitTimer] = useState(() => new NXLogicConfirmNode(3)); - const [ldgInhibitTimer] = useState(() => new NXLogicConfirmNode(3)); - const [agent1Eng1DischargeTimer] = useState(() => new NXLogicClockNode(10, 0)); - const [agent2Eng1DischargeTimer] = useState(() => new NXLogicClockNode(30, 0)); - const [agent1Eng2DischargeTimer] = useState(() => new NXLogicClockNode(10, 0)); - const [agent2Eng2DischargeTimer] = useState(() => new NXLogicClockNode(30, 0)); - const [agentAPUDischargeTimer] = useState(() => new NXLogicClockNode(10, 0)); - const [iceSevereDetectedTimer] = useState(() => new NXLogicConfirmNode(40, false)); - const [iceDetectedTimer1] = useState(() => new NXLogicConfirmNode(40, false)); - const [iceDetectedTimer2] = useState(() => new NXLogicConfirmNode(5)); - const [iceNotDetTimer1] = useState(() => new NXLogicConfirmNode(60)); - const [iceNotDetTimer2] = useState(() => new NXLogicConfirmNode(130)); - const [packOffNotFailed1] = useState(() => new NXLogicConfirmNode(60)); - const [packOffNotFailed2] = useState(() => new NXLogicConfirmNode(60)); - const [packOffBleedAvailable1] = useState(() => new NXLogicConfirmNode(5, false)); - const [packOffBleedAvailable2] = useState(() => new NXLogicConfirmNode(5, false)); - const [cabAltSetReset1] = useState(() => new NXLogicMemoryNode()); - const [cabAltSetReset2] = useState(() => new NXLogicMemoryNode()); - const [elac1HydConfirmNode] = useState(() => new NXLogicConfirmNode(3, false)); - const [elac1FaultConfirmNode] = useState(() => new NXLogicConfirmNode(0.6, true)); - const [elac1HydConfirmNodeOutput, setElac1HydConfirmNodeOutput] = useState(false); - const [elac1FaultConfirmNodeOutput, setElac1FaultConfirmNodeOutput] = useState(false); - const [elac2HydConfirmNode] = useState(() => new NXLogicConfirmNode(3, false)); - const [elac2FaultConfirmNode] = useState(() => new NXLogicConfirmNode(0.6, true)); - const [elac2HydConfirmNodeOutput, setElac2HydConfirmNodeOutput] = useState(false); - const [elac2FaultConfirmNodeOutput, setElac2FaultConfirmNodeOutput] = useState(false); - const [altn1LawConfirmNode] = useState(() => new NXLogicConfirmNode(0.3, true)); - const [altn1LawConfirmNodeOutput, setAltn1LawConfirmNodeOutput] = useState(false); - const [altn2LawConfirmNode] = useState(() => new NXLogicConfirmNode(0.3, true)); - const [altn2LawConfirmNodeOutput, setAltn2LawConfirmNodeOutput] = useState(false); - - const [memoMessageLeft, setMemoMessageLeft] = useState([]); - const [memoMessageRight, setMemoMessageRight] = useState([]); - const [flightPhase] = useSimVar('L:A32NX_FWC_FLIGHT_PHASE', 'enum', 1000); - - /* SETTINGS */ - const [unit] = usePersistentProperty('CONFIG_USING_METRIC_UNIT', '1'); - const configPortableDevices = parseInt(NXDataStore.get('CONFIG_USING_PORTABLE_DEVICES', '0')); - - /* ANTI-ICE */ - const [eng1AntiIce] = useSimVar('ENG ANTI ICE:1', 'bool', 500); - const [eng2AntiIce] = useSimVar('ENG ANTI ICE:2', 'bool', 500); - const [wingAntiIce] = useSimVar('L:A32NX_PNEU_WING_ANTI_ICE_SYSTEM_SELECTED', 'bool', 500); - const [icePercentage] = useSimVar('STRUCTURAL ICE PCT', 'percent over 100', 500); - const [tat] = useSimVar('TOTAL AIR TEMPERATURE', 'celsius', 1000); - const [inCloud] = useSimVar('AMBIENT IN CLOUD', 'boolean', 1000); - - /* ELECTRICAL */ - const [engine1Generator] = useSimVar('L:A32NX_ELEC_ENG_GEN_1_POTENTIAL_NORMAL', 'bool', 500); - const [engine2Generator] = useSimVar('L:A32NX_ELEC_ENG_GEN_2_POTENTIAL_NORMAL', 'bool', 500); - const [emergencyElectricGeneratorPotential] = useSimVar('L:A32NX_ELEC_EMER_GEN_POTENTIAL', 'number', 500); - const [dcESSBusPowered] = useSimVar('L:A32NX_ELEC_DC_ESS_BUS_IS_POWERED', 'bool', 500); - const [dc2BusPowered] = useSimVar('L:A32NX_ELEC_DC_2_BUS_IS_POWERED', 'bool', 500); - const [ac1BusPowered] = useSimVar('L:A32NX_ELEC_AC_1_BUS_IS_POWERED', 'bool', 500); - const [ac2BusPowered] = useSimVar('L:A32NX_ELEC_AC_2_BUS_IS_POWERED', 'bool', 500); - const emergencyGeneratorOn = emergencyElectricGeneratorPotential > 0 ? 1 : 0; - - /* ENGINE AND THROTTLE */ - - const [engine1State] = useSimVar('L:A32NX_ENGINE_STATE:1', 'enum', 500); - const [engine2State] = useSimVar('L:A32NX_ENGINE_STATE:2', 'enum', 500); - const [throttle1Position] = useSimVar('L:A32NX_AUTOTHRUST_TLA:1', 'number', 100); - const [throttle2Position] = useSimVar('L:A32NX_AUTOTHRUST_TLA:2', 'number', 100); - const [engine1ValueSwitch] = useSimVar('FUELSYSTEM VALVE SWITCH:1', 'bool', 500); - const [engine2ValueSwitch] = useSimVar('FUELSYSTEM VALVE SWITCH:2', 'bool', 500); - const [N1Eng1] = useSimVar('L:A32NX_ENGINE_N1:1', 'number', 500); - const [N1Eng2] = useSimVar('L:A32NX_ENGINE_N1:2', 'number', 500); - const [N1IdleEng1] = useSimVar('L:A32NX_ENGINE_IDLE_N1:1', 'number', 500); - const [N1IdleEng2] = useSimVar('L:A32NX_ENGINE_IDLE_N1:2', 'number', 500); - const N1AboveIdle = Math.floor(N1Eng1) > N1IdleEng1 ? 1 : 0; - const N2AboveIdle = Math.floor(N1Eng2) > N1IdleEng2 ? 1 : 0; - const [autothrustLeverWarningFlex] = useSimVar('L:A32NX_AUTOTHRUST_THRUST_LEVER_WARNING_FLEX', 'bool', 500); - const [autothrustLeverWarningTOGA] = useSimVar('L:A32NX_AUTOTHRUST_THRUST_LEVER_WARNING_TOGA', 'bool', 500); - const thrustLeverNotSet = autothrustLeverWarningFlex === 1 || autothrustLeverWarningTOGA === 1; - const [engSelectorPosition] = useSimVar('L:XMLVAR_ENG_MODE_SEL', 'enum', 1000); - const [autoThrustStatus] = useSimVar('L:A32NX_AUTOTHRUST_STATUS', 'enum', 500); - - /* FIRE */ - - const [fireButton1] = useSimVar('L:A32NX_FIRE_BUTTON_ENG1', 'bool', 500); - const [fireButton2] = useSimVar('L:A32NX_FIRE_BUTTON_ENG2', 'bool', 500); - const [fireButtonAPU] = useSimVar('L:A32NX_FIRE_BUTTON_APU', 'bool', 500); - const [eng1FireTest] = useSimVar('L:A32NX_FIRE_TEST_ENG1', 'bool', 500); - const [eng2FireTest] = useSimVar('L:A32NX_FIRE_TEST_ENG2', 'bool', 500); - const [apuFireTest] = useSimVar('L:A32NX_FIRE_TEST_APU', 'bool', 500); - const [eng1Agent1PB] = useSimVar('L:A32NX_FIRE_ENG1_AGENT1_Discharge', 'bool', 500); - const [eng1Agent2PB] = useSimVar('L:A32NX_FIRE_ENG1_AGENT2_Discharge', 'bool', 500); - const [eng2Agent1PB] = useSimVar('L:A32NX_FIRE_ENG2_AGENT1_Discharge', 'bool', 500); - const [eng2Agent2PB] = useSimVar('L:A32NX_FIRE_ENG2_AGENT2_Discharge', 'bool', 500); - const [apuAgentPB] = useSimVar('L:A32NX_FIRE_APU_AGENT1_Discharge', 'bool', 500); - const [cargoFireTest] = useSimVar('L:A32NX_FIRE_TEST_CARGO', 'bool', 500); - const [cargoFireAgentDisch] = useSimVar('L:A32NX_CARGOSMOKE_FWD_DISCHARGED', 'bool', 500); - - useEffect(() => { - if (eng1FireTest === 0 && eng2FireTest === 0 && apuFireTest === 0 && cargoFireTest === 0) { - masterWarning(0); - } - }, [eng1FireTest, eng2FireTest, apuFireTest, cargoFireTest]); - - /* FUEL */ - const [fuel] = useSimVar('A:INTERACTIVE POINT OPEN:9', 'percent', 500); - const [fob] = useSimVar('FUEL TOTAL QUANTITY WEIGHT', 'kg', 500); - const fobRounded = Math.round(fob / 10) * 10; - const [usrStartRefueling] = useSimVar('L:A32NX_REFUEL_STARTED_BY_USR', 'bool', 500); - const [leftOuterInnerValve] = useSimVar('FUELSYSTEM VALVE OPEN:4', 'bool', 500); - const [rightOuterInnerValve] = useSimVar('FUELSYSTEM VALVE OPEN:5', 'bool', 500); - const [fuelXFeedPBOn] = useSimVar('L:XMLVAR_Momentary_PUSH_OVHD_FUEL_XFEED_Pressed', 'bool', 500); - - /* HYDRAULICS */ - const [greenLP] = useSimVar('L:A32NX_HYD_GREEN_EDPUMP_LOW_PRESS', 'bool', 500); - const [greenSysPressurised] = useSimVar('L:A32NX_HYD_GREEN_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool', 500); - const [greenHydEng1PBAuto] = useSimVar('L:A32NX_OVHD_HYD_ENG_1_PUMP_PB_IS_AUTO', 'bool', 500); - const [blueLP] = useSimVar('L:A32NX_HYD_BLUE_EDPUMP_LOW_PRESS', 'bool', 500); - const [blueSysPressurised] = useSimVar('L:A32NX_HYD_BLUE_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool', 500); - const [blueRvrLow] = useSimVar('L:A32NX_HYD_BLUE_RESERVOIR_LEVEL_IS_LOW', 'bool', 500); - - const [yellowRvrOvht] = useSimVar('L:A32NX_HYD_YELLOW_RESERVOIR_OVHT', 'bool', 500); - const [greenRvrOvht] = useSimVar('L:A32NX_HYD_GREEN_RESERVOIR_OVHT', 'bool', 500); - const [blueRvrOvht] = useSimVar('L:A32NX_HYD_BLUE_RESERVOIR_OVHT', 'bool', 500); - const [blueElecPumpPBAuto] = useSimVar('L:A32NX_OVHD_HYD_EPUMPB_PB_IS_AUTO', 'bool', 500); - const [yellowLP] = useSimVar('L:A32NX_HYD_YELLOW_EDPUMP_LOW_PRESS', 'bool', 500); - const [yellowSysPressurised] = useSimVar('L:A32NX_HYD_YELLOW_SYSTEM_1_SECTION_PRESSURE_SWITCH', 'bool', 500); - const [eng1pumpPBisAuto] = useSimVar('L:A32NX_OVHD_HYD_ENG_1_PUMP_PB_IS_AUTO', 'bool', 500); - const [eng2pumpPBisAuto] = useSimVar('L:A32NX_OVHD_HYD_ENG_2_PUMP_PB_IS_AUTO', 'bool', 500); - const [yepumpPBisAuto] = useSimVar('L:A32NX_OVHD_HYD_EPUMPY_PB_IS_AUTO', 'bool', 500); - const [ptuIsAuto] = useSimVar('L:A32NX_OVHD_HYD_PTU_PB_IS_AUTO', 'bool', 500); - const [hydPTU] = useSimVar('L:A32NX_HYD_PTU_ON_ECAM_MEMO', 'bool', 500); - const [ratDeployed] = useSimVar('L:A32NX_HYD_RAT_STOW_POSITION', 'percent over 100', 500); - - /* F/CTL */ - const fcdc1DiscreteWord1 = useArinc429Var('L:A32NX_FCDC_1_DISCRETE_WORD_1'); - const fcdc2DiscreteWord1 = useArinc429Var('L:A32NX_FCDC_2_DISCRETE_WORD_1'); - const fcdc1DiscreteWord2 = useArinc429Var('L:A32NX_FCDC_1_DISCRETE_WORD_2'); - const fcdc2DiscreteWord2 = useArinc429Var('L:A32NX_FCDC_2_DISCRETE_WORD_2'); - const fcdc1DiscreteWord3 = useArinc429Var('L:A32NX_FCDC_1_DISCRETE_WORD_3'); - const fcdc2DiscreteWord3 = useArinc429Var('L:A32NX_FCDC_2_DISCRETE_WORD_3'); - const fcdc1DiscreteWord4 = useArinc429Var('L:A32NX_FCDC_1_DISCRETE_WORD_4'); - const fcdc2DiscreteWord4 = useArinc429Var('L:A32NX_FCDC_2_DISCRETE_WORD_4'); - - const spoilersArmed = fcdc1DiscreteWord4.getBitValueOr(27, false) || fcdc2DiscreteWord4.getBitValueOr(27, false); - const speedBrakeCommand = fcdc1DiscreteWord4.getBitValueOr(28, false) || fcdc2DiscreteWord4.getBitValueOr(28, false); - - // ELAC 1 FAULT computation - const se1f = (fcdc1DiscreteWord1.getBitValueOr(19, false) || fcdc2DiscreteWord1.getBitValueOr(19, false)) - && (fcdc1DiscreteWord1.getBitValueOr(20, false) || fcdc2DiscreteWord1.getBitValueOr(20, false)); - const elac1FaultCondition = !([1, 10].includes(flightPhase) && (fcdc1DiscreteWord3.getBitValueOr(19, false) || fcdc2DiscreteWord3.getBitValueOr(19, false))) - && dcESSBusPowered - && ((fcdc1DiscreteWord1.getBitValueOr(23, false) || fcdc2DiscreteWord1.getBitValueOr(23, false)) || (!elac1HydConfirmNodeOutput && se1f)); - const elac1FaultLine123Display = !(fcdc1DiscreteWord3.getBitValueOr(19, false) || fcdc2DiscreteWord3.getBitValueOr(19, false)) - && (fcdc1DiscreteWord1.getBitValueOr(23, false) || fcdc2DiscreteWord1.getBitValueOr(23, false)); - const elac1FaultLine45Display = false; - - // ELAC 2 FAULT computation - const se2f = (fcdc1DiscreteWord1.getBitValueOr(21, false) || fcdc2DiscreteWord1.getBitValueOr(21, false)) - && (fcdc1DiscreteWord1.getBitValueOr(22, false) || fcdc2DiscreteWord1.getBitValueOr(22, false)); - const elac2FaultCondition = !([1, 10].includes(flightPhase) && (fcdc1DiscreteWord3.getBitValueOr(20, false) || fcdc2DiscreteWord3.getBitValueOr(20, false))) - && dc2BusPowered - && ((fcdc1DiscreteWord1.getBitValueOr(24, false) || fcdc2DiscreteWord1.getBitValueOr(24, false)) - || (!elac2HydConfirmNodeOutput && se2f)); - const elac2FaultLine123Display = !(fcdc1DiscreteWord3.getBitValueOr(20, false) || fcdc2DiscreteWord3.getBitValueOr(20, false)) - && (fcdc1DiscreteWord1.getBitValueOr(24, false) || fcdc2DiscreteWord1.getBitValueOr(24, false)); - const elac2FaultLine45Display = false; - - // SEC 1 FAULT computation - const ss1f = fcdc1DiscreteWord1.getBitValueOr(25, false) || fcdc2DiscreteWord1.getBitValueOr(25, false); - const sec1FaultCondition = !([1, 10].includes(flightPhase) && (fcdc1DiscreteWord3.getBitValueOr(27, false) || fcdc2DiscreteWord3.getBitValueOr(27, false))) - && dcESSBusPowered - && ss1f; - const sec1FaultLine123Display = !(fcdc1DiscreteWord3.getBitValueOr(27, false) || fcdc2DiscreteWord3.getBitValueOr(27, false)); - const sec1FaultLine45Display = false; - - // SEC 2 FAULT computation - const ss2f = fcdc1DiscreteWord1.getBitValueOr(26, false) || fcdc2DiscreteWord1.getBitValueOr(26, false); - const sec2FaultCondition = !([1, 10].includes(flightPhase) && (fcdc1DiscreteWord3.getBitValueOr(28, false) || fcdc2DiscreteWord3.getBitValueOr(28, false))) - && dc2BusPowered - && ss2f; - const sec2FaultLine123Display = !(fcdc1DiscreteWord3.getBitValueOr(28, false) || fcdc2DiscreteWord3.getBitValueOr(28, false)); - - // SEC 3 FAULT computation - const ss3f = fcdc1DiscreteWord1.getBitValueOr(29, false) || fcdc2DiscreteWord1.getBitValueOr(29, false); - const sec3FaultCondition = !([1, 10].includes(flightPhase) && (fcdc1DiscreteWord3.getBitValueOr(29, false) || fcdc2DiscreteWord3.getBitValueOr(29, false))) - && dc2BusPowered - && ss3f; - const sec3FaultLine123Display = !(fcdc1DiscreteWord3.getBitValueOr(29, false) || fcdc2DiscreteWord3.getBitValueOr(29, false)); - - // FCDC 1+2 FAULT computation - const SFCDC1FT = fcdc1DiscreteWord1.isFailureWarning() && fcdc1DiscreteWord2.isFailureWarning() && fcdc1DiscreteWord3.isFailureWarning(); - const SFCDC2FT = fcdc2DiscreteWord1.isFailureWarning() && fcdc2DiscreteWord2.isFailureWarning() && fcdc2DiscreteWord3.isFailureWarning(); - const SFCDC12FT = SFCDC1FT && SFCDC2FT; - const fcdc12FaultCondition = SFCDC12FT && dc2BusPowered; - const fcdc1FaultCondition = SFCDC1FT && !SFCDC12FT; - const fcdc2FaultCondition = SFCDC2FT && !(SFCDC12FT || !dc2BusPowered); - - // ALTN LAW 2 computation - const SPA2 = fcdc1DiscreteWord1.getBitValueOr(13, false) || fcdc2DiscreteWord1.getBitValueOr(13, false); - const altn2Condition = SPA2 && ![1, 10].includes(flightPhase); - - // ALTN LAW 1 computation - const SPA1 = fcdc1DiscreteWord1.getBitValueOr(12, false) || fcdc2DiscreteWord1.getBitValueOr(12, false); - const altn1Condition = SPA1 && ![1, 10].includes(flightPhase); - - // DIRECT LAW computation - const SPBUL = (false && SFCDC12FT) || (fcdc1DiscreteWord1.getBitValueOr(15, false) || fcdc2DiscreteWord1.getBitValueOr(15, false)); - const directLawCondition = SPBUL && ![1, 10].includes(flightPhase); - - // L+R ELEV FAULT computation - const lhElevBlueFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(15, false)) - || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(15, false)); - const lhElevGreenFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(16, false)) - || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(16, false)); - const rhElevBlueFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(17, false)) - || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(17, false)); - const rhElevGreenFail = (fcdc1DiscreteWord3.isNormalOperation() && !fcdc1DiscreteWord3.getBitValueOr(18, false)) - || (fcdc2DiscreteWord3.isNormalOperation() && !fcdc2DiscreteWord3.getBitValueOr(18, false)); - const lrElevFaultCondition = lhElevBlueFail && lhElevGreenFail && rhElevBlueFail && rhElevGreenFail && ![1, 10].includes(flightPhase); - - /* LANDING GEAR AND LIGHTS */ - // const [left1LandingGear] = useSimVar('L:A32NX_LGCIU_1_LEFT_GEAR_COMPRESSED', 'bool', 500); - // const [right1LandingGear] = useSimVar('L:A32NX_LGCIU_1_RIGHT_GEAR_COMPRESSED', 'bool', 500); - // const aircraftOnGround = left1LandingGear === 1 || right1LandingGear === 1; - // FIXME The landing gear triggers the dual engine failure on loading - const aircraftOnGround = SimVar.GetSimVarValue('SIM ON GROUND', 'Bool'); - const [landingGearLeverDown] = useSimVar('L:A32NX_GEAR_HANDLE_POSITION', 'bool', 500); - const [landingLight2Retracted] = useSimVar('L:LANDING_2_Retracted', 'bool', 500); - const [landingLight3Retracted] = useSimVar('L:LANDING_3_Retracted', 'bool', 500); - const [autoBrakesArmedMode] = useSimVar('L:A32NX_AUTOBRAKES_ARMED_MODE', 'enum', 500); - const [antiskidActive] = useSimVar('ANTISKID BRAKES ACTIVE', 'bool', 500); - const [lgciu1Fault] = useSimVar('L:A32NX_LGCIU_1_FAULT', 'bool', 500); - const [lgciu2Fault] = useSimVar('L:A32NX_LGCIU_2_FAULT', 'bool', 500); - - /* OTHER STUFF */ - - const [seatBelt] = useSimVar('A:CABIN SEATBELTS ALERT SWITCH', 'bool', 500); - const [noSmoking] = useSimVar('L:A32NX_NO_SMOKING_MEMO', 'bool', 500); - const [noSmokingSwitchPosition] = useSimVar('L:XMLVAR_SWITCH_OVHD_INTLT_NOSMOKING_Position', 'enum', 500); - - const [strobeLightsOn] = useSimVar('L:LIGHTING_STROBE_0', 'bool', 500); - - const [gpwsFlapMode] = useSimVar('L:A32NX_GPWS_FLAP_OFF', 'bool', 500); - const [tomemo] = useSimVar('L:A32NX_FWC_TOMEMO', 'bool', 500); - const [ldgmemo] = useSimVar('L:A32NX_FWC_LDGMEMO', 'bool', 500); - - const [autoBrake] = useSimVar('L:A32NX_AUTOBRAKES_ARMED_MODE', 'enum', 500); - const [flapsHandle] = useSimVar('L:A32NX_FLAPS_HANDLE_INDEX', 'enum', 500); - const [flapsIndex] = useSimVar('L:A32NX_FLAPS_CONF_INDEX', 'number', 100); - - const [slatsAngle] = useSimVar('L:A32NX_LEFT_SLATS_ANGLE', 'degrees', 100); - const slatsInfD = slatsAngle <= 17; - const slatsSupG = slatsAngle >= 25; - - const [flapsAngle] = useSimVar('L:A32NX_LEFT_FLAPS_ANGLE', 'degrees', 100); - const flapsInfA = flapsAngle <= 2; - const flapsSupF = flapsAngle >= 24; - - const [toconfig] = useSimVar('L:A32NX_TO_CONFIG_NORMAL', 'bool', 100); - - const [adirsRemainingAlignTime] = useSimVar('L:A32NX_ADIRS_REMAINING_IR_ALIGNMENT_TIME', 'seconds', 1000); - const [adiru1State] = useSimVar('L:A32NX_ADIRS_ADIRU_1_STATE', 'enum', 500); - const [adiru2State] = useSimVar('L:A32NX_ADIRS_ADIRU_2_STATE', 'enum', 500); - const [adiru3State] = useSimVar('L:A32NX_ADIRS_ADIRU_3_STATE', 'enum', 500); - - const [callPushAll] = useSimVar('L:PUSH_OVHD_CALLS_ALL', 'bool', 100); - const [callPushForward] = useSimVar('L:PUSH_OVHD_CALLS_FWD', 'bool', 100); - const [callPushAft] = useSimVar('L:PUSH_OVHD_CALLS_AFT', 'bool', 100); - const [cabinReady] = useSimVar('L:A32NX_CABIN_READY', 'bool'); - - const [toconfigBtn] = useSimVar('L:A32NX_BTN_TOCONFIG', 'bool'); - const [flapsMcdu] = useSimVar('L:A32NX_TO_CONFIG_FLAPS', 'number', 500); - const [flapsMcduEntered] = useSimVar('L:A32NX_TO_CONFIG_FLAPS_ENTERED', 'bool', 500); - const [parkBrake] = useSimVar('L:A32NX_PARK_BRAKE_LEVER_POS', 'bool', 500); - const [brakesHot] = useSimVar('L:A32NX_BRAKES_HOT', 'bool', 500); - const [v1Speed] = useSimVar('L:AIRLINER_V1_SPEED', 'knots', 500); - const [vrSpeed] = useSimVar('L:AIRLINER_VR_SPEED', 'knots', 500); - const [v2Speed] = useSimVar('L:AIRLINER_V2_SPEED', 'knots'); - const [cabin] = useSimVar('INTERACTIVE POINT OPEN:0', 'percent', 1000); - const [catering] = useSimVar('INTERACTIVE POINT OPEN:3', 'percent', 1000); - const [cargofwdLocked] = useSimVar('L:A32NX_FWD_DOOR_CARGO_LOCKED', 'bool', 1000); - const [cargoaftLocked] = useSimVar('L:A32NX_AFT_DOOR_CARGO_LOCKED', 'bool', 1000); - const [apuMasterSwitch] = useSimVar('L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON', 'bool', 500); - const [flightPhaseInhibitOverride] = useSimVar('L:A32NX_FWC_INHIBOVRD', 'bool', 500); - const [nwSteeringDisc] = useSimVar('L:A32NX_HYD_NW_STRG_DISC_ECAM_MEMO', 'bool', 500); - const [predWSOn] = useSimVar('L:A32NX_SWITCH_RADAR_PWS_Position', 'bool', 1000); - const [gpwsTerrOff] = useSimVar('L:A32NX_GPWS_TERR_OFF', 'bool', 500); - const [gpwsSysOff] = useSimVar('L:A32NX_GPWS_SYS_OFF', 'Bool'); - const [tcasMode] = useSimVar('L:A32NX_TCAS_MODE', 'enum', 500); - const [tcasSensitivity] = useSimVar('L:A32NX_TCAS_SENSITIVITY', 'enum', 500); - const [compMesgCount] = useSimVar('L:A32NX_COMPANY_MSG_COUNT', 'number', 500); - const height1: Arinc429Word = useArinc429Var('L:A32NX_RA_1_RADIO_ALTITUDE'); - const height2: Arinc429Word = useArinc429Var('L:A32NX_RA_2_RADIO_ALTITUDE'); - const height1Failed = height1.isFailureWarning(); - const height2Failed = height2.isFailureWarning(); - - const [apuBleedValveOpen] = useSimVar('L:A32NX_APU_BLEED_AIR_VALVE_OPEN', 'bool', 500); - const [apuAvail] = useSimVar('L:A32NX_OVHD_APU_START_PB_IS_AVAILABLE', 'bool', 500); - - const [brakeFan] = useSimVar('L:A32NX_BRAKE_FAN', 'bool', 500); - const [dmcSwitchingKnob] = useSimVar('L:A32NX_EIS_DMC_SWITCHING_KNOB', 'enum', 500); - const [ndXfrKnob] = useSimVar('L:A32NX_ECAM_ND_XFR_SWITCHING_KNOB', 'bool', 500); - const [gpwsFlaps3] = useSimVar('L:A32NX_GPWS_FLAPS3', 'bool', 500); - const [manLandingElevation] = useSimVar('L:XMLVAR_KNOB_OVHD_CABINPRESS_LDGELEV', 'number', 500); - const [ATTKnob] = useSimVar('L:A32NX_ATT_HDG_SWITCHING_KNOB', 'enum', 500); - const [AIRKnob] = useSimVar('L:A32NX_AIR_DATA_SWITCHING_KNOB', 'enum', 500); - - const [radioAlt] = useSimVar('PLANE ALT ABOVE GROUND MINUS CG', 'Feet', 500); - const [fac1Failed] = useSimVar('L:A32NX_FBW_FAC_FAILED:1', 'bool', 500); - const [tcasFault] = useSimVar('L:A32NX_TCAS_FAULT', 'bool', 500); - - const [cabinRecircBtnOn] = useSimVar('L:A32NX_OVHD_VENT_CAB_FANS_PB_IS_ON', 'bool', 500); - const computedAirSpeed: Arinc429Word = useArinc429Var('L:A32NX_ADIRS_ADR_1_COMPUTED_AIRSPEED', 1000); - // Reduce number of rewrites triggered by this value - const computedAirSpeedToNearest2 = Math.round(computedAirSpeed.value / 2) * 2; - const adirsAlt: Arinc429Word = useArinc429Var('L:A32NX_ADIRS_ADR_1_ALTITUDE', 500); - - /* PACKS */ - const [crossfeed] = useSimVar('L:A32NX_PNEU_XBLEED_VALVE_OPEN', 'bool', 500); - const [eng1Bleed] = useSimVar('A:BLEED AIR ENGINE:1', 'bool'); - const [eng1BleedPbFault] = useSimVar('L:A32NX_OVHD_PNEU_ENG_1_BLEED_PB_HAS_FAULT', 'bool', 500); - const [eng2Bleed] = useSimVar('A:BLEED AIR ENGINE:2', 'bool', 100); - const [eng2BleedPbFault] = useSimVar('L:A32NX_OVHD_PNEU_ENG_2_BLEED_PB_HAS_FAULT', 'bool', 500); - const [pack1Fault] = useSimVar('L:A32NX_OVHD_COND_PACK_1_PB_HAS_FAULT', 'bool'); - const [pack2Fault] = useSimVar('L:A32NX_OVHD_COND_PACK_2_PB_HAS_FAULT', 'bool'); - const [pack1On] = useSimVar('L:A32NX_OVHD_COND_PACK_1_PB_IS_ON', 'bool'); - const [pack2On] = useSimVar('L:A32NX_OVHD_COND_PACK_2_PB_IS_ON', 'bool'); - const [excessPressure] = useSimVar('L:A32NX_PRESS_EXCESS_CAB_ALT', 'bool', 500); - - const [voiceVHF3] = useSimVar('A:COM ACTIVE FREQUENCY:3', 'number', 500); - - /* WARNINGS AND FAILURES */ - const landASAPRed: boolean = !!(!aircraftOnGround - && ( - fireButton1 === 1 - || eng1FireTest === 1 - || fireButton2 === 1 - || eng2FireTest === 1 - || fireButtonAPU === 1 - || apuFireTest === 1 - || emergencyGeneratorOn - || (engine1State === 0 && engine2State === 0) - || (greenLP === 1 && yellowLP === 1) - || (yellowLP === 1 && blueLP === 1) - || (greenLP === 1 && blueLP === 1) - )); - - const engDualFault = !!(!aircraftOnGround && ( - (fireButton1 === 1 && fireButton2 === 1) - || (!engine1ValueSwitch && !engine2ValueSwitch) - || (engine1State === 0 && engine2State === 0) - || (!N1AboveIdle && !N2AboveIdle) - )); - - const [masterWarningButtonLeft] = useSimVar('L:PUSH_AUTOPILOT_MASTERAWARN_L', 'bool', 100); - const [masterCautionButtonLeft] = useSimVar('L:PUSH_AUTOPILOT_MASTERCAUT_L', 'bool', 100); - const [masterWarningButtonRight] = useSimVar('L:PUSH_AUTOPILOT_MASTERAWARN_R', 'bool', 100); - const [masterCautionButtonRight] = useSimVar('L:PUSH_AUTOPILOT_MASTERCAUT_R', 'bool', 100); - const [clearButtonLeft] = useSimVar('L:A32NX_BTN_CLR', 'bool'); - const [clearButtonRight] = useSimVar('L:A32NX_BTN_CLR2', 'bool'); - const [recallButton] = useSimVar('L:A32NX_BTN_RCL', 'bool'); - const [failuresLeft, setFailuresLeft] = useState([]); - const [failuresRight, setFailuresRight] = useState([]); - const [allCurrentFailures, setAllCurrentFailures] = useState([]); - const [recallFailures, setRecallFailures] = useState([]); - const [recallReset, setRecallReset] = useState(true); - const [toconfigFailed, setToConfigFailed] = useState(false); - - const masterWarning = (toggle: number) => { - SimVar.SetSimVarValue('L:A32NX_MASTER_WARNING', 'Bool', toggle); - SimVar.SetSimVarValue('L:Generic_Master_Warning_Active', 'Bool', toggle); - }; - - const masterCaution = (toggle: number) => { - SimVar.SetSimVarValue('L:A32NX_MASTER_CAUTION', 'Bool', toggle); - SimVar.SetSimVarValue('L:Generic_Master_Caution_Active', 'Bool', toggle); - }; - - useEffect(() => { - masterWarning(0); - }, [masterWarningButtonLeft, masterWarningButtonRight]); - - useEffect(() => { - masterCaution(0); - }, [masterCautionButtonLeft, masterCautionButtonRight]); - - useEffect(() => { - if (clearButtonLeft === 1 || clearButtonRight === 1) { - if (typeof failuresLeft !== 'undefined' && failuresLeft.length > 0) { - const updatedLeftFailures = failuresLeft.slice(1); - const updatedRecallFailures = allCurrentFailures.filter((item) => !updatedLeftFailures.includes(item)); - setRecallFailures(updatedRecallFailures); - setFailuresLeft(updatedLeftFailures); - } - } - setRecallReset(!recallReset); - SimVar.SetSimVarValue('L:A32NX_BTN_CLR', 'Bool', 0); - SimVar.SetSimVarValue('L:A32NX_BTN_CLR2', 'Bool', 0); - }, [clearButtonLeft, clearButtonRight]); - - useEffect(() => { - if (recallButton === 1) { - if (recallFailures.length > 0) { - const recall = recallFailures[0]; - const updatedRecallFailures = recallFailures.slice(1); - const updatedLeftFailures: string[] = failuresLeft.concat([recall]); - setRecallFailures(updatedRecallFailures); - setFailuresLeft(updatedLeftFailures); - } - setRecallReset(!recallReset); - } - }, [recallButton]); - - /* TICK CHECK */ - let showTakeoffInhibit = false; - let showLandingInhibit = false; - const [agent1Eng1Discharge, setAgent1Eng1Discharge] = useState(0); - const [agent2Eng1Discharge, setAgent2Eng1Discharge] = useState(0); - const [agent1Eng2Discharge, setAgent1Eng2Discharge] = useState(0); - const [agent2Eng2Discharge, setAgent2Eng2Discharge] = useState(0); - const [agentAPUDischarge, setAgentAPUDischarge] = useState(0); - const [iceDetected1, setIceDetected1] = useState(0); - const [iceDetected2, setIceDetected2] = useState(0); - const [iceSevereDetected, setIceSevereDetected] = useState(0); - const [iceNotDetected1, setIceNotDetected1] = useState(0); - const [iceNotDetected2, setIceNotDetected2] = useState(0); - const [packOffBleedIsAvailable1, setPackOffBleedIsAvailable1] = useState(0); - const [packOffBleedIsAvailable2, setPackOffBleedIsAvailable2] = useState(0); - const [packOffNotFailure1, setPackOffNotFailure1] = useState(0); - const [packOffNotFailure2, setPackOffNotFailure2] = useState(0); - const [cabAltSetResetState1, setCabAltSetResetState1] = useState(false); - const [cabAltSetResetState2, setCabAltSetResetState2] = useState(false); - - useUpdate((deltaTime) => { - showTakeoffInhibit = toInhibitTimer.write([3, 4, 5].includes(flightPhase) && !flightPhaseInhibitOverride, deltaTime); - showLandingInhibit = ldgInhibitTimer.write([7, 8].includes(flightPhase) && !flightPhaseInhibitOverride, deltaTime); - const agent1Eng1DischargeNode = agent1Eng1DischargeTimer.write(fireButton1 === 1, deltaTime); - if (agent1Eng1Discharge !== agent1Eng1DischargeNode) { - setAgent1Eng1Discharge(agent1Eng1DischargeNode); - } - const agent2Eng1DischargeNode = agent2Eng1DischargeTimer.write(fireButton1 === 1 && eng1Agent1PB === 1 && !aircraftOnGround, deltaTime); - if (agent2Eng1Discharge !== agent2Eng1DischargeNode) { - setAgent2Eng1Discharge(agent2Eng1DischargeNode); - } - const agent1Eng2DischargeNode = agent1Eng2DischargeTimer.write(fireButton2 === 1 && !eng1Agent1PB, deltaTime); - if (agent1Eng2Discharge !== agent1Eng2DischargeNode) { - setAgent1Eng2Discharge(agent1Eng2DischargeNode); - } - const agent2Eng2DischargeNode = agent2Eng2DischargeTimer.write(fireButton2 === 1 && eng1Agent1PB === 1, deltaTime); - if (agent2Eng2Discharge !== agent2Eng2DischargeNode) { - setAgent2Eng2Discharge(agent2Eng2DischargeNode); - } - const agentAPUDischargeNode = agentAPUDischargeTimer.write(fireButton2 === 1 && eng1Agent1PB === 1, deltaTime); - if (agentAPUDischarge !== agentAPUDischargeNode) { - setAgentAPUDischarge(agentAPUDischargeNode); - } - const iceDetected1Node = iceDetectedTimer1.write(icePercentage >= 0.1 && tat < 10 && !aircraftOnGround, deltaTime); - if (iceDetected1 !== iceDetected1Node) { - setIceDetected1(iceDetected1Node); - } - const iceDetected2Node = iceDetectedTimer2.write(iceDetected1Node && !(eng1AntiIce && eng2AntiIce), deltaTime); - if (iceDetected2 !== iceDetected2Node) { - setIceDetected2(iceDetected2Node); - } - - const iceSevereDetectedNode = iceSevereDetectedTimer.write(icePercentage >= 0.5 && tat < 10 && !aircraftOnGround, deltaTime); - if (iceSevereDetected !== iceSevereDetectedNode) { - setIceSevereDetected(iceSevereDetectedNode); - } - - const iceNotDetected1Node = iceNotDetTimer1.write(eng1AntiIce === 1 || eng2AntiIce === 1 || wingAntiIce === 1, deltaTime); - if (iceNotDetected1 !== iceNotDetected1Node) { - setIceNotDetected1(iceNotDetected1Node); - } - - const iceNotDetected2Node = iceNotDetTimer2.write(iceNotDetected1 && !(icePercentage >= 0.1 || (tat < 10 && inCloud === 1)), deltaTime); - if (iceNotDetected2 !== iceNotDetected2Node) { - setIceNotDetected2(iceNotDetected2Node); - } - - const packOffBleedIsAvailable1Node = packOffBleedAvailable1.write((eng1Bleed === 1 && !eng1BleedPbFault) || crossfeed === 1, deltaTime); - if (packOffBleedIsAvailable1 !== packOffBleedIsAvailable1Node) { - setPackOffBleedIsAvailable1(packOffBleedIsAvailable1Node); - } - - const packOffBleedIsAvailable2Node = packOffBleedAvailable2.write((eng2Bleed === 1 && !eng2BleedPbFault) || crossfeed === 1, deltaTime); - if (packOffBleedIsAvailable2 !== packOffBleedIsAvailable2Node) { - setPackOffBleedIsAvailable2(packOffBleedIsAvailable2Node); - } - - const packOffNotFailed1Node = packOffNotFailed1.write(!pack1On && !pack1Fault && packOffBleedAvailable1.read() && flightPhase === 6, deltaTime); - if (packOffNotFailure1 !== packOffNotFailed1Node) { - setPackOffNotFailure1(packOffNotFailed1Node); - } - const packOffNotFailed2Node = packOffNotFailed2.write(!pack2On && !pack2Fault && packOffBleedAvailable2.read() && flightPhase === 6, deltaTime); - if (packOffNotFailure2 !== packOffNotFailed2Node) { - setPackOffNotFailure2(packOffNotFailed2Node); - } - const cabAltSetReset1Node = cabAltSetReset1.write(adirsAlt.value > 10000 && excessPressure === 1, excessPressure === 1 && [3, 10].includes(flightPhase)); - if (cabAltSetResetState1 !== cabAltSetReset1Node) { - setCabAltSetResetState1(cabAltSetReset1Node); - } - - const cabAltSetReset2Node = cabAltSetReset2.write(adirsAlt.value > 16000 && excessPressure === 1, excessPressure === 1 && [3, 10].includes(flightPhase)); - if (cabAltSetResetState2 !== cabAltSetReset2Node) { - setCabAltSetResetState2(cabAltSetReset2Node); - } - - const elac1HydraulicResult = elac1HydConfirmNode.write(!greenSysPressurised && !blueSysPressurised, deltaTime); - if (elac1HydConfirmNodeOutput !== elac1HydraulicResult) { - setElac1HydConfirmNodeOutput(elac1HydraulicResult); - } - - const elac1FaultResult = elac1FaultConfirmNode.write(elac1FaultCondition, deltaTime); - if (elac1FaultConfirmNodeOutput !== elac1FaultResult) { - setElac1FaultConfirmNodeOutput(elac1FaultResult); - } - - const elac2HydraulicResult = elac2HydConfirmNode.write((!greenSysPressurised || !yellowSysPressurised) && !blueSysPressurised, deltaTime); - if (elac2HydConfirmNodeOutput !== elac2HydraulicResult) { - setElac2HydConfirmNodeOutput(elac2HydraulicResult); - } - - const elac2FaultResult = elac2FaultConfirmNode.write(elac2FaultCondition, deltaTime); - if (elac2FaultConfirmNodeOutput !== elac2FaultResult) { - setElac2FaultConfirmNodeOutput(elac2FaultResult); - } - - const altn1Result = altn1LawConfirmNode.write(altn1Condition, deltaTime); - if (altn1LawConfirmNodeOutput !== altn1Result) { - setAltn1LawConfirmNodeOutput(altn1Result); - } - - const altn2Result = altn2LawConfirmNode.write(altn2Condition, deltaTime); - if (altn2LawConfirmNodeOutput !== altn2Result) { - setAltn2LawConfirmNodeOutput(altn2Result); - } - }); - - /* FAILURES, MEMOS AND SPECIAL LINES */ - - interface EWDItem { - flightPhaseInhib: number[], - simVarIsActive: boolean, - whichCodeToReturn: any[], - codesToReturn: string[], - memoInhibit: boolean, - failure: number, - sysPage: number, - side: string - } - - interface EWDMessageDict { - [key: string] : EWDItem - } - - const EWDMessageFailures: EWDMessageDict = { - 3400210: { // OVERSPEED FLAPS FULL - flightPhaseInhib: [2, 3, 4, 8, 9, 10], - simVarIsActive: flapsIndex === 5 && computedAirSpeedToNearest2 > 181, - whichCodeToReturn: [0, 1], - codesToReturn: ['340021001', '340021002'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 3400220: { // OVERSPEED FLAPS 3 - flightPhaseInhib: [2, 3, 4, 8, 9, 10], - simVarIsActive: flapsIndex === 4 && computedAirSpeedToNearest2 > 189, - whichCodeToReturn: [0, 1], - codesToReturn: ['340022001', '340022002'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 3400230: { // OVERSPEED FLAPS 2 - flightPhaseInhib: [2, 3, 4, 8, 9, 10], - simVarIsActive: flapsIndex === 3 && computedAirSpeedToNearest2 > 203, - whichCodeToReturn: [0, 1], - codesToReturn: ['340023001', '340023002'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 3400235: { // OVERSPEED FLAPS 1+F - flightPhaseInhib: [2, 3, 4, 8, 9, 10], - simVarIsActive: flapsIndex === 2 && computedAirSpeedToNearest2 > 219, - whichCodeToReturn: [0, 1], - codesToReturn: ['340023501', '340023502'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 3400240: { // OVERSPEED FLAPS 1 - flightPhaseInhib: [2, 3, 4, 8, 9, 10], - simVarIsActive: flapsIndex === 1 && computedAirSpeedToNearest2 > 233, - whichCodeToReturn: [0, 1], - codesToReturn: ['340024001', '340024002'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 7700027: { // DUAL ENGINE FAILURE - flightPhaseInhib: [], - simVarIsActive: engDualFault === true, - whichCodeToReturn: [ - 0, - !emergencyGeneratorOn ? 1 : null, - 5, - !(apuMasterSwitch === 1 || apuAvail === 1) && radioAlt < 2500 ? 6 : null, - N1AboveIdle === 1 || N2AboveIdle === 1 ? 7 : null, - fac1Failed === 1 ? 8 : null, - 9, 10, 11, - ], - codesToReturn: ['770002701', '770002702', '770002703', '770002704', '770002705', '770002706', '770002707', '770002708', '770002709', '770002710', '770002711', '770002712'], - memoInhibit: false, - failure: 3, - sysPage: 0, - side: 'LEFT', - }, - 2600010: { // ENG 1 FIRE - flightPhaseInhib: [], - simVarIsActive: !!(eng1FireTest === 1 || fireButton1 === 1), - whichCodeToReturn: [ - 0, - throttle1Position !== 0 && !aircraftOnGround ? 1 : null, - (throttle1Position !== 0 || throttle2Position !== 0) && aircraftOnGround ? 2 : null, - !parkBrake && aircraftOnGround ? 3 : null, - !parkBrake && aircraftOnGround ? 4 : null, - aircraftOnGround ? 5 : null, - aircraftOnGround ? 6 : null, - !engine1ValueSwitch ? null : 7, - !fireButton1 ? 8 : null, - !aircraftOnGround && agent1Eng1Discharge === 1 && !eng1Agent1PB ? 9 : null, - agent1Eng1Discharge === 2 && !aircraftOnGround && !eng1Agent1PB ? 10 : null, - !eng1Agent1PB && aircraftOnGround ? 11 : null, - !eng1Agent2PB && aircraftOnGround ? 12 : null, - aircraftOnGround ? 13 : null, - !aircraftOnGround ? 14 : null, - agent2Eng1Discharge === 1 && !eng1Agent2PB ? 15 : null, - (agent2Eng1Discharge === 1 && !eng1Agent2PB) || (agent2Eng1Discharge === 2 && !eng1Agent2PB) ? 16 : null, - ], - codesToReturn: ['260001001', '260001002', '260001003', '260001004', '260001005', - '260001006', '260001007', '260001008', '260001009', '260001010', '260001011', - '260001012', '260001013', '260001014', '260001015', '260001016', '260001017'], - memoInhibit: false, - failure: 3, - sysPage: 0, - side: 'LEFT', - }, - 2600020: { // ENG 2 FIRE - flightPhaseInhib: [], - simVarIsActive: !!(eng2FireTest === 1 || fireButton2 === 1), - whichCodeToReturn: [ - 0, - throttle2Position !== 0 && !aircraftOnGround ? 1 : null, - (throttle1Position !== 0 || throttle2Position !== 0) && aircraftOnGround ? 2 : null, - !parkBrake && aircraftOnGround ? 3 : null, - !parkBrake && aircraftOnGround ? 4 : null, - aircraftOnGround ? 5 : null, - aircraftOnGround ? 6 : null, - !engine2ValueSwitch ? null : 7, - !fireButton2 ? 8 : null, - !aircraftOnGround && agent1Eng2Discharge === 1 && !eng2Agent1PB ? 9 : null, - agent1Eng2Discharge === 2 && !aircraftOnGround && !eng2Agent1PB ? 10 : null, - !eng2Agent1PB && aircraftOnGround ? 11 : null, - !eng2Agent2PB && aircraftOnGround ? 12 : null, - aircraftOnGround ? 13 : null, - !aircraftOnGround ? 14 : null, - agent2Eng2Discharge === 1 && !eng2Agent2PB ? 15 : null, - (agent2Eng2Discharge === 1 && !eng2Agent2PB) || (agent2Eng2Discharge === 2 && !eng2Agent2PB) ? 16 : null, - ], - codesToReturn: ['260002001', '260002002', '260002003', '260002004', '260002005', - '260002006', '260002007', '260002008', '260002009', '260002010', '260002011', - '260002012', '260002013', '260002014', '260002015', '260002016'], - memoInhibit: false, - failure: 3, - sysPage: 0, - side: 'LEFT', - }, - 2600030: { // APU FIRE - flightPhaseInhib: [], - simVarIsActive: !!(apuFireTest === 1 || fireButtonAPU === 1), - whichCodeToReturn: [ - 0, - !fireButtonAPU ? 1 : null, - agentAPUDischarge === 1 && !apuAgentPB ? 2 : null, - agentAPUDischarge === 2 && !apuAgentPB ? 3 : null, - apuMasterSwitch === 1 ? 4 : null, - ], - codesToReturn: ['260003001', '260003002', '260003003', '260003004', '260003005'], - memoInhibit: false, - failure: 3, - sysPage: 6, - side: 'LEFT', - }, - 2700085: { // SLATS NOT IN TO CONFIG - flightPhaseInhib: [5, 6, 7, 8], - simVarIsActive: ( - flapsMcduEntered === 1 - && flapsHandle !== flapsMcdu - && [1, 2, 9].includes(flightPhase) - && toconfigFailed - ) - || ( - [3, 4, 5].includes(flightPhase) && (slatsInfD || slatsSupG) - ), - whichCodeToReturn: [0, 1], - codesToReturn: ['270008501', '270008502'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 2700090: { // FLAPS NOT IN TO CONFIG - flightPhaseInhib: [5, 6, 7, 8], - simVarIsActive: ( - flapsMcduEntered === 1 - && flapsHandle !== flapsMcdu - && [1, 2, 9].includes(flightPhase) - && toconfigFailed - ) - || ( - [3, 4, 5].includes(flightPhase) && (flapsInfA || flapsSupF) - ), - whichCodeToReturn: [0, 1], - codesToReturn: ['270009001', '270009002'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 2700110: { // ELAC 1 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: elac1FaultConfirmNodeOutput, - whichCodeToReturn: [ - 0, - elac1FaultLine123Display ? 1 : null, - elac1FaultLine123Display ? 2 : null, - elac1FaultLine123Display ? 3 : null, - elac1FaultLine45Display ? 4 : null, - elac1FaultLine45Display ? 5 : null, - ], - codesToReturn: ['270011001', '270011002', '270011003', '270011004', '270011005', '270011006'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700120: { // ELAC 2 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: elac2FaultConfirmNodeOutput, - whichCodeToReturn: [ - 0, - elac2FaultLine123Display ? 1 : null, - elac2FaultLine123Display ? 2 : null, - elac2FaultLine123Display ? 3 : null, - elac2FaultLine45Display ? 4 : null, - elac2FaultLine45Display ? 5 : null, - ], - codesToReturn: ['270012001', '270012002', '270012003', '270012004', '270012005', '270012006'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700210: { // SEC 1 FAULT - flightPhaseInhib: [3, 4, 5], - simVarIsActive: sec1FaultCondition, - whichCodeToReturn: [ - 0, - sec1FaultLine123Display ? 1 : null, - sec1FaultLine123Display ? 2 : null, - sec1FaultLine123Display ? 3 : null, - sec1FaultLine45Display ? 4 : null, - ], - codesToReturn: ['270021001', '270021002', '270021003', '270021004', '270021005'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700220: { // SEC 2 FAULT - flightPhaseInhib: [3, 4, 5], - simVarIsActive: sec2FaultCondition, - whichCodeToReturn: [ - 0, - sec2FaultLine123Display ? 1 : null, - sec2FaultLine123Display ? 2 : null, - sec2FaultLine123Display ? 3 : null, - ], - codesToReturn: ['270022001', '270022002', '270022003', '270022004'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700230: { // SEC 3 FAULT - flightPhaseInhib: [3, 4, 5], - simVarIsActive: sec3FaultCondition, - whichCodeToReturn: [ - 0, - sec3FaultLine123Display ? 1 : null, - sec3FaultLine123Display ? 2 : null, - sec3FaultLine123Display ? 3 : null, - ], - codesToReturn: ['270023001', '270023002', '270023003', '270023004'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700360: { // FCDC 1+2 FAULT - flightPhaseInhib: [3, 4, 5, 7], - simVarIsActive: fcdc12FaultCondition, - whichCodeToReturn: [0, 1], - codesToReturn: ['270036001', '270036002'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700365: { // DIRECT LAW - flightPhaseInhib: [4, 5, 7, 8], - simVarIsActive: directLawCondition, - whichCodeToReturn: [0, 1, 2, 3, 4, null, 6, 7], - codesToReturn: ['270036501', '270036502', '270036503', '270036504', '270036505', '270036506', '270036507', '270036508'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700375: { // ALTN 2 - flightPhaseInhib: [4, 5, 7, 8], - simVarIsActive: altn2LawConfirmNodeOutput, - whichCodeToReturn: [0, 1, null, 3, 4, null, 6], - codesToReturn: ['270037501', '270037502', '270037503', '270037504', '270037505', '270037506', '270037507'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700390: { // ALTN 1 - flightPhaseInhib: [4, 5, 7, 8], - simVarIsActive: altn1LawConfirmNodeOutput, - whichCodeToReturn: [0, 1, null, 3, 4, null, 6], - codesToReturn: ['270039001', '270039002', '270039003', '270039004', '270039005', '270039006', '270039007'], - memoInhibit: false, - failure: 2, - sysPage: 10, - side: 'LEFT', - }, - 2700400: { // L+R ELEV FAULT - flightPhaseInhib: [], - simVarIsActive: lrElevFaultCondition, - whichCodeToReturn: [0, 1, 2, null, null, 5], - codesToReturn: ['270040001', '270040002', '270040003', '270040004', '270040005', '270040006'], - memoInhibit: false, - failure: 3, - sysPage: 10, - side: 'LEFT', - }, - 2700555: { // FCDC 1 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: fcdc1FaultCondition, - whichCodeToReturn: [0], - codesToReturn: ['270055501'], - memoInhibit: false, - failure: 1, - sysPage: -1, - side: 'LEFT', - }, - 2700557: { // FCDC 2 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: fcdc2FaultCondition, - whichCodeToReturn: [0], - codesToReturn: ['270055701'], - memoInhibit: false, - failure: 1, - sysPage: -1, - side: 'LEFT', - }, - 3200050: { // PK BRK ON - flightPhaseInhib: [1, 4, 5, 6, 7, 8, 9, 10], - simVarIsActive: !!(flightPhase === 3 && parkBrake === 1), - // TODO no separate slats indication - whichCodeToReturn: [0], - codesToReturn: ['320005001'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 2131221: { // EXCESS CAB ALT - flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], - simVarIsActive: !!(!aircraftOnGround && excessPressure === 1), - // TODO no separate slats indication - whichCodeToReturn: [ - 0, - cabAltSetResetState1 ? 1 : null, - cabAltSetResetState2 && seatBelt !== 1 ? 2 : null, - cabAltSetResetState2 ? 3 : null, - cabAltSetResetState1 ? 4 : null, - cabAltSetResetState2 && (throttle1Position !== 0 || throttle2Position !== 0) && autoThrustStatus !== 2 ? 5 : null, - cabAltSetResetState2 && !speedBrakeCommand ? 6 : null, - cabAltSetResetState2 ? 7 : null, - cabAltSetResetState2 && engSelectorPosition !== 2 ? 8 : null, - cabAltSetResetState2 ? 9 : null, - cabAltSetResetState1 && !cabAltSetResetState2 ? 10 : null, - cabAltSetResetState2 ? 11 : null, - cabAltSetResetState2 ? 12 : null, - cabAltSetResetState2 ? 13 : null, - 14, - 15, - 16, - ], - codesToReturn: ['213122101', '213122102', '213122103', '213122104', '213122105', - '213122106', '213122107', '213122108', '213122109', '213122110', '213122111', '213122112', '213122113', '213122114', '213122115', '213122116'], - memoInhibit: false, - failure: 3, - sysPage: 2, - side: 'LEFT', - }, - 2600150: { // SMOKE FWD CARGO SMOKE - flightPhaseInhib: [4, 5, 7, 8], - simVarIsActive: !!([1, 2, 3, 6, 9, 10].includes(flightPhase) && cargoFireTest === 1), - // TODO no separate slats indication - whichCodeToReturn: [ - 0, - cabinRecircBtnOn === 1 ? 2 : null, - [1, 10].includes(flightPhase) && !cargoFireAgentDisch ? 3 : null, - !cargoFireAgentDisch ? 4 : null, - !aircraftOnGround ? 5 : null, - !aircraftOnGround ? 6 : null, - aircraftOnGround ? 7 : null, - aircraftOnGround ? 8 : null, - ], - codesToReturn: ['260015001', '260015002', '260015003', '260015004', '260015005', '260015006', '260015007', '260015008', '260015009'], - memoInhibit: false, - failure: 3, - sysPage: -1, - side: 'LEFT', - }, - 7700647: { // THR LEVERS NOT SET (on ground) - flightPhaseInhib: [1, 4, 5, 6, 7, 8, 10], - simVarIsActive: [2, 3, 4, 8, 9].includes(flightPhase) && ( - !!((throttle1Position !== 35 && thrustLeverNotSet) || (throttle2Position !== 35 && thrustLeverNotSet)) - ), - whichCodeToReturn: [ - 0, - autothrustLeverWarningFlex === 1 ? 1 : null, - autothrustLeverWarningTOGA === 1 ? 2 : null, - ], - codesToReturn: ['770064701', '770064702', '770064703'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 2161207: { // PACK 1 ABNORMALLY OFF - flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], - simVarIsActive: packOffNotFailed1.read(), - whichCodeToReturn: [0], - codesToReturn: ['216120701'], - memoInhibit: false, - failure: 2, - sysPage: 1, - side: 'LEFT', - }, - 2161208: { // PACK 2 ABNORMALLY OFF - flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], - simVarIsActive: packOffNotFailed2.read(), - whichCodeToReturn: [0], - codesToReturn: ['216120801'], - memoInhibit: false, - failure: 2, - sysPage: 1, - side: 'LEFT', - }, - 3200060: { // NW ANTI SKID INACTIVE - flightPhaseInhib: [4, 5], - simVarIsActive: antiskidActive === 0, - whichCodeToReturn: [0, 1], - codesToReturn: ['320006001', '320006002'], - memoInhibit: false, - failure: 2, - sysPage: 9, - side: 'LEFT', - }, - 3200180: { // LGCIU 1 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: lgciu1Fault && !(lgciu1Fault && lgciu2Fault) && dcESSBusPowered, - whichCodeToReturn: [0, !gpwsSysOff ? 1 : null], - codesToReturn: ['320018001', '320018002'], - memoInhibit: false, - failure: 1, - sysPage: -1, - side: 'LEFT', - }, - 3200190: { // LGCIU 2 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: lgciu2Fault && !(lgciu1Fault && lgciu2Fault) && dc2BusPowered, - whichCodeToReturn: [0], - codesToReturn: ['320019001'], - memoInhibit: false, - failure: 1, - sysPage: -1, - side: 'LEFT', - }, - 3200195: { // LGCIU 1+2 FAULT - flightPhaseInhib: [4, 5, 7, 8], - simVarIsActive: lgciu1Fault && lgciu2Fault && dc2BusPowered && dcESSBusPowered, - whichCodeToReturn: [0, 1, !gpwsSysOff ? 2 : null], - codesToReturn: ['320019501', '320019502', '320019503'], - memoInhibit: false, - failure: 2, - sysPage: 9, - side: 'LEFT', - }, - 3400140: { // RA 1 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: height1Failed && ac1BusPowered, - whichCodeToReturn: [0], - codesToReturn: ['340014001'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 3400150: { // RA 2 FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: height2Failed && ac2BusPowered, - whichCodeToReturn: [0], - codesToReturn: ['340015001'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 3400500: { // TCAS FAULT - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: !!(![1, 10].includes(flightPhase) && tcasFault === 1), - whichCodeToReturn: [0], - codesToReturn: ['340050001'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 3400507: { // NAV TCAS STBY (in flight) - flightPhaseInhib: [1, 2, 3, 4, 5, 7, 8, 9, 10], - simVarIsActive: !!(flightPhase === 6 && tcasSensitivity === 1), - whichCodeToReturn: [0], - codesToReturn: ['340050701'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 3200010: { // L/G-BRAKES OVHT - flightPhaseInhib: [4, 8, 9, 10], - simVarIsActive: (toconfig === 1 || flightPhase === 3) - && brakesHot === 1, - whichCodeToReturn: [ - 0, - !aircraftOnGround ? 1 : null, - [1, 10].includes(flightPhase) ? 2 : null, - !aircraftOnGround ? 3 : null, - [1, 2].includes(flightPhase) && !brakeFan ? 4 : null, - aircraftOnGround ? 5 : null, - !aircraftOnGround ? 6 : null, - !aircraftOnGround ? 7 : null, - !aircraftOnGround ? 8 : null, - ], - codesToReturn: ['320001001', '320001002', '320001003', '320001004', '320001005', '320001006', '320001007', '320001008', '320001009'], - memoInhibit: false, - failure: 2, - sysPage: 9, - side: 'LEFT', - }, - 3081186: { // SEVERE ICE DETECTED - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: iceSevereDetectedTimer.read(), - whichCodeToReturn: [ - 0, - !wingAntiIce ? 1 : null, - engSelectorPosition !== 2 ? 2 : null, - ], - codesToReturn: ['308128001', '308128002', '308128003'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 3081280: { // ICE DETECTED - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: iceDetectedTimer2.read(), - whichCodeToReturn: [ - 0, - !eng1AntiIce ? 1 : null, - !eng2AntiIce ? 2 : null, - ], - codesToReturn: ['308128001', '308128002', '308128003'], - memoInhibit: false, - failure: 2, - sysPage: -1, - side: 'LEFT', - }, - 2900126: // *HYD - Blue reservoir overheat - { - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: blueRvrOvht, - whichCodeToReturn: [ - 0, - blueElecPumpPBAuto ? 1 : null, - ], - codesToReturn: ['290012601', '290012602'], - memoInhibit: false, - failure: 2, - sysPage: 4, - side: 'LEFT', - }, - 2900127: // *HYD - Yellow reservoir overheat - { - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: yellowRvrOvht, - whichCodeToReturn: [ - 0, - ptuIsAuto ? 1 : null, - eng2pumpPBisAuto ? 2 : null, - !yepumpPBisAuto ? 3 : null, - ], - codesToReturn: ['290012701', '290012702', '290012703', '290012704'], - memoInhibit: false, - failure: 2, - sysPage: 4, - side: 'LEFT', - }, - 2900128: // *HYD - Green reservoir overheat - { - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: greenRvrOvht, - whichCodeToReturn: [ - 0, - ptuIsAuto ? 1 : null, - eng1pumpPBisAuto ? 2 : null, - ], - codesToReturn: ['290012801', '290012802', '290012803'], - memoInhibit: false, - failure: 2, - sysPage: 4, - side: 'LEFT', - }, - 2900310: // *HYD - Blue - { - flightPhaseInhib: [4, 5], - simVarIsActive: !!(!(blueRvrLow === 1 || !blueElecPumpPBAuto) - && (!dcESSBusPowered || !ac1BusPowered) - && blueLP === 1 - && ![1, 10].includes(flightPhase) - && !emergencyGeneratorOn), - whichCodeToReturn: [0], - codesToReturn: ['290031001'], - memoInhibit: false, - failure: 2, - sysPage: 4, - side: 'RIGHT', - }, - 2900312: // *HYD - Green Engine 1 // - { - flightPhaseInhib: [], - simVarIsActive: ![1, 10, 2, 9].includes(flightPhase) - // && ENG 1 OUT - not implemented - && greenLP === 1 - && !greenHydEng1PBAuto - && !emergencyGeneratorOn, - whichCodeToReturn: [0], - codesToReturn: ['290031201'], - memoInhibit: false, - failure: 2, - sysPage: 4, - side: 'RIGHT', - }, - }; - - const EWDMessageMemos: EWDMessageDict = { - '0000010': { // T.O MEMO - flightPhaseInhib: [1, 3, 6, 10], - simVarIsActive: !!tomemo, - whichCodeToReturn: [ - autoBrake === 3 ? 1 : 0, - noSmoking === 1 && seatBelt === 1 ? 3 : 2, - cabinReady ? 5 : 4, - spoilersArmed ? 7 : 6, - flapsHandle >= 1 && flapsHandle <= 3 ? 9 : 8, - toconfig ? 11 : 10, - ], - codesToReturn: ['000001001', '000001002', '000001003', '000001004', '000001005', '000001006', '000001007', '000001008', '000001009', '000001010', '000001011', '000001012'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000020': { // LANDING MEMO - flightPhaseInhib: [1, 2, 3, 4, 5, 9, 10], - simVarIsActive: !!ldgmemo, - whichCodeToReturn: [ - landingGearLeverDown === 1 ? 1 : 0, - noSmokingSwitchPosition !== 2 && seatBelt === 1 ? 3 : 2, - cabinReady ? 5 : 4, - spoilersArmed ? 7 : 6, - !gpwsFlaps3 && flapsHandle !== 4 ? 8 : null, - !gpwsFlaps3 && flapsHandle === 4 ? 9 : null, - gpwsFlaps3 === 1 && flapsHandle !== 3 ? 10 : null, - gpwsFlaps3 === 1 && flapsHandle === 3 ? 11 : null, - ], - codesToReturn: ['000002001', '000002002', '000002003', '000002004', '000002005', '000002006', '000002007', '000002008', '000002009', '000002010', '000002011', '000002012'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000050': { // REFUELING - flightPhaseInhib: [], - simVarIsActive: !!(fuel === 100 || usrStartRefueling), - whichCodeToReturn: [0], - codesToReturn: ['000005001'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000030': { // IR IN ALIGN - flightPhaseInhib: [3, 4, 5, 6, 7, 8, 9, 10], - simVarIsActive: !!(adirsRemainingAlignTime >= 240 && [adiru1State, adiru2State, adiru3State].every((a) => a === 1)), - whichCodeToReturn: [ - adirsMessage1(adirsRemainingAlignTime, (engine1State > 0 && engine1State < 4) || (engine2State > 0 && engine2State < 4)), - ], - codesToReturn: ['000003001', '000003002', '000003003', '000003004', '000003005', '000003006', '000003007', '000003008'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000031': { // IR IN ALIGN - flightPhaseInhib: [3, 4, 5, 6, 7, 8, 9, 10], - simVarIsActive: !!(adirsRemainingAlignTime > 0 && adirsRemainingAlignTime < 240 && [adiru1State, adiru2State, adiru3State].every((a) => a === 1)), - whichCodeToReturn: [ - adirsMessage2(adirsRemainingAlignTime, (engine1State > 0 && engine1State < 4) || (engine2State > 0 && engine2State < 4)), - ], - codesToReturn: ['000003101', '000003102', '000003103', '000003104', '000003105', '000003106', '000003107', '000003108'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000055': // SPOILERS ARMED - { - flightPhaseInhib: [], - simVarIsActive: !!spoilersArmed, - whichCodeToReturn: [0], - codesToReturn: ['000005501'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000080': // SEAT BELTS - { - flightPhaseInhib: [], - simVarIsActive: !!seatBelt, - whichCodeToReturn: [0], - codesToReturn: ['000008001'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000090': // NO SMOKING - { - flightPhaseInhib: [], - simVarIsActive: !!(noSmoking === 1 && !configPortableDevices), - whichCodeToReturn: [0], - codesToReturn: ['000009001'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000095': // PORTABLE DEVICES - { - flightPhaseInhib: [], - simVarIsActive: !!(noSmoking === 1 && configPortableDevices), - whichCodeToReturn: [0], - codesToReturn: ['000009501'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000100': // STROBE LIGHT OFF - { - flightPhaseInhib: [], - simVarIsActive: !!(!aircraftOnGround && strobeLightsOn === 2), - whichCodeToReturn: [0], - codesToReturn: ['000010001'], - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000105': // OUTR TK FUEL XFRD - { - flightPhaseInhib: [], // Plus check that outer tanks not empty - simVarIsActive: !!(leftOuterInnerValve || rightOuterInnerValve), - whichCodeToReturn: [0], - codesToReturn: ['000010501'], // config memo - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000305': // GPWS FLAP MODE OFF - { - flightPhaseInhib: [], - simVarIsActive: !!gpwsFlapMode, - whichCodeToReturn: [0], - codesToReturn: ['000030501'], // Not inhibited - memoInhibit: !!(tomemo === 1 || ldgmemo === 1), - failure: 0, - sysPage: -1, - side: 'LEFT', - }, - '0000140': // T.O. INHIBIT - { - flightPhaseInhib: [], - simVarIsActive: showTakeoffInhibit, - whichCodeToReturn: [0], - codesToReturn: ['000014001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000150': // LDG INHIBIT - { - flightPhaseInhib: [], - simVarIsActive: showLandingInhibit, - whichCodeToReturn: [0], - codesToReturn: ['000015001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000350': // LAND ASAP RED - { - flightPhaseInhib: [], - simVarIsActive: !!landASAPRed, - whichCodeToReturn: [0], - codesToReturn: ['000035001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000360': // LAND ASAP AMBER - { - flightPhaseInhib: [], - simVarIsActive: !!(!landASAPRed && !aircraftOnGround && ( - engine1State === 0 - || engine2State === 0 - )), - whichCodeToReturn: [0], - codesToReturn: ['000036001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000060': // SPEED BRK - { - flightPhaseInhib: [], - simVarIsActive: speedBrakeCommand && ![1, 8, 9, 10].includes(flightPhase), - whichCodeToReturn: [![6, 7].includes(flightPhase) ? 1 : 0], - codesToReturn: ['000006001', '000006002'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000200': // PARK BRK - { - flightPhaseInhib: [], - simVarIsActive: !!([1, 2, 9, 10].includes(flightPhase) && parkBrake === 1), - whichCodeToReturn: [0], - codesToReturn: ['000020001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000040': // NW STRG DISC - { - flightPhaseInhib: [], - simVarIsActive: nwSteeringDisc === 1, - whichCodeToReturn: [engine1State > 0 || engine2State > 1 ? 1 : 0], - codesToReturn: ['000004001', '000004002'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000160': // PTU ON - { - flightPhaseInhib: [], - simVarIsActive: hydPTU === 1, - whichCodeToReturn: [0], - codesToReturn: ['000016001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000210': // RAT OUT - { - flightPhaseInhib: [], - simVarIsActive: ratDeployed > 0, - whichCodeToReturn: [[1, 2].includes(flightPhase) ? 1 : 0], - codesToReturn: ['000021001', '000021002'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000070': // IGNITION - { - flightPhaseInhib: [], - simVarIsActive: engSelectorPosition === 2, - whichCodeToReturn: [0], - codesToReturn: ['000007001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000540': // PRED W/S OFF - { - flightPhaseInhib: [], - simVarIsActive: !!(predWSOn === 0 && ![1, 10].includes(flightPhase)), - whichCodeToReturn: [[3, 4, 5, 7, 8, 9].includes(flightPhase) || toconfig === 1 ? 1 : 0], - codesToReturn: ['000054001', '000054002'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000545': // TERR OFF - { - flightPhaseInhib: [1, 10], - simVarIsActive: !!(gpwsTerrOff === 1 && ![1, 10].includes(flightPhase)), - whichCodeToReturn: [[3, 4, 5, 7, 8, 9].includes(flightPhase) || toconfig === 1 ? 1 : 0], - codesToReturn: ['000054501', '000054502'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000320': // TCAS STBY - { - flightPhaseInhib: [], - simVarIsActive: !!(tcasSensitivity === 1 && flightPhase !== 6), - whichCodeToReturn: [0], - codesToReturn: ['000032001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000325': // TCAS STBY in flight - { - flightPhaseInhib: [], - simVarIsActive: !!(tcasSensitivity === 1 && flightPhase === 6), - whichCodeToReturn: [0], - codesToReturn: ['000032501'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000552': // COMPANY MESSAGE - { - flightPhaseInhib: [], - simVarIsActive: [1, 2, 6, 9, 10].includes(flightPhase) && compMesgCount > 0, - whichCodeToReturn: [0], - codesToReturn: ['000055201'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000260': // ENG ANTI ICE - { - flightPhaseInhib: [3, 4, 5, 7, 8], - simVarIsActive: !!(eng1AntiIce === 1 || eng2AntiIce === 1), - whichCodeToReturn: [0], - codesToReturn: ['000026001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000270': // WING ANTI ICE - { - flightPhaseInhib: [], - simVarIsActive: wingAntiIce === 1, - whichCodeToReturn: [0], - codesToReturn: ['000027001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000275': // ICE NOT DETECTED - { - flightPhaseInhib: [1, 2, 3, 4, 8, 9, 10], - simVarIsActive: iceNotDetTimer2.read() && !aircraftOnGround, - whichCodeToReturn: [0], - codesToReturn: ['000027501'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000170': // APU AVAIL - { - flightPhaseInhib: [], - simVarIsActive: !!(apuAvail === 1 && !apuBleedValveOpen), - whichCodeToReturn: [0], - codesToReturn: ['000017001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000180': // APU BLEED - { - flightPhaseInhib: [], - simVarIsActive: !!(apuAvail === 1 && apuBleedValveOpen === 1), - whichCodeToReturn: [0], - codesToReturn: ['000018001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000190': // LDG LT - { - flightPhaseInhib: [], - simVarIsActive: !!(!landingLight2Retracted || !landingLight3Retracted), - whichCodeToReturn: [0], - codesToReturn: ['000019001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000220': // BRAKE FAN - { - flightPhaseInhib: [], - simVarIsActive: brakeFan === 1, - whichCodeToReturn: [0], - codesToReturn: ['000022001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000290': // SWITCHING PNL - { - flightPhaseInhib: [], - simVarIsActive: !!(ndXfrKnob !== 1 || dmcSwitchingKnob !== 1), - whichCodeToReturn: [0], - codesToReturn: ['000029001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000300': // GPWS FLAPS 3 - { - flightPhaseInhib: [], - simVarIsActive: gpwsFlaps3 === 1, - whichCodeToReturn: [0], - codesToReturn: ['000030001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000022': // AUTOBRAKE - { - flightPhaseInhib: [], - simVarIsActive: [7, 8].includes(flightPhase), - whichCodeToReturn: [parseInt(autoBrakesArmedMode) - 1], - codesToReturn: ['000002201', '000002202', '000002203', '000002204'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000230': // MAN LANDING ELEVATION - { - flightPhaseInhib: [], - simVarIsActive: manLandingElevation > 0, - whichCodeToReturn: [0], - codesToReturn: ['000023001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000250': // FUEL X FEED - { - flightPhaseInhib: [], - simVarIsActive: fuelXFeedPBOn === 1, - whichCodeToReturn: [[3, 4, 5].includes(flightPhase) ? 1 : 0], - codesToReturn: ['000025001', '000025002'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000680': // ADIRS SWTG - { - flightPhaseInhib: [], - simVarIsActive: !!(ATTKnob !== 1 || AIRKnob !== 1), - whichCodeToReturn: [0], - codesToReturn: ['000068001'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - '0000567': // VHF3 VOICE - { - flightPhaseInhib: [], - simVarIsActive: voiceVHF3 !== 0 && [1, 2, 6, 9, 10].includes(flightPhase), - whichCodeToReturn: [0], - codesToReturn: ['000056701'], - memoInhibit: false, - failure: 0, - sysPage: -1, - side: 'RIGHT', - }, - }; - - /* TO CONFIG */ - - useEffect(() => { - if (tomemo === 1 && toconfigBtn === 1) { - // TODO Note that fuel tank low pressure and gravity feed warnings are not included - let systemStatus = false; - if (engine1Generator && engine2Generator && !greenLP && !yellowLP && !blueLP && eng1pumpPBisAuto && eng2pumpPBisAuto) { - systemStatus = true; - } - const speeds = !!(v1Speed <= vrSpeed && vrSpeed <= v2Speed); - const doors = !!(cabin === 0 && catering === 0 && cargoaftLocked && cargofwdLocked); - const flapsAgree = !flapsMcduEntered || flapsHandle === flapsMcdu; - const sb = !speedBrakeCommand; - - if (systemStatus && speeds && !brakesHot && doors && flapsAgree && sb) { - SimVar.SetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool', 1); - setToConfigFailed(false); - } else { - SimVar.SetSimVarValue('L:A32NX_TO_CONFIG_NORMAL', 'bool', 0); - setToConfigFailed(true); - } - } - }, [ - engine1Generator, engine2Generator, blueLP, greenLP, yellowLP, eng1pumpPBisAuto, eng2pumpPBisAuto, - flapsMcdu, flapsMcduEntered, speedBrakeCommand, parkBrake, v1Speed, vrSpeed, v2Speed, cabin, - catering, cargoaftLocked, cargofwdLocked, toconfigBtn, tomemo, flapsHandle, brakesHot, - ]); - - useEffect(() => { - if (callPushAft || callPushAll || callPushForward) { - SimVar.SetSimVarValue('L:A32NX_CABIN_READY', 'bool', 1); - } - }, [callPushAft, callPushAll, callPushForward]); - - useEffect(() => { - let tempMemoArrayLeft:string[] = []; - let tempMemoArrayRight:string[] = []; - const allFailureKeys: string[] = []; - let tempFailureArrayLeft:string[] = []; - let failureKeysLeft: string[] = failuresLeft; - let recallFailureKeys: string[] = recallFailures; - let tempFailureArrayRight:string[] = []; - const failureKeysRight: string[] = failuresRight; - let leftFailureSystemCount = 0; - let rightFailureSystemCount = 0; - // Update failuresLeft list in case failure has been resolved - for (const [key, value] of Object.entries(EWDMessageFailures)) { - if (!value.simVarIsActive || value.flightPhaseInhib.some((e) => e === flightPhase)) { - failureKeysLeft = failureKeysLeft.filter((e) => e !== key); - recallFailureKeys = recallFailures.filter((e) => e !== key); - } - } - setRecallFailures(recallFailureKeys); - // Failures first - for (const [key, value] of Object.entries(EWDMessageFailures)) { - if (value.simVarIsActive && !value.flightPhaseInhib.some((e) => e === flightPhase)) { - if (value.side === 'LEFT') { - allFailureKeys.push(key); - } - - if ((value.side === 'LEFT' && !failuresLeft.includes(key) && !recallFailureKeys.includes(key)) || (value.side === 'RIGHT' && !failuresRight.includes(key))) { - if (value.side === 'LEFT') { - failureKeysLeft.push(key); - } else { - failureKeysRight.push(key); - } - - if (value.failure === 3) { - masterWarning(1); - } - if (value.failure === 2) { - masterCaution(1); - } - } else if (![eng1FireTest, eng2FireTest, apuFireTest, cargoFireTest].every((e) => e === 0)) { - masterWarning(1); - } - const newCode: string[] = []; - if (!recallFailureKeys.includes(key)) { - const codeIndex = value.whichCodeToReturn.filter((e) => e !== null); - codeIndex.forEach((e: number) => { - newCode.push(value.codesToReturn[e]); - }); - if (value.sysPage > -1) { - if (value.side === 'LEFT') { - leftFailureSystemCount++; - } else { - rightFailureSystemCount++; - } - } - } - if (value.side === 'LEFT') { - tempFailureArrayLeft = tempFailureArrayLeft.concat(newCode); - } else { - tempFailureArrayRight = tempFailureArrayRight.concat(newCode); - } - - if (value.sysPage > -1) { - SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', value.sysPage); - } - } - } - - const failLeft = tempFailureArrayLeft.length > 0; - - const mesgFailOrderLeft: string[] = []; - const mesgFailOrderRight: string[] = []; - for (const [, value] of Object.entries(EWDMessageFailures)) { - if (value.side === 'LEFT') { - mesgFailOrderLeft.push(...value.codesToReturn); - } else { - mesgFailOrderRight.push(...value.codesToReturn); - } - } - const orderedFailureArrayLeft = mapOrder(tempFailureArrayLeft, mesgFailOrderLeft); - const orderedFailureArrayRight = mapOrder(tempFailureArrayRight, mesgFailOrderRight); - - setAllCurrentFailures(allFailureKeys); - setFailuresLeft(failureKeysLeft); - setFailuresRight(failureKeysRight); - - if (tempFailureArrayLeft.length > 0) { - setMemoMessageLeft(orderedFailureArrayLeft); - } - - for (const [, value] of Object.entries(EWDMessageMemos)) { - if (value.simVarIsActive && !(value.memoInhibit) && !value.flightPhaseInhib.some((e) => e === flightPhase)) { - const newCode: string[] = []; - - const codeIndex = value.whichCodeToReturn.filter((e) => e !== null); - codeIndex.forEach((e: number) => { - newCode.push(value.codesToReturn[e]); - }); - - if (value.side === 'LEFT' && !failLeft) { - tempMemoArrayLeft = tempMemoArrayLeft.concat(newCode); - } - if (value.side === 'RIGHT') { - const tempArrayRight = tempMemoArrayRight.filter((e) => !value.codesToReturn.includes(e)); - tempMemoArrayRight = tempArrayRight.concat(newCode); - } - - if (value.sysPage > -1) { - SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', value.sysPage); - } - } - } - const mesgOrderLeft: string[] = []; - const mesgOrderRight: string[] = []; - for (const [, value] of Object.entries(EWDMessageMemos)) { - if (value.side === 'LEFT') { - mesgOrderLeft.push(...value.codesToReturn); - } else { - mesgOrderRight.push(...value.codesToReturn); - } - } - const orderedMemoArrayLeft = mapOrder(tempMemoArrayLeft, mesgOrderLeft); - let orderedMemoArrayRight = mapOrder(tempMemoArrayRight, mesgOrderRight); - - if (!failLeft) { - setMemoMessageLeft(orderedMemoArrayLeft); - if (orderedFailureArrayRight.length === 0) { - masterCaution(0); - masterWarning(0); - } - } - - if (leftFailureSystemCount + rightFailureSystemCount === 0) { - SimVar.SetSimVarValue('L:A32NX_ECAM_SFAIL', 'number', -1); - } - - if (orderedFailureArrayRight.length > 0) { - // Right side failures need to be inserted between special lines - // and the rest of the memo - const specialLines = ['000014001', '000015001', '000035001', '000036001', '220001501', '220002101']; - const filteredMemo = orderedMemoArrayRight.filter((e) => !specialLines.includes(e)); - const specLinesInMemo = orderedMemoArrayRight.filter((e) => specialLines.includes(e)); - if (specLinesInMemo.length > 0) { - orderedMemoArrayRight = [...specLinesInMemo, ...orderedFailureArrayRight, ...filteredMemo]; - } else { - orderedMemoArrayRight = [...orderedFailureArrayRight, ...orderedMemoArrayRight]; - } - } - setMemoMessageRight(orderedMemoArrayRight); - - // - }, [ac1BusPowered, - ac2BusPowered, - adirsMessage1(adirsRemainingAlignTime, (engine1State > 0 || engine2State > 0)), - adirsMessage2(adirsRemainingAlignTime, (engine1State > 0 || engine2State > 0)), - adiru1State, - adiru2State, - adiru3State, - agent1Eng1Discharge, - agent1Eng2Discharge, - agent2Eng1Discharge, - agent2Eng2Discharge, - agentAPUDischarge, - AIRKnob, - altn1LawConfirmNodeOutput, - altn2LawConfirmNodeOutput, - antiskidActive, - apuAgentPB, - apuAvail, - apuBleedValveOpen, - apuFireTest, - apuMasterSwitch, - ATTKnob, - autoBrake, - autoBrakesArmedMode, - autoThrustStatus, - blueElecPumpPBAuto, - blueRvrLow, - blueRvrOvht, - brakeFan, - cabAltSetResetState1, - cabAltSetResetState2, - cabinReady, - cabinRecircBtnOn, - cargoFireAgentDisch, - cargoFireTest, - compMesgCount, - computedAirSpeedToNearest2, - configPortableDevices, - dc2BusPowered, - dcESSBusPowered, - dmcSwitchingKnob, - directLawCondition, - elac1FaultConfirmNodeOutput, - elac1FaultLine123Display, - elac2FaultConfirmNodeOutput, - elac2FaultLine123Display, - sec1FaultCondition, - sec1FaultLine123Display, - sec2FaultCondition, - sec2FaultLine123Display, - sec3FaultCondition, - sec3FaultLine123Display, - lrElevFaultCondition, - fcdc12FaultCondition, - fcdc1FaultCondition, - fcdc2FaultCondition, - emergencyGeneratorOn, - engine1ValueSwitch, - engine2ValueSwitch, - eng1Agent1PB, - eng1Agent2PB, - eng1AntiIce, - eng1FireTest, - engine1State, - eng1pumpPBisAuto, - eng2Agent1PB, - eng2Agent2PB, - eng2AntiIce, - eng2FireTest, - eng2pumpPBisAuto, - engine2State, - engDualFault, - engSelectorPosition, - excessPressure, - fac1Failed, - fireButton1, - fireButton2, - fireButtonAPU, - flapsInfA, - flapsSupF, - flapsHandle, - flapsIndex, - flightPhase, - flightPhaseInhibitOverride, - fobRounded, - fuel, - fuelXFeedPBOn, - gpwsFlapMode, - gpwsFlaps3, - gpwsTerrOff, - greenHydEng1PBAuto, - greenRvrOvht, - height1Failed, - height2Failed, - hydPTU, - iceDetectedTimer1, - iceDetectedTimer2, - iceNotDetTimer1, - iceNotDetTimer2, - iceSevereDetectedTimer, - landASAPRed, - landingLight2Retracted, - landingLight3Retracted, - ldgmemo, - leftOuterInnerValve, - lgciu1Fault, - lgciu2Fault, - manLandingElevation, - ndXfrKnob, - noSmoking, - noSmokingSwitchPosition, - nwSteeringDisc, - packOffBleedIsAvailable1, - packOffBleedIsAvailable1, - packOffNotFailure1, - packOffNotFailure2, - parkBrake, - predWSOn, - ptuIsAuto, - ratDeployed, - recallReset, - rightOuterInnerValve, - seatBelt, - showTakeoffInhibit, - showLandingInhibit, - slatsInfD, - slatsSupG, - speedBrakeCommand, - spoilersArmed, - strobeLightsOn, - tcasFault, - tcasMode, - tcasSensitivity, - toconfig, - toconfigFailed, - throttle1Position, - throttle2Position, - thrustLeverNotSet, - tomemo, - unit, - usrStartRefueling, - wingAntiIce, - voiceVHF3, - yellowRvrOvht, - yepumpPBisAuto, - ]); - - useEffect(() => { - [1, 2, 3, 4, 5, 6, 7].forEach((value) => { - SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_LEFT_LINE_${value}`, 'string', ''); - }); - if (memoMessageLeft.length > 0) { - memoMessageLeft.forEach((value, index) => { - SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_LEFT_LINE_${index + 1}`, 'string', value); - }); - } - }, [memoMessageLeft]); - - useEffect(() => { - [1, 2, 3, 4, 5, 6, 7].forEach((value) => { - SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_RIGHT_LINE_${value}`, 'string', ''); - }); - if (memoMessageRight.length > 0) { - memoMessageRight.forEach((value, index) => { - SimVar.SetSimVarValue(`L:A32NX_EWD_LOWER_RIGHT_LINE_${index + 1}`, 'string', value); - }); - } - }, [memoMessageRight]); - - useEffect(() => { - SimVar.SetSimVarValue('L:A32NX_STATUS_LEFT_LINE_8', 'string', '000000001'); - }, []); - - return null; -}; - -export default PseudoFWC; diff --git a/fbw-a32nx/src/systems/instruments/src/EWD/index.tsx b/fbw-a32nx/src/systems/instruments/src/EWD/index.tsx index 8593b60079a..cf1aa58c8cd 100644 --- a/fbw-a32nx/src/systems/instruments/src/EWD/index.tsx +++ b/fbw-a32nx/src/systems/instruments/src/EWD/index.tsx @@ -1,5 +1,6 @@ -import React from 'react'; +import React, { useState } from 'react'; import { DisplayUnit } from '@instruments/common/displayUnit'; +import { useUpdate } from '@instruments/common/hooks'; import { render } from '../Common'; import UpperDisplay from './elements/UpperDisplay'; import LowerLeftDisplay from './elements/LowerLeftDisplay'; @@ -7,28 +8,33 @@ import LowerRightDisplay from './elements/LowerRightDisplay'; import STS from './elements/STS'; import ADV from './elements/ADV'; import DownArrow from './elements/DownArrow'; -import PseudoFWC from './elements/PseudoFWC'; +import { PseudoFWC } from './PseudoFWC'; import './style.scss'; -export const EWD: React.FC = () => ( - - - - - - - - - - - - - - -); +export const EWD: React.FC = () => { + const [pseudoFwc] = useState(() => new PseudoFWC()); + + useUpdate((deltaTime) => pseudoFwc.onUpdate(deltaTime)); + + return ( + + + + + + + + + + + + + + ); +}; render();