Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a32nx/fms): database holds #9775

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
1. [A380X/MFD] Add airport data page into the MFD (DATA > AIRPORT) - @bulenteroglu (senolitam)
1. [A380X/EFB] Adds PRIM/SEC/FCDC failures to EFB - @flogross89 (floridude)
1. [A380X/PFD] Fix precision of pitch trim indicator - @flogross89 (floridude)

1. [A32NX/FMS] Add terminal area database holds for MSFS2024 - @tracernz (Mike)

## 0.12.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2023 FlyByWire Simulations
// Copyright (c) 2021-2023, 2025 FlyByWire Simulations
//
// SPDX-License-Identifier: GPL-3.0

Expand Down Expand Up @@ -55,22 +55,112 @@ class CDUHoldAtPage {
type: HoldType.Computed,
};
modifiedHold = {};

const fix = waypoint.terminationWaypoint();
if (fix && fix.area === 1 /* WaypointArea.Terminal */ && fix.airportIdent && fix.airportIdent.length === 4) {
Fmgc.NavigationDatabaseService.activeDatabase.getHolds(fix.ident, fix.airportIdent).then((holds) => {
// Pick a hold based on altitude suitability and inbound course
// Missing in the navdata is the duplicate indicator that would help us pick the right area/airspace type.
holds
.filter((v) => v.waypoint.databaseId === fix.databaseId)
.sort((a, b) => {
let ret = CDUHoldAtPage.holdVerticalDistanceFromAlt(alt, a) - CDUHoldAtPage.holdVerticalDistanceFromAlt(alt, b);
if (ret === 0) {
ret = Math.abs(a.magneticCourse - inboundMagneticCourse) - Math.abs(b.magneticCourse - inboundMagneticCourse);
}
return ret;
});

if (holds[0]) {
defaultHold = {
inboundMagneticCourse: holds[0].magneticCourse,
turnDirection: holds[0].turnDirection,
time: holds[0].lengthTime ? holds[0].lengthTime : undefined,
distance: holds[0].length ? holds[0].length : undefined,
type: HoldType.Database,
};
}

CDUHoldAtPage.addOrEditManualHold(
mcdu,
waypointIndexFP,
// eslint-disable-next-line prefer-object-spread
Object.assign({}, defaultHold),
modifiedHold,
defaultHold,
forPlan,
inAlternate,
);
}).catch(() => {
CDUHoldAtPage.addOrEditManualHold(
mcdu,
waypointIndexFP,
// eslint-disable-next-line prefer-object-spread
Object.assign({}, defaultHold),
modifiedHold,
defaultHold,
forPlan,
inAlternate,
);
});
return;
}
}

mcdu.flightPlanService.addOrEditManualHold(
CDUHoldAtPage.addOrEditManualHold(
mcdu,
waypointIndexFP,
// eslint-disable-next-line prefer-object-spread
Object.assign({}, defaultHold),
modifiedHold,
defaultHold,
forPlan,
inAlternate,
).then((holdIndex) => {
CDUHoldAtPage.DrawPage(mcdu, holdIndex, waypointIndexFP, forPlan, inAlternate);
});
);
}
}

static holdVerticalDistanceFromAlt(altitude, hold) {
switch (hold.altitudeDescriptor) {
case "B":
if (altitude <= hold.altitude1 && altitude >= hold.altitude2) {
return 0;
}
if (altitude > hold.altitude1) {
return altitude - hold.altitude1;
}
return hold.altitude2 - altitude;
case "+":
return altitude >= hold.altitude1 ? 0 : hold.altitude1 - altitude;
case "-":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you could do

Suggested change
return altitude >= hold.altitude1 ? 0 : hold.altitude1 - altitude;
return Math.max(0, hold.altitude1 - altitude);

The same for the next case.

return altitude <= hold.altitude1 ? 0 : altitude - hold.altitude1;
default:
// no restriction, so always suitable
return 0;
}
}

static addOrEditManualHold(
mcdu,
atIndex,
desiredHold,
modifiedHold,
defaultHold,
planIndex,
alternate,
) {
mcdu.flightPlanService.addOrEditManualHold(
atIndex,
desiredHold,
modifiedHold,
defaultHold,
planIndex,
alternate,
).then((holdIndex) => {
CDUHoldAtPage.DrawPage(mcdu, holdIndex, atIndex, planIndex, alternate);
});
}

static DrawPage(mcdu, waypointIndexFP, originalFpIndex, forPlan, inAlternate) {
mcdu.clearDisplay();
mcdu.page.Current = mcdu.page.HoldAtPage;
Expand Down
Loading