Skip to content

Commit

Permalink
fix(a380x/fcu): pre-sel not recognising baro unit change (#9164)
Browse files Browse the repository at this point in the history
Co-authored-by: Saschl <[email protected]>
Co-authored-by: alepouna <[email protected]>
  • Loading branch information
3 people committed Nov 1, 2024
1 parent 6ed7487 commit 73562a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
## 0.13.0

1. [GENERAL] Fixed issue in C++ WASM Framework that caused performance degradation in some WASM modules - @frankkopp (Frank Kopp)
1. [FCU] Fixed auto-initialisation of baro unit - @tracernz (Mike)
1. [A380X/FCU] Fixed auto-initialisation of baro unit - @tracernz (Mike)
1. [A380X/FCU] Fix baro-preselect not recognising baro unit changes - @tracernz (Mike)

## 0.12.0

Expand Down
19 changes: 17 additions & 2 deletions fbw-a380x/src/systems/instruments/src/FCU/Managers/BaroManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { EventBus, HEvent, Instrument, KeyEventManager, Subject, UnitType } from '@microsoft/msfs-sdk';
import { EventBus, HEvent, Instrument, KeyEventManager, MathUtils, Subject, UnitType } from '@microsoft/msfs-sdk';

export type BaroMode = ReturnType<typeof Simplane.getPressureSelectedMode>;
export type BaroUnit = ReturnType<typeof Simplane.getPressureSelectedUnits>;
Expand Down Expand Up @@ -56,7 +56,7 @@ export class BaroManager implements Instrument {
this.publisher.pub(this.modeEventKey, v);
}, true);

this.unit.sub((v) => this.publisher.pub(this.unitEventKey, v), true);
this.unit.sub(this.onBaroUnitChanged.bind(this), true);

this.correction.sub((v) => this.publisher.pub(this.correctionEventKey, v));

Expand All @@ -75,6 +75,21 @@ export class BaroManager implements Instrument {
}
}

private onBaroUnitChanged(newUnit: BaroUnit): void {
this.publisher.pub(this.unitEventKey, newUnit);

if (this.mode.get() === 'STD') {
// we need to change the unit of the pre-selected value
const correction = this.correction.get();
const isCorrectionInHg = correction < 100;
if (newUnit === 'inches of mercury' && !isCorrectionInHg) {
this.correction.set(MathUtils.round(UnitType.IN_HG.convertFrom(correction, UnitType.HPA), 0.01));
} else if (newUnit === 'millibar' && isCorrectionInHg) {
this.correction.set(MathUtils.round(UnitType.HPA.convertFrom(correction, UnitType.IN_HG), 1));
}
}
}

private onHEvent(event: string): void {
if (this.mode.get() !== 'STD') {
return;
Expand Down

0 comments on commit 73562a2

Please sign in to comment.