diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md
index ed5143b4776..015fa7ec4b3 100644
--- a/.github/CHANGELOG.md
+++ b/.github/CHANGELOG.md
@@ -109,6 +109,7 @@
1. [A380X/FLIGHT MODEL] Fix pitchup and unrecoverable stall - - @donstim (donbikes#4084)
1. [ATC/TCAS] Fixed TCAS failure on baro corrected altitude going invalid - @tracernz (Mike)
1. [ATC/TCAS] Fixed TCAS slant range computation - @tracernz (Mike)
+1. [A380X] Add baro unit (hPa/in.Hg) auto selection - @tracernz (Mike)
## 0.12.0
diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_BaroSelector.js b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_BaroSelector.js
deleted file mode 100644
index 246698a4d22..00000000000
--- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_BaroSelector.js
+++ /dev/null
@@ -1,45 +0,0 @@
-const IN_HG_REGIONS = ["K", "C", "M", "P", "RJ", "RO", "TI", "TJ"];
-
-class A32NX_BaroSelector {
- init() {
- const configInitBaroUnit = NXDataStore.get("CONFIG_INIT_BARO_UNIT", "IN HG");
- if (configInitBaroUnit != "AUTO") {
- this.setBaroSelector(configInitBaroUnit == "HPA");
- } else {
- const interval = setInterval(() => {
- const inGame = window.parent && window.parent.document.body.getAttribute("gamestate") === "ingame";
- if (inGame) {
- clearInterval(interval);
- this.autoSetBaroUnit();
- }
- }, 100);
- }
- }
- update(_deltaTime, _core) {
- // noop
- }
- setBaroSelector(value) {
- SimVar.SetSimVarValue("L:A32NX_FCU_EFIS_L_BARO_IS_INHG", "bool", !value);
- SimVar.SetSimVarValue("L:A32NX_FCU_EFIS_R_BARO_IS_INHG", "bool", !value);
- this.baroSelectionCompleted = true;
- }
- /** @private */
- async autoSetBaroUnit() {
- const sessionId = await Coherent.call("START_NEAREST_SEARCH_SESSION", 1 /* AIRPORT */);
- const handler = Coherent.on("NearestSearchCompleted", (result) => {
- if (result.sessionId === sessionId) {
- handler.clear();
- const useInHg = result.added.length > 0 && (
- IN_HG_REGIONS.includes(result.added[0].charAt(7))
- || IN_HG_REGIONS.includes(result.added[0].substring(7, 9))
- );
- this.setBaroSelector(!useInHg);
- }
- });
-
- const lat = SimVar.GetSimVarValue("PLANE LATITUDE", "degree latitude");
- const lon = SimVar.GetSimVarValue("PLANE LONGITUDE", "degree longitude");
-
- Coherent.call("SEARCH_NEAREST", sessionId, lat, lon, 50000, 1);
- }
-}
diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_Core.js b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_Core.js
index 052b6ce7bb7..2378ceacdf6 100644
--- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_Core.js
+++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_Core.js
@@ -3,11 +3,6 @@ const ENABLE_TOTAL_UPDATE_TIME_TRACING = false;
class A32NX_Core {
constructor() {
this.modules = [
- {
- name: 'BaroSelector',
- module: new A32NX_BaroSelector(),
- updateInterval: 300,
- },
{
name: 'Refuel',
module: new A32NX_Refuel(),
diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/Airliners/FlyByWire_A320_Neo/CDU/A320_Neo_CDU.html b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/Airliners/FlyByWire_A320_Neo/CDU/A320_Neo_CDU.html
index 47a12964387..5c05322c049 100644
--- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/Airliners/FlyByWire_A320_Neo/CDU/A320_Neo_CDU.html
+++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/Airliners/FlyByWire_A320_Neo/CDU/A320_Neo_CDU.html
@@ -161,7 +161,6 @@
-
diff --git a/fbw-a32nx/src/systems/extras-host/index.ts b/fbw-a32nx/src/systems/extras-host/index.ts
index ef203f29900..02592417602 100644
--- a/fbw-a32nx/src/systems/extras-host/index.ts
+++ b/fbw-a32nx/src/systems/extras-host/index.ts
@@ -8,6 +8,7 @@
import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk';
import {
+ BaroUnitSelector,
ExtrasSimVarPublisher,
FlightDeckBounds,
GPUManagement,
@@ -93,6 +94,11 @@ class ExtrasHost extends BaseInstrument {
private readonly lightSync: LightSync = new LightSync(this.bus);
+ private readonly baroUnitSelector = new BaroUnitSelector((isHpa) => {
+ SimVar.SetSimVarValue('L:A32NX_FCU_EFIS_L_BARO_IS_INHG', 'bool', !isHpa);
+ SimVar.SetSimVarValue('L:A32NX_FCU_EFIS_R_BARO_IS_INHG', 'bool', !isHpa);
+ });
+
/**
* "mainmenu" = 0
* "loading" = 1
@@ -156,6 +162,8 @@ class ExtrasHost extends BaseInstrument {
this.aircraftSync.connectedCallback();
this.backplane.init();
+
+ this.baroUnitSelector.performSelection();
}
public parseXMLConfig(): void {
diff --git a/fbw-a380x/src/systems/extras-host/index.ts b/fbw-a380x/src/systems/extras-host/index.ts
index 178e7003756..910b1f6f63e 100644
--- a/fbw-a380x/src/systems/extras-host/index.ts
+++ b/fbw-a380x/src/systems/extras-host/index.ts
@@ -1,7 +1,7 @@
// Copyright (c) 2022 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0
-import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk';
+import { Clock, EventBus, HEventPublisher, InstrumentBackplane, SimVarValueType } from '@microsoft/msfs-sdk';
import {
FlightDeckBounds,
NotificationManager,
@@ -12,6 +12,7 @@ import {
MsfsFlightModelPublisher,
MsfsMiscPublisher,
GroundSupportPublisher,
+ BaroUnitSelector,
} from '@flybywiresim/fbw-sdk';
import { PushbuttonCheck } from 'extras-host/modules/pushbutton_check/PushbuttonCheck';
import { KeyInterceptor } from './modules/key_interceptor/KeyInterceptor';
@@ -86,6 +87,11 @@ class ExtrasHost extends BaseInstrument {
private readonly lightSync: LightSync = new LightSync(this.bus);
+ private readonly baroUnitSelector = new BaroUnitSelector((isHpa) => {
+ SimVar.SetSimVarValue('L:XMLVAR_Baro_Selector_HPA_1', SimVarValueType.Bool, isHpa);
+ SimVar.SetSimVarValue('L:XMLVAR_Baro_Selector_HPA_2', SimVarValueType.Bool, isHpa);
+ });
+
/**
* "mainmenu" = 0
* "loading" = 1
@@ -144,6 +150,8 @@ class ExtrasHost extends BaseInstrument {
this.aircraftSync.connectedCallback();
this.backplane.init();
+
+ this.baroUnitSelector.performSelection();
}
public parseXMLConfig(): void {
diff --git a/fbw-common/src/systems/instruments/src/EFB/Dashboard/Widgets/WeatherWidget.tsx b/fbw-common/src/systems/instruments/src/EFB/Dashboard/Widgets/WeatherWidget.tsx
index 4ee1cd481cf..726879678b2 100644
--- a/fbw-common/src/systems/instruments/src/EFB/Dashboard/Widgets/WeatherWidget.tsx
+++ b/fbw-common/src/systems/instruments/src/EFB/Dashboard/Widgets/WeatherWidget.tsx
@@ -78,7 +78,7 @@ interface WeatherWidgetProps {
}
export const WeatherWidget: FC = ({ name, simbriefIcao, userIcao }) => {
- const [baroType] = usePersistentProperty('CONFIG_INIT_BARO_UNIT', 'HPA');
+ const [baroType] = usePersistentProperty('CONFIG_INIT_BARO_UNIT', 'AUTO');
const dispatch = useAppDispatch();
const [simbriefIcaoAtLoading, setSimbriefIcaoAtLoading] = useState(simbriefIcao);
const [metarSource] = usePersistentProperty('CONFIG_METAR_SRC', 'MSFS');
diff --git a/fbw-common/src/systems/shared/src/extras/BaroUnitSelector.ts b/fbw-common/src/systems/shared/src/extras/BaroUnitSelector.ts
new file mode 100644
index 00000000000..5d9016a96b1
--- /dev/null
+++ b/fbw-common/src/systems/shared/src/extras/BaroUnitSelector.ts
@@ -0,0 +1,46 @@
+import { NXDataStore } from '@flybywiresim/fbw-sdk';
+import { GameStateProvider, Wait } from '@microsoft/msfs-sdk';
+import { NearestSearchType } from '../../../navdata/client/backends/Msfs/FsTypes';
+
+export class BaroUnitSelector {
+ private static readonly IN_HG_REGIONS = ['K', 'C', 'M', 'P', 'RJ', 'RO', 'TI', 'TJ'];
+
+ private facilityListener?: ViewListener.ViewListener;
+
+ constructor(private readonly setBaroSelector: (isHpa: boolean) => void) {}
+
+ public performSelection(): void {
+ const configInitBaroUnit = NXDataStore.get('CONFIG_INIT_BARO_UNIT', 'AUTO');
+ if (configInitBaroUnit !== 'AUTO') {
+ this.setBaroSelector(configInitBaroUnit == 'HPA');
+ } else if (this.facilityListener) {
+ this.autoSetBaroUnit();
+ } else {
+ RegisterViewListener('JS_LISTENER_FACILITY', () => this.autoSetBaroUnit(), true);
+ }
+ }
+
+ /** @private */
+ private async autoSetBaroUnit() {
+ await Wait.awaitSubscribable(GameStateProvider.get(), (v) => v === GameState.ingame, true);
+
+ const sessionId = await Coherent.call('START_NEAREST_SEARCH_SESSION', NearestSearchType.Airport);
+ const handler = Coherent.on('NearestSearchCompleted', (result: { sessionId: number; added: string[] }) => {
+ if (result.sessionId === sessionId) {
+ handler.clear();
+
+ const useInHg =
+ result.added.length > 0 &&
+ (BaroUnitSelector.IN_HG_REGIONS.includes(result.added[0].charAt(7)) ||
+ BaroUnitSelector.IN_HG_REGIONS.includes(result.added[0].substring(7, 9)));
+
+ this.setBaroSelector(!useInHg);
+ }
+ });
+
+ const lat = SimVar.GetSimVarValue('PLANE LATITUDE', 'degree latitude');
+ const lon = SimVar.GetSimVarValue('PLANE LONGITUDE', 'degree longitude');
+
+ Coherent.call('SEARCH_NEAREST', sessionId, lat, lon, 50000, 1);
+ }
+}
diff --git a/fbw-common/src/systems/shared/src/extras/index.ts b/fbw-common/src/systems/shared/src/extras/index.ts
new file mode 100644
index 00000000000..3f9ae8a5e10
--- /dev/null
+++ b/fbw-common/src/systems/shared/src/extras/index.ts
@@ -0,0 +1 @@
+export * from './BaroUnitSelector';
diff --git a/fbw-common/src/systems/shared/src/index.ts b/fbw-common/src/systems/shared/src/index.ts
index 22439dfe5b1..72cf0ec84ba 100644
--- a/fbw-common/src/systems/shared/src/index.ts
+++ b/fbw-common/src/systems/shared/src/index.ts
@@ -8,6 +8,7 @@ export * from './ArincEventBus';
export * from './ArincEventBusSubscriber';
export * from './checklists';
export * from './Constants';
+export * from './extras';
export * from './FbwAircraftSentryClient';
export * from './FmMessages';
export * from './GenericDataListenerSync';
diff --git a/igniter.config.mjs b/igniter.config.mjs
index 56c9701c654..4cbd5342d6d 100644
--- a/igniter.config.mjs
+++ b/igniter.config.mjs
@@ -50,6 +50,7 @@ export default new TaskOfTasks('all', [
new ExecTask('extras-host', 'npm run build-a32nx:extras-host', [
'fbw-a32nx/src/systems/extras-host',
'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/ExtrasHost',
+ 'fbw-common/src/systems/shared/src/extras',
]),
new ExecTask('failures', 'npm run build-a32nx:failures', [
'fbw-a32nx/src/systems/failures',
@@ -194,6 +195,7 @@ export default new TaskOfTasks('all', [
new ExecTask('extras-host', 'npm run build-a380x:extras-host', [
'fbw-a380x/src/systems/extras-host',
'fbw-a380x/out/flybywire-aircraft-a380-842/html_ui/Pages/VCockpit/Instruments/A380X/ExtrasHost',
+ 'fbw-common/src/systems/shared/src/extras',
]),
new ExecTask('systems-host', 'npm run build-a380x:systems-host', [
'fbw-a380x/src/systems/systems-host',