From 73562a2f6bd9a67ad790367b835803edea7ab74a Mon Sep 17 00:00:00 2001 From: Michael Corcoran Date: Wed, 30 Oct 2024 04:24:06 +1300 Subject: [PATCH] fix(a380x/fcu): pre-sel not recognising baro unit change (#9164) Co-authored-by: Saschl <19493808+Saschl@users.noreply.github.com> Co-authored-by: alepouna <98479040+alepouna@users.noreply.github.com> --- .github/CHANGELOG.md | 3 ++- .../src/FCU/Managers/BaroManager.ts | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index de85370abac..d8fb169d9f8 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -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 diff --git a/fbw-a380x/src/systems/instruments/src/FCU/Managers/BaroManager.ts b/fbw-a380x/src/systems/instruments/src/FCU/Managers/BaroManager.ts index abf29d0f034..5ffff80911d 100644 --- a/fbw-a380x/src/systems/instruments/src/FCU/Managers/BaroManager.ts +++ b/fbw-a380x/src/systems/instruments/src/FCU/Managers/BaroManager.ts @@ -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; export type BaroUnit = ReturnType; @@ -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)); @@ -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;