Skip to content

Commit

Permalink
fix: enable transition from done phase to preflight phase (#9664)
Browse files Browse the repository at this point in the history
* fix: enable transition from done phase to preflight phase

* cleanup

* apply suggestions
  • Loading branch information
Saschl authored Jan 4, 2025
1 parent 9afdf9f commit ae669a6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +151,32 @@ export class FlightManagementComputer implements FmcInterface {
// TODO remove this cyclic dependency, isWaypointInUse should be moved to DataInterface
private dataManager: DataManager | null = null;

private readonly sub = this.bus.getSubscriber<FlightPhaseManagerEvents & MfdUIData>();

private readonly flightPhase = ConsumerSubject.create<FmgcFlightPhase>(
this.sub.on('fmgc_flight_phase'),
this.flightPhaseManager.phase,
);
private readonly activePage = ConsumerSubject.create<ActiveUriInformation | null>(
this.sub.on('mfd_active_uri'),
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;
}
Expand Down Expand Up @@ -216,6 +254,12 @@ export class FlightManagementComputer implements FmcInterface {

this.flightPhaseManager.addOnPhaseChanged((prev, next) => this.onFlightPhaseChanged(prev, next));

this.shouldBePreflightPhase.sub((shouldBePreflight) => {
if (shouldBePreflight) {
this.flightPhaseManager.changePhase(FmgcFlightPhase.Preflight);
}
}, true);

this.subs.push(
this.enginesWereStarted.sub((val) => {
if (
Expand Down Expand Up @@ -594,6 +638,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: {
Expand Down Expand Up @@ -756,8 +801,6 @@ export class FlightManagementComputer implements FmcInterface {
}

case FmgcFlightPhase.Done:
this.mfdReference?.uiService.navigateTo('fms/data/status');

this.flightPlanService
.reset()
.then(() => {
Expand All @@ -767,6 +810,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);
Expand Down
2 changes: 1 addition & 1 deletion fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export enum InteractionMode {
export class MfdComponent extends DisplayComponent<MfdComponentProps> implements DisplayInterface, MfdDisplayInterface {
private readonly sub = this.props.bus.getSubscriber<ClockEvents & MfdSimvars>();

#uiService = new MfdUiService(this.props.captOrFo);
#uiService = new MfdUiService(this.props.captOrFo, this.props.bus);

get uiService() {
return this.#uiService;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = '',
Expand All @@ -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<MfdUIData>;

constructor(
public captOrFo: 'CAPT' | 'FO',
private readonly bus: EventBus,
) {
this.pub = this.bus.getPublisher<MfdUIData>();
}

public readonly activeUri = Subject.create<ActiveUriInformation>({
uri: '',
Expand Down Expand Up @@ -79,6 +87,7 @@ export class MfdUiService {

const parsedUri = this.parseUri(nextUri);
this.activeUri.set(parsedUri);
this.pub.pub('mfd_active_uri', parsedUri);
}

/*
Expand Down
5 changes: 5 additions & 0 deletions fbw-a380x/src/systems/instruments/src/MFD/shared/MfdUIData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ActiveUriInformation } from 'instruments/src/MFD/pages/common/MfdUiService';

export interface MfdUIData {
mfd_active_uri: ActiveUriInformation;
}

0 comments on commit ae669a6

Please sign in to comment.