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): accurate altimetry and split baro corrections #9659

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9a34bf4
feat(adr): implement altitude calculation
tracernz Dec 14, 2024
2f7f192
refactor: split msfs altimeters
tracernz Dec 14, 2024
1cbaedd
feat: add shared switching knob defs
tracernz Dec 14, 2024
80c9ffa
fix: arinc429 piping and raw word bugs
tracernz Dec 14, 2024
9cd6c48
fix: accept functional test as valid a429 ssm
tracernz Dec 14, 2024
e34ef43
feat: add some new-style shared publishers
tracernz Dec 14, 2024
b457656
feat: fms nav function provides pressure altitude
tracernz Dec 14, 2024
0fb1014
fix(fms): flight phase pressure altitude usage
tracernz Dec 14, 2024
cb00f95
fix: pressure altitude source selection
tracernz Dec 14, 2024
3e15648
fix(pfd): filter is specific by corner freq, not time constant
tracernz Dec 14, 2024
a096582
feat(pfd): provide previous filter output
tracernz Dec 14, 2024
b9a8535
fix(pfd): select correct displayed altitude source
tracernz Dec 14, 2024
ac8f870
feat(pfd): add pseudo dmc to publish dmc data for fwc
tracernz Dec 14, 2024
d2a1512
feat(pfd): check alt message
tracernz Dec 14, 2024
581d91b
docs: correct inaccurate comment
tracernz Dec 14, 2024
df7f321
feat(fwc): alti and baro ref discrepancy
tracernz Dec 14, 2024
0a5a843
fix(fcu): baro sync
tracernz Dec 14, 2024
6b841ee
build: add missing dep to make atc rebuild on tcas changes
tracernz Dec 14, 2024
eba34d9
fix(a380x/fcu): provide baro altimetry bus outputs and prepare split
tracernz Dec 14, 2024
60b96e2
fix(a380x/pfd): plumb new altitude and baro data
tracernz Dec 14, 2024
322f82d
docs: changelog
tracernz Dec 14, 2024
f9e18a3
feat(a380x/fcu): pre-sel lvar for 3rd party
tracernz Dec 14, 2024
8f7d1a5
fix: spelling of kohlsman
tracernz Dec 16, 2024
213ee01
fix(a32nx): set KOHLSMAN SETTING STD on right altimeter
tracernz Dec 16, 2024
c8ee868
fix: struct member name
tracernz Dec 16, 2024
2c76385
Merge remote-tracking branch 'upstream/master' into mrc-altimetry
tracernz Dec 16, 2024
2f39f7c
fix: too trigger happy on the replace
tracernz Dec 16, 2024
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
6 changes: 6 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
1. [A380X/FCU] Add correct QFE label using the baro preselect display - @heclak (Heclak)
1. [FMS] Move the speed limit data to performance data, so that it is flight-plan-specific - @BlueberryKing (BlueberryKing)
1. [A32NX/FWC] Add FCU faults - @tracernz (Mike)
1. [ADR] Implement accurate altimetry computations - @tracernz (Mike)
1. [A32NX] Split EIS baro corrections between captain and first officer side - @tracernz (Mike)
1. [A32NX] Increased available baro correction range to 745-1100 hPa - @tracernz (Mike)
1. [A32NX/FWC] Add baro ref and altitude discrepancy warnings - @tracernz (Mike)
1. [A32NX/PFD] Add CHECK ALT message - @tracernz (Mike)
1. [A380X] Increased available baro correction range to 745-1100 hPa - @tracernz (Mike)

## 0.12.0

Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/docs/a320-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@

- A32NX.FCU_EFIS_{side}_BARO_SET
- Triggered to set the baro value on FCU
- Value is expected as the first parameter, in hPa * 16 (i.e. with a factor 16 applied, same as KOHLSMANN_SET).
- Value is expected as the first parameter, in hPa * 16 (i.e. with a factor 16 applied, same as KOHLSMAN_SET).
- side = L, R

- A32NX.FCU_EFIS_{side}_BARO_PUSH
Expand Down
1 change: 0 additions & 1 deletion fbw-a32nx/docs/a320-simvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,6 @@ In the variables below, {number} should be replaced with one item in the set: {
- A32NX_ADIRS_ADR_{number}_BARO_CORRECTED_ALTITUDE_{side}
- Arinc429Word<Feet>
- The baro corrected altitude in feet.
- TODO currently returns pressure altitude when STD mode is selected
- {side}
- 1: Captain
- 2: First Officer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,14 @@ airspeed_indicator.0 = 1, 0
airspeed_indicator.1 = 1, 0

[ALTIMETERS]
altimeter.0 = 1 ; PFDs, index 1 in simvars
altimeter_position.0 = 5.000000, -5.000000, 0.000000
altimeter.1 = 1 ; ISIS, index 2 in simvars
altimeter_position.1 = -5.000000, -5.000000, 0.000000
altimeter.2 = 1 ; Autopilot, index 3 in simvars
altimeter_position.2 = 5.000000, -5.000000, 0.000000
altimeter.0 = 1 ; Captain side, index 1 in simvars
altimeter_position.0 = 5.000000, -5.000000, 0.000000
altimeter.1 = 1 ; First officer side, index 2 in simvars
altimeter_position.1 = 5.000000, -5.000000, 0.000000
altimeter.2 = 1 ; ISIS, index 3 in simvars
altimeter_position.2 = -5.000000, -5.000000, 0.000000
altimeter.3 = 1 ; Autopilot, index 4 in simvars
altimeter_position.3 = 5.000000, -5.000000, 0.000000


[GPWS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@
<UseTemplate Name="FBW_ISIS_Knob_Template">
<ANIM_NAME>AUTOPILOT_Knob_Baro</ANIM_NAME>
<NODE_ID>AUTOPILOT_Knob_Baro</NODE_ID>
<ALTIMETER_INDEX>3</ALTIMETER_INDEX>
</UseTemplate>
<UseTemplate Name="FBW_Anim_Interactions">
<ANIM_TYPE>BUTTON</ANIM_TYPE>
Expand Down
32 changes: 18 additions & 14 deletions fbw-a32nx/src/behavior/src/A32NX_Interior_EFIS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,36 @@
</Template>

<Template Name="FBW_AIRLINER_Switch_Baro_Selector_Template">
<DefaultTemplateParameters>
<Parameters Type="Default">
<ID>1</ID>
<SIDE>L</SIDE>
</DefaultTemplateParameters>

<UseTemplate Name="FBW_AIRLINER_Switch_Baro_Selector_SubTemplate">
</UseTemplate>
</Template>

<Template Name="FBW_AIRLINER_Switch_Baro_Selector_SubTemplate">
<DefaultTemplateParameters>
</Parameters>
<Parameters Type="Default">
<NODE_ID>AIRLINER_Switch_Baro_Selector_#ID#</NODE_ID>
<ANIM_NAME>AIRLINER_Switch_Baro_Selector_#ID#</ANIM_NAME>
<PART_ID>AIRLINER_Switch_Baro_Selector</PART_ID>
<WWISE_EVENT_1>lswitch</WWISE_EVENT_1>
<WWISE_EVENT_2>lswitch</WWISE_EVENT_2>
<ANIMTIP_0>TT:COCKPIT.TOOLTIPS.BARO_SET_UNIT_TO_HPA</ANIMTIP_0>
<ANIMTIP_1>TT:COCKPIT.TOOLTIPS.BARO_SET_UNIT_TO_HG</ANIMTIP_1>
</DefaultTemplateParameters>

</Parameters>
<Parameters Type="OVERRIDE">
<Switch Param="SIDE">
<Case Value="R">
<OFFSIDE>L</OFFSIDE>
</Case>
<Default>
<OFFSIDE>R</OFFSIDE>
</Default>
</Switch >
</Parameters>
<Component ID="#NODE_ID#" Node="#NODE_ID#">
<UseTemplate Name="ASOBO_GT_Switch_Code">
<!-- TODO unsync Baro unit selector -->
<LEFT_SINGLE_CODE>
(L:A32NX_FCU_EFIS_L_BARO_IS_INHG) ! (&gt;L:A32NX_FCU_EFIS_L_BARO_IS_INHG)
(L:A32NX_FCU_EFIS_R_BARO_IS_INHG) ! (&gt;L:A32NX_FCU_EFIS_R_BARO_IS_INHG)
(L:A32NX_FCU_EFIS_#SIDE#_BARO_IS_INHG) ! (&gt;L:A32NX_FCU_EFIS_#SIDE#_BARO_IS_INHG)
(L:A32NX_FO_SYNC_EFIS_ENABLED) if{
(L:A32NX_FCU_EFIS_#SIDE#_BARO_IS_INHG) (&gt;L:A32NX_FCU_EFIS_#OFFSIDE#_BARO_IS_INHG)
}
</LEFT_SINGLE_CODE>
<ANIM_CODE>(L:A32NX_FCU_EFIS_#SIDE#_BARO_IS_INHG) ! 100 *</ANIM_CODE>
</UseTemplate>
Expand Down
21 changes: 12 additions & 9 deletions fbw-a32nx/src/behavior/src/A32NX_Interior_ISIS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
</Template>

<Template Name="FBW_ISIS_Knob_SubTemplate1">
<DefaultTemplateParameters>
<Parameters Type="Default">
<ALTIMETER_INDEX>#ID#</ALTIMETER_INDEX>
</Parameters>
<Parameters Type="Default">
<NODE_ID>AUTOPILOT_Knob_Baro_#ID##SUFFIX_ID#</NODE_ID>
<ANIM_NAME>AUTOPILOT_Knob_Baro_#ID##SUFFIX_ID#</ANIM_NAME>
<PART_ID>AUTOPILOT_Knob_Baro</PART_ID>
Expand All @@ -41,12 +44,12 @@
<MODE_STD>1</MODE_STD>
<!-- this can't be represented in RNP (yet...?), so we use this escape hatch -->
<SET_QNH_CODE>
2 (O:A32NX_ISIS_BARO_SAVED, number) (&gt;K:2:KOHLSMAN_SET)
#ALTIMETER_INDEX# (O:A32NX_ISIS_BARO_SAVED, number) (&gt;K:2:KOHLSMAN_SET)
</SET_QNH_CODE>
<SET_STD_CODE>
2 16211 (&gt;K:2:KOHLSMAN_SET)
#ALTIMETER_INDEX# 16211 (&gt;K:2:KOHLSMAN_SET)
</SET_STD_CODE>
</DefaultTemplateParameters>
</Parameters>
<Component ID="#NODE_ID#" Node="#NODE_ID#">
<UseTemplate Name="ASOBO_GT_Knob_Infinite_Push">
<ANTICLOCKWISE_CONDITION>1</ANTICLOCKWISE_CONDITION>
Expand All @@ -56,9 +59,9 @@
} els{
(L:A32NX_ISIS_BARO_MODE, enum) #MODE_STD# != if{
(L:A32NX_ISIS_BARO_UNIT_INHG, enum) if{
2 (&gt;K:KOHLSMAN_DEC)
#ALTIMETER_INDEX# (&gt;K:KOHLSMAN_DEC)
} els{
2 (A:KOHLSMAN SETTING MB:2, millibars) -- 16 * (&gt;K:2:KOHLSMAN_SET)
#ALTIMETER_INDEX# (A:KOHLSMAN SETTING MB:#ALTIMETER_INDEX#, millibars) -- 16 * (&gt;K:2:KOHLSMAN_SET)
}
}
}
Expand All @@ -70,17 +73,17 @@
} els{
(L:A32NX_ISIS_BARO_MODE, enum) #MODE_STD# != if{
(L:A32NX_ISIS_BARO_UNIT_INHG, enum) if{
2 (&gt;K:KOHLSMAN_INC)
#ALTIMETER_INDEX# (&gt;K:KOHLSMAN_INC)
} els{
2 (A:KOHLSMAN SETTING MB:2, millibars) ++ 16 * (&gt;K:2:KOHLSMAN_SET)
#ALTIMETER_INDEX# (A:KOHLSMAN SETTING MB:#ALTIMETER_INDEX#, millibars) ++ 16 * (&gt;K:2:KOHLSMAN_SET)
}
}
}
</CLOCKWISE_CODE>
<LEFT_SINGLE_CODE type="rnp">
alias bugsActive = (L:A32NX_ISIS_BUGS_ACTIVE, bool);
alias baroMode = (L:A32NX_ISIS_BARO_MODE, enum);
alias baroSetting = (A:KOHLSMAN SETTING MB:2, bars);
alias baroSetting = (A:KOHLSMAN SETTING MB:#ALTIMETER_INDEX#, bars);
alias baroSaved = (O:A32NX_ISIS_BARO_SAVED, number);

if bugsActive {
Expand Down
117 changes: 0 additions & 117 deletions fbw-a32nx/src/behavior/src/A32NX_Interior_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,123 +529,6 @@
</UseTemplate>
</Template>

<Template Name="FBW_AUTOPILOT_Knob_Baro_Template">
<DefaultTemplateParameters>
<ID>1</ID>
<ANIMREF_ID>-1</ANIMREF_ID>
<ANIMTIP_0>TT:COCKPIT.TOOLTIPS.AUTOPILOT_PANEL_BARO_KNOB_INCREASE</ANIMTIP_0>
<ANIMTIP_0_ON_CURSOR>TurnRight</ANIMTIP_0_ON_CURSOR>
<ANIMTIP_1>TT:COCKPIT.TOOLTIPS.AUTOPILOT_PANEL_BARO_KNOB_DECREASE</ANIMTIP_1>
<ANIMTIP_1_ON_CURSOR>TurnLeft</ANIMTIP_1_ON_CURSOR>
<ANIMTIP_2>TT:COCKPIT.TOOLTIPS.BARO_REF_SET_STD</ANIMTIP_2>
<ANIMTIP_2_ON_CURSOR>DownArrow</ANIMTIP_2_ON_CURSOR>
<ANIMTIP_3>TT:COCKPIT.TOOLTIPS.BARO_ENABLE_SELECTION</ANIMTIP_3>
<ANIMTIP_3_ON_CURSOR>UpArrow</ANIMTIP_3_ON_CURSOR>
<ANIMTIP_4>TT:COCKPIT.TOOLTIPS.BARO_REF_SET_STD</ANIMTIP_4>
<ANIMTIP_4_ON_CURSOR>Hand</ANIMTIP_4_ON_CURSOR>
</DefaultTemplateParameters>

<UseTemplate Name="ASOBO_GT_Helper_Suffix_ID_Appender">
<TEMPLATE_TO_CALL>FBW_AUTOPILOT_Knob_Baro_SubTemplate1</TEMPLATE_TO_CALL>
</UseTemplate>
</Template>
<Template Name="FBW_AUTOPILOT_Knob_Baro_SubTemplate1">
<DefaultTemplateParameters>
<NODE_ID>AUTOPILOT_Knob_Baro_#ID##SUFFIX_ID#</NODE_ID>
<ANIM_NAME>AUTOPILOT_Knob_Baro_#ID##SUFFIX_ID#</ANIM_NAME>
<PART_ID>AUTOPILOT_Knob_Baro</PART_ID>
<ANIMREF_ID>-1</ANIMREF_ID>
<ANIMTIP_0>TT:COCKPIT.TOOLTIPS.AUTOPILOT_PANEL_BARO_KNOB_INCREASE</ANIMTIP_0>
<ANIMTIP_0_ON_CURSOR>TurnRight</ANIMTIP_0_ON_CURSOR>
<ANIMTIP_1>TT:COCKPIT.TOOLTIPS.AUTOPILOT_PANEL_BARO_KNOB_DECREASE</ANIMTIP_1>
<ANIMTIP_1_ON_CURSOR>TurnLeft</ANIMTIP_1_ON_CURSOR>
</DefaultTemplateParameters>
<Component ID="#NODE_ID#" Node="#NODE_ID#">
<UseTemplate Name="FBW_AUTOPILOT_Knob_Baro_SubTemplate2">
</UseTemplate>
</Component>
</Template>
<Template Name="FBW_AUTOPILOT_Knob_Baro_SubTemplate2">
<DefaultTemplateParameters>
<BARO_ID>#ID#</BARO_ID>
<ANIM_NAME_KNOB>#ANIM_NAME#</ANIM_NAME_KNOB>
<ANIM_NAME_PUSH>AUTOPILOT_Knob_Baro_#ID#_push#SUFFIX_ID#</ANIM_NAME_PUSH>
<Switch Param="AIRLINER_TYPE">
<Case Value="A320">
<MODE_BARO>0</MODE_BARO>
<MODE_QNH>1</MODE_QNH>
<MODE_STD>2</MODE_STD>
<ANIM_NAME_PUSHPULL>AUTOPILOT_Knob_Baro_#ID#_pushpull#SUFFIX_ID#</ANIM_NAME_PUSHPULL>
</Case>
</Switch>
<Condition Valid="USE_PUSH_STD">
<PUSH/>
</Condition>
</DefaultTemplateParameters>

<Switch>
<Case Check="AIRLINER_TYPE">
<Switch Param="AIRLINER_TYPE">
<Case Value="A320">
<UseTemplate Name="ASOBO_GT_Knob_Infinite_PushPull">
<ANTICLOCKWISE_CODE>
#BARO_ID# (&gt;K:KOHLSMAN_DEC)
</ANTICLOCKWISE_CODE>
<CLOCKWISE_CODE>
#BARO_ID# (&gt;K:KOHLSMAN_INC)
</CLOCKWISE_CODE>
<CLOCKWISE_CONDITION>(L:XMLVAR_Baro#BARO_ID#_Mode) #MODE_STD# !=</CLOCKWISE_CONDITION>
<ANTICLOCKWISE_CONDITION>(L:XMLVAR_Baro#BARO_ID#_Mode) #MODE_STD# !=</ANTICLOCKWISE_CONDITION>
<PULL_CODE>
#MODE_STD# (&gt;L:XMLVAR_Baro#BARO_ID#_Mode)
</PULL_CODE>
<PUSH_CODE>
(L:XMLVAR_Baro#BARO_ID#_Mode) #MODE_STD# == if{ #MODE_BARO# (&gt;L:XMLVAR_Baro#BARO_ID#_Mode) } els{ (L:XMLVAR_Baro#BARO_ID#_Mode) ! (&gt;L:XMLVAR_Baro#BARO_ID#_Mode) }
</PUSH_CODE>
<CENTER_RADIUS>0</CENTER_RADIUS>
<OVERRIDE_PUSH_ANIM_CODE>0 100 (L:XMLVAR_Baro#BARO_ID#_Mode) #MODE_STD# == ? 50 (O:_PushAnimVar) ?</OVERRIDE_PUSH_ANIM_CODE>
<COUNT>36</COUNT>
</UseTemplate>
</Case>
<Default>
<UseTemplate Name="ASOBO_GT_Knob_Infinite_Push">
<ANTICLOCKWISE_CODE>
(L:XMLVAR_Baro#BARO_ID#_ForcedToSTD) ! if{
#BARO_ID# (&gt;K:KOHLSMAN_DEC)
}
</ANTICLOCKWISE_CODE>
<CLOCKWISE_CODE>
(L:XMLVAR_Baro#BARO_ID#_ForcedToSTD) ! if{
#BARO_ID# (&gt;K:KOHLSMAN_INC)
}
</CLOCKWISE_CODE>
<LEFT_SINGLE_CODE>
(L:XMLVAR_Baro#BARO_ID#_ForcedToSTD) ! (&gt;L:XMLVAR_Baro#BARO_ID#_ForcedToSTD)
(L:XMLVAR_Baro#BARO_ID#_ForcedToSTD) if{
(A:KOHLSMAN SETTING MB:1, mbars) 16 * (&gt;L:XMLVAR_Baro#BARO_ID#_SavedPressure)
#BARO_ID# (&gt;K:BAROMETRIC_STD_PRESSURE)
} els{
#BARO_ID# (L:XMLVAR_Baro#BARO_ID#_SavedPressure) (&gt;K:2:KOHLSMAN_SET)
}
</LEFT_SINGLE_CODE>
<COUNT>36</COUNT>
<NORMALIZED_TIME_1>0.1</NORMALIZED_TIME_1>
<NORMALIZED_TIME_2>0.5</NORMALIZED_TIME_2>
</UseTemplate>
</Default>
</Switch>
</Case>
<Default>
<UseTemplate Name="ASOBO_GT_Knob_Infinite">
<ANTICLOCKWISE_CODE>#BARO_ID# (&gt;K:KOHLSMAN_DEC)</ANTICLOCKWISE_CODE>
<CLOCKWISE_CODE>#BARO_ID# (&gt;K:KOHLSMAN_INC)</CLOCKWISE_CODE>
<WWISE_EVENT>RMPknob</WWISE_EVENT>
<COUNT>36</COUNT>
</UseTemplate>
</Default>
</Switch>
</Template>

<Template Name="FBW_CVR_Ground_Control_Pushbutton">
<DefaultTemplateParameters>
<WWISE_EVENT_1>mpb1on</WWISE_EVENT_1>
Expand Down
34 changes: 23 additions & 11 deletions fbw-a32nx/src/systems/fmgc/src/flightphase/FlightPhaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
import { Arinc429Word, ConfirmationNode } from '@flybywiresim/fbw-sdk';
import { VerticalMode } from '@shared/autopilot';
import { FmgcFlightPhase, isAllEngineOn, isAnEngineOn, isOnGround, isReady, isSlewActive } from '@shared/flightphase';
import { EventBus, Subject } from '@microsoft/msfs-sdk';
import { ConsumerValue, EventBus, Subject } from '@microsoft/msfs-sdk';
import { NavigationEvents } from '@fmgc/navigation/Navigation';

export interface FlightPhaseManagerEvents {
/** The FMGC flight phase. */
Expand All @@ -36,19 +37,23 @@ function canInitiateDes(distanceToDestination: number): boolean {
}

export class FlightPhaseManager {
private readonly sub = this.bus.getSubscriber<NavigationEvents>();

private readonly pressureAltitude = ConsumerValue.create(this.sub.on('fms_nav_pressure_altitude'), null);

private onGroundConfirmationNode = new ConfirmationNode(30 * 1000);

private readonly activePhase = Subject.create(this.initialPhase || FmgcFlightPhase.Preflight);

private phases: { [key in FmgcFlightPhase]: Phase } = {
[FmgcFlightPhase.Preflight]: new PreFlightPhase(),
[FmgcFlightPhase.Takeoff]: new TakeOffPhase(),
[FmgcFlightPhase.Climb]: new ClimbPhase(),
[FmgcFlightPhase.Cruise]: new CruisePhase(),
[FmgcFlightPhase.Descent]: new DescentPhase(),
[FmgcFlightPhase.Approach]: new ApproachPhase(),
[FmgcFlightPhase.GoAround]: new GoAroundPhase(),
[FmgcFlightPhase.Done]: new DonePhase(),
[FmgcFlightPhase.Preflight]: new PreFlightPhase(this.pressureAltitude),
[FmgcFlightPhase.Takeoff]: new TakeOffPhase(this.pressureAltitude),
[FmgcFlightPhase.Climb]: new ClimbPhase(this.pressureAltitude),
[FmgcFlightPhase.Cruise]: new CruisePhase(this.pressureAltitude),
[FmgcFlightPhase.Descent]: new DescentPhase(this.pressureAltitude),
[FmgcFlightPhase.Approach]: new ApproachPhase(this.pressureAltitude),
[FmgcFlightPhase.GoAround]: new GoAroundPhase(this.pressureAltitude),
[FmgcFlightPhase.Done]: new DonePhase(this.pressureAltitude),
};

private phaseChangeListeners: Array<(prev: FmgcFlightPhase, next: FmgcFlightPhase) => void> = [];
Expand Down Expand Up @@ -146,12 +151,19 @@ export class FlightPhaseManager {
}

handleNewCruiseAltitudeEntered(newCruiseFlightLevel: number): void {
const currentFlightLevel = Math.round(SimVar.GetSimVarValue('INDICATED ALTITUDE:3', 'feet') / 100);
const pressureAltitude = this.pressureAltitude.get();
const currentFlightLevel = pressureAltitude === null ? null : Math.round(pressureAltitude / 100);

if (this.phase === FmgcFlightPhase.Approach) {
this.changePhase(FmgcFlightPhase.Climb);
} else if (currentFlightLevel < newCruiseFlightLevel && this.phase === FmgcFlightPhase.Descent) {
} else if (
currentFlightLevel !== null &&
currentFlightLevel < newCruiseFlightLevel &&
this.phase === FmgcFlightPhase.Descent
) {
this.changePhase(FmgcFlightPhase.Climb);
} else if (
currentFlightLevel !== null &&
currentFlightLevel > newCruiseFlightLevel &&
(this.phase === FmgcFlightPhase.Climb || this.phase === FmgcFlightPhase.Descent)
) {
Expand Down
Loading
Loading