Skip to content

Commit

Permalink
refactor: move auto baro unit to extras host and enable on a380x (#9654)
Browse files Browse the repository at this point in the history
* refactor: move auto baro to extras host

* feat(a380x): auto baro unit selection

* fix(efb): match default with others

* docs: changelog
  • Loading branch information
tracernz authored and Saschl committed Jan 2, 2025
1 parent 62ad366 commit 3f8786b
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@

<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_Speeds.js"></script>
<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_SoundManager.js"></script>
<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_BaroSelector.js"></script>
<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_Refuel.js"></script>
<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_DMC.js"></script>
<script type="text/html" import-script="/Pages/A32NX_Core/A32NX_LocalVarUpdater.js"></script>
Expand Down
8 changes: 8 additions & 0 deletions fbw-a32nx/src/systems/extras-host/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk';
import {
BaroUnitSelector,
ExtrasSimVarPublisher,
FlightDeckBounds,
GPUManagement,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -156,6 +162,8 @@ class ExtrasHost extends BaseInstrument {
this.aircraftSync.connectedCallback();

this.backplane.init();

this.baroUnitSelector.performSelection();
}

public parseXMLConfig(): void {
Expand Down
10 changes: 9 additions & 1 deletion fbw-a380x/src/systems/extras-host/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -144,6 +150,8 @@ class ExtrasHost extends BaseInstrument {
this.aircraftSync.connectedCallback();

this.backplane.init();

this.baroUnitSelector.performSelection();
}

public parseXMLConfig(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface WeatherWidgetProps {
}

export const WeatherWidget: FC<WeatherWidgetProps> = ({ 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');
Expand Down
46 changes: 46 additions & 0 deletions fbw-common/src/systems/shared/src/extras/BaroUnitSelector.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions fbw-common/src/systems/shared/src/extras/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BaroUnitSelector';
1 change: 1 addition & 0 deletions fbw-common/src/systems/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 3f8786b

Please sign in to comment.