Skip to content

Commit

Permalink
fix: only update ewd memo lines on change (#7921)
Browse files Browse the repository at this point in the history
* fix: only set lines for ewd when memos changed

* simplify check

* fix: use subscribables properly to set status lines
  • Loading branch information
Saschl authored Apr 7, 2023
1 parent 977e820 commit a9b4ac9
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions fbw-a32nx/src/systems/instruments/src/EWD/PseudoFWC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subject, Subscribable, MappedSubject, ArraySubject, DebounceTimer } from 'msfssdk';
import { Subject, Subscribable, MappedSubject, DebounceTimer } from 'msfssdk';

import { Arinc429Register, Arinc429Word } from '@shared/arinc429';
import { NXLogicClockNode, NXLogicConfirmNode, NXLogicMemoryNode, NXLogicPulseNode, NXLogicTriggeredMonostableNode } from '@instruments/common/NXLogic';
Expand Down Expand Up @@ -40,6 +40,16 @@ export class PseudoFWC {
/** The time to play the single chime sound in ms */
private static readonly AURAL_SC_PLAY_TIME = 500;

private static readonly EWD_MESSAGE_LINES = 7;

private static readonly ewdMessageSimVarsLeft = Array.from({ length: PseudoFWC.EWD_MESSAGE_LINES }, (_, i) => `L:A32NX_EWD_LOWER_LEFT_LINE_${i + 1}`);

private readonly ewdMessageLinesLeft = Array.from({ length: PseudoFWC.EWD_MESSAGE_LINES }, (_, _i) => Subject.create(''));

private static readonly ewdMessageSimVarsRight = Array.from({ length: PseudoFWC.EWD_MESSAGE_LINES }, (_, i) => `L:A32NX_EWD_LOWER_RIGHT_LINE_${i + 1}`);

private readonly ewdMessageLinesRight = Array.from({ length: PseudoFWC.EWD_MESSAGE_LINES }, (_, _i) => Subject.create(''));

/* PSEUDO FWC VARIABLES */

private readonly allCurrentFailures: string[] = [];
Expand All @@ -48,10 +58,6 @@ export class PseudoFWC {

private readonly failuresRight: string[] = [];

private memoMessageLeft: ArraySubject<string> = ArraySubject.create([]);

private memoMessageRight: ArraySubject<string> = ArraySubject.create([]);

private recallFailures: string[] = [];

private auralCrcKeys: string[] = [];
Expand Down Expand Up @@ -678,23 +684,13 @@ export class PseudoFWC {
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.ewdMessageLinesLeft.forEach((ls, i) => ls.sub((l) => {
SimVar.SetSimVarValue(PseudoFWC.ewdMessageSimVarsLeft[i], 'string', l ?? '');
}));

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);
});
});
this.ewdMessageLinesRight.forEach((ls, i) => ls.sub((l) => {
SimVar.SetSimVarValue(PseudoFWC.ewdMessageSimVarsRight[i], 'string', l ?? '');
}));

SimVar.SetSimVarValue('L:A32NX_STATUS_LEFT_LINE_8', 'string', '000000001');
}
Expand Down Expand Up @@ -1594,7 +1590,7 @@ export class PseudoFWC {
this.failuresRight.push(...failureKeysRight);

if (tempFailureArrayLeft.length > 0) {
this.memoMessageLeft.set(orderedFailureArrayLeft);
this.ewdMessageLinesLeft.forEach((l, i) => l.set(orderedFailureArrayLeft[i]));
}

for (const [, value] of Object.entries(this.ewdMessageMemos)) {
Expand Down Expand Up @@ -1635,7 +1631,7 @@ export class PseudoFWC {
let orderedMemoArrayRight: string[] = this.mapOrder(tempMemoArrayRight, mesgOrderRight);

if (!failLeft) {
this.memoMessageLeft.set(orderedMemoArrayLeft);
this.ewdMessageLinesLeft.forEach((l, i) => l.set(orderedMemoArrayLeft[i]));

if (orderedFailureArrayRight.length === 0) {
this.masterCaution.set(false);
Expand All @@ -1660,7 +1656,7 @@ export class PseudoFWC {
}
}

this.memoMessageRight.set(orderedMemoArrayRight);
this.ewdMessageLinesRight.forEach((l, i) => l.set(orderedMemoArrayRight[i]));

// This does not consider interrupting c-chord, priority of synthetic voice etc.
// We shall wait for the rust FWC for those nice things!
Expand Down

0 comments on commit a9b4ac9

Please sign in to comment.