From a229326fc93d39df77d84cb2543afee059c4639b Mon Sep 17 00:00:00 2001 From: Saschl Date: Mon, 16 Dec 2024 00:43:46 +0100 Subject: [PATCH 1/3] fix: enable transition from done phase to preflight phase --- .../src/MFD/FMC/FlightManagementComputer.ts | 45 +++++++++++++++++-- .../src/systems/instruments/src/MFD/MFD.tsx | 2 +- .../src/MFD/pages/common/MfdUiService.tsx | 13 +++++- .../instruments/src/MFD/shared/MfdUIData.ts | 8 ++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts diff --git a/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts b/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts index c2e05a204e2..fdb2f6876d3 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts +++ b/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts @@ -16,7 +16,16 @@ import { NavigationDatabaseService, } from '@fmgc/index'; import { A380AircraftConfig } from '@fmgc/flightplanning/A380AircraftConfig'; -import { ArraySubject, EventBus, SimVarValueType, Subject, Subscribable, Subscription } from '@microsoft/msfs-sdk'; +import { + ArraySubject, + ConsumerSubject, + EventBus, + MappedSubject, + SimVarValueType, + Subject, + Subscribable, + Subscription, +} from '@microsoft/msfs-sdk'; import { A380AltitudeUtils } from '@shared/OperatingAltitudes'; import { maxBlockFuel, maxCertifiedAlt, maxZfw } from '@shared/PerformanceConstants'; import { FmgcFlightPhase } from '@shared/flightphase'; @@ -48,6 +57,9 @@ import { FmcIndex } from 'instruments/src/MFD/FMC/FmcServiceInterface'; import { FmsErrorType } from '@fmgc/FmsError'; import { A380Failure } from '@failures'; import { FpmConfigs } from '@fmgc/flightplanning/FpmConfig'; +import { FlightPhaseManagerEvents } from '@fmgc/flightphase'; +import { MfdUIData } from 'instruments/src/MFD/shared/MfdUIData'; +import { ActiveUriInformation } from 'instruments/src/MFD/pages/common/MfdUiService'; export interface FmsErrorMessage { message: McduMessage; @@ -139,6 +151,23 @@ export class FlightManagementComputer implements FmcInterface { // TODO remove this cyclic dependency, isWaypointInUse should be moved to DataInterface private dataManager: DataManager | null = null; + private readonly flightPhase = ConsumerSubject.create(null, this.flightPhaseManager.phase); + private readonly activePage = ConsumerSubject.create(null, null); + private readonly isReset = Subject.create(true); + + private readonly shouldBePreflightPhase = MappedSubject.create( + ([phase, page, isReset]) => { + const isPreflight = + phase === FmgcFlightPhase.Done && + isReset && + (page?.uri === 'fms/active/init' || page?.uri === 'fms/active/fuel-load' || page?.uri === 'fms/active/perf'); + return isPreflight; + }, + this.flightPhase, + this.activePage, + this.isReset, + ); + public getDataManager() { return this.dataManager; } @@ -216,6 +245,16 @@ export class FlightManagementComputer implements FmcInterface { this.flightPhaseManager.addOnPhaseChanged((prev, next) => this.onFlightPhaseChanged(prev, next)); + const sub = this.bus.getSubscriber(); + this.flightPhase.setConsumer(sub.on('fmgc_flight_phase')); + this.activePage.setConsumer(sub.on('mfd_active_uri')); + + this.shouldBePreflightPhase.sub((shouldBePreflight) => { + if (shouldBePreflight) { + this.flightPhaseManager.changePhase(FmgcFlightPhase.Preflight); + } + }, true); + this.subs.push( this.enginesWereStarted.sub((val) => { if ( @@ -594,6 +633,7 @@ export class FlightManagementComputer implements FmcInterface { this.acInterface.updateManagedSpeed(); SimVar.SetSimVarValue('L:A32NX_CABIN_READY', 'Bool', 0); + this.isReset.set(false); switch (nextPhase) { case FmgcFlightPhase.Takeoff: { @@ -756,8 +796,6 @@ export class FlightManagementComputer implements FmcInterface { } case FmgcFlightPhase.Done: - this.mfdReference?.uiService.navigateTo('fms/data/status'); - this.flightPlanService .reset() .then(() => { @@ -767,6 +805,7 @@ export class FlightManagementComputer implements FmcInterface { this.clearLatestFmsErrorMessage(); SimVar.SetSimVarValue('L:A32NX_COLD_AND_DARK_SPAWN', 'Bool', true).then(() => { this.mfdReference?.uiService.navigateTo('fms/data/status'); + this.isReset.set(true); }); }) .catch(console.error); diff --git a/fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx b/fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx index 5203dbeb91e..166e5dd066e 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx +++ b/fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx @@ -65,7 +65,7 @@ export enum InteractionMode { export class MfdComponent extends DisplayComponent implements DisplayInterface, MfdDisplayInterface { private readonly sub = this.props.bus.getSubscriber(); - #uiService = new MfdUiService(this.props.captOrFo); + #uiService = new MfdUiService(this.props.captOrFo, this.props.bus); get uiService() { return this.#uiService; diff --git a/fbw-a380x/src/systems/instruments/src/MFD/pages/common/MfdUiService.tsx b/fbw-a380x/src/systems/instruments/src/MFD/pages/common/MfdUiService.tsx index 1b635ba76e3..7459d9ada0b 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/pages/common/MfdUiService.tsx +++ b/fbw-a380x/src/systems/instruments/src/MFD/pages/common/MfdUiService.tsx @@ -1,4 +1,5 @@ -import { FSComponent, Subject } from '@microsoft/msfs-sdk'; +import { EventBus, FSComponent, Publisher, Subject } from '@microsoft/msfs-sdk'; +import { MfdUIData } from 'instruments/src/MFD/shared/MfdUIData'; export enum MfdSystem { None = '', @@ -23,7 +24,14 @@ export interface ActiveUriInformation { * Handles navigation (and potentially other aspects) for MFD pages */ export class MfdUiService { - constructor(public captOrFo: 'CAPT' | 'FO') {} + private readonly pub: Publisher; + + constructor( + public captOrFo: 'CAPT' | 'FO', + private readonly bus: EventBus, + ) { + this.pub = this.bus.getPublisher(); + } public readonly activeUri = Subject.create({ uri: '', @@ -79,6 +87,7 @@ export class MfdUiService { const parsedUri = this.parseUri(nextUri); this.activeUri.set(parsedUri); + this.pub.pub('mfd_active_uri', parsedUri); } /* diff --git a/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts b/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts new file mode 100644 index 00000000000..7bcbaea7171 --- /dev/null +++ b/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts @@ -0,0 +1,8 @@ +import { ActiveUriInformation } from 'instruments/src/MFD/pages/common/MfdUiService'; + +/** + * Mfd Events + */ +export interface MfdUIData { + mfd_active_uri: ActiveUriInformation; +} From 966948aff46eb6e82823ce92d6b171fc09b4d73a Mon Sep 17 00:00:00 2001 From: Saschl Date: Mon, 16 Dec 2024 00:54:48 +0100 Subject: [PATCH 2/3] cleanup --- fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts b/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts index 7bcbaea7171..eb625b63896 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts +++ b/fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts @@ -1,8 +1,5 @@ import { ActiveUriInformation } from 'instruments/src/MFD/pages/common/MfdUiService'; -/** - * Mfd Events - */ export interface MfdUIData { mfd_active_uri: ActiveUriInformation; } From 29a21699d67b249ab07987ff3f2f47ef5a39ca86 Mon Sep 17 00:00:00 2001 From: Saschl Date: Thu, 2 Jan 2025 14:42:27 +0100 Subject: [PATCH 3/3] apply suggestions --- .../src/MFD/FMC/FlightManagementComputer.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts b/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts index fdb2f6876d3..92096f26a14 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts +++ b/fbw-a380x/src/systems/instruments/src/MFD/FMC/FlightManagementComputer.ts @@ -151,8 +151,17 @@ export class FlightManagementComputer implements FmcInterface { // TODO remove this cyclic dependency, isWaypointInUse should be moved to DataInterface private dataManager: DataManager | null = null; - private readonly flightPhase = ConsumerSubject.create(null, this.flightPhaseManager.phase); - private readonly activePage = ConsumerSubject.create(null, null); + private readonly sub = this.bus.getSubscriber(); + + private readonly flightPhase = ConsumerSubject.create( + this.sub.on('fmgc_flight_phase'), + this.flightPhaseManager.phase, + ); + private readonly activePage = ConsumerSubject.create( + this.sub.on('mfd_active_uri'), + null, + ); + private readonly isReset = Subject.create(true); private readonly shouldBePreflightPhase = MappedSubject.create( @@ -245,10 +254,6 @@ export class FlightManagementComputer implements FmcInterface { this.flightPhaseManager.addOnPhaseChanged((prev, next) => this.onFlightPhaseChanged(prev, next)); - const sub = this.bus.getSubscriber(); - this.flightPhase.setConsumer(sub.on('fmgc_flight_phase')); - this.activePage.setConsumer(sub.on('mfd_active_uri')); - this.shouldBePreflightPhase.sub((shouldBePreflight) => { if (shouldBePreflight) { this.flightPhaseManager.changePhase(FmgcFlightPhase.Preflight);