Skip to content

Commit

Permalink
add extra-host module for airframe check, remove airframe check from efb
Browse files Browse the repository at this point in the history
  • Loading branch information
Revyn112 committed Feb 19, 2024
1 parent 92c4131 commit 1e3f0f0
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ size_mm = 1430,1000
pixel_size = 1430,1000
texture = $EFB

htmlgauge00 = A32NX/EFB/efb.html?Airframe=A320_251N, 0,0,1430,1000
htmlgauge00 = A32NX/EFB/efb.html, 0,0,1430,1000

[VCockpit17]
size_mm = 0,0
Expand All @@ -149,7 +149,7 @@ pixel_size = 0,0
texture = NO_TEXTURE
background_color = 0,0,0

htmlgauge00 = A32NX/ExtrasHost/extras-host.html,0,0,1,1
htmlgauge00 = A32NX/ExtrasHost/extras-host.html?Airframe=A320_251N,0,0,1,1

[VPainting01]
size_mm = 2048,512
Expand Down
7 changes: 7 additions & 0 deletions fbw-a32nx/src/systems/extras-host/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ExtrasSimVarPublisher } from 'extras-host/modules/common/ExtrasSimVarPu
import { PushbuttonCheck } from 'extras-host/modules/pushbutton_check/PushbuttonCheck';
import { KeyInterceptor } from './modules/key_interceptor/KeyInterceptor';
import { VersionCheck } from './modules/version_check/VersionCheck';
import { AirframeCheck } from './modules/airframe_check/AirframeCheck';

/**
* This is the main class for the extras-host instrument.
Expand Down Expand Up @@ -40,6 +41,8 @@ class ExtrasHost extends BaseInstrument {

private readonly keyInterceptor: KeyInterceptor;

private readonly airframeCheck: AirframeCheck;

/**
* "mainmenu" = 0
* "loading" = 1
Expand All @@ -60,6 +63,7 @@ class ExtrasHost extends BaseInstrument {
this.pushbuttonCheck = new PushbuttonCheck(this.bus, this.notificationManager);
this.versionCheck = new VersionCheck(this.bus);
this.keyInterceptor = new KeyInterceptor(this.bus, this.notificationManager);
this.airframeCheck = new AirframeCheck(this.bus);

console.log('A32NX_EXTRASHOST: Created');
}
Expand All @@ -82,6 +86,7 @@ class ExtrasHost extends BaseInstrument {
this.pushbuttonCheck.connectedCallback();
this.versionCheck.connectedCallback();
this.keyInterceptor.connectedCallback();
this.airframeCheck.connectedCallback();
}

public Update(): void {
Expand All @@ -94,6 +99,7 @@ class ExtrasHost extends BaseInstrument {
this.versionCheck.startPublish();
this.keyInterceptor.startPublish();
this.simVarPublisher.startPublish();
this.airframeCheck.startPublish();
}
this.gameState = gs;
} else {
Expand All @@ -102,6 +108,7 @@ class ExtrasHost extends BaseInstrument {

this.versionCheck.update();
this.keyInterceptor.update();
this.airframeCheck.update();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { AircraftType } from '@flybywiresim/fbw-sdk';
import { EventBus } from '@microsoft/msfs-sdk';

/**
* This class is used to check the airframe of the aircraft and set the LVar
*/
export class AirframeCheck {
constructor(private readonly bus: EventBus) {
console.log('AirframeCheck: Created');
}

public connectedCallback(): void {
// empty
}

public startPublish(): void {
console.log('AirframeCheck: startPublish()');

const airframe = new URL(document.querySelectorAll('vcockpit-panel > *')[0].getAttribute('url')).searchParams.get('Airframe');
let aircraftType: AircraftType;

switch (airframe) {
case 'A380_842':
aircraftType = AircraftType.A380_842;
break;
case 'A320_251N':
aircraftType = AircraftType.A320_251N;
break;
default:
aircraftType = AircraftType.Unknown;
break;
}

SimVar.SetSimVarValue('L:A32NX_AIRCRAFT_TYPE', 'enum', aircraftType);
console.log(`AirframeCheck: set ${aircraftType}`);
}

public update(): void {
// empty
}
}
2 changes: 0 additions & 2 deletions fbw-a32nx/src/systems/fmgc/src/components/ReadySignal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AircraftType } from '@flybywiresim/fbw-sdk';
import { FlightPlanManager } from '@fmgc/wtsdk';
import { FmgcComponent } from './FmgcComponent';

Expand All @@ -17,7 +16,6 @@ export class ReadySignal implements FmgcComponent {
&& SimVar.GetSimVarValue('L:A32NX_IS_READY', 'number') !== 1) {
// set ready signal that JS code is initialized and flight is actually started
// -> user pressed 'READY TO FLY' button
SimVar.SetSimVarValue('L:A32NX_AIRCRAFT_TYPE', 'enum', AircraftType.A320_251N);
SimVar.SetSimVarValue('L:A32NX_IS_READY', 'number', 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React, { useState } from 'react';
import { IconPlane } from '@tabler/icons';
import { CloudArrowDown } from 'react-bootstrap-icons';
import { AircraftType, usePersistentProperty } from '@flybywiresim/fbw-sdk';
import { AircraftType, usePersistentProperty, useSimVar } from '@flybywiresim/fbw-sdk';
import { toast } from 'react-toastify';
import { fetchSimbriefDataAction, isSimbriefDataLoaded } from '../../Store/features/simBrief';
import { useAppSelector, useAppDispatch } from '../../Store/store';
Expand Down Expand Up @@ -71,7 +71,7 @@ export const FlightWidget = () => {
const [simbriefDataPending, setSimbriefDataPending] = useState(false);
const [navigraphUsername] = usePersistentProperty('NAVIGRAPH_USERNAME');
const [overrideSimBriefUserID] = usePersistentProperty('CONFIG_OVERRIDE_SIMBRIEF_USERID');
const [airframe] = useState(getAirframeType());
const [airframe] = useSimVar('L:A32NX_AIRCRAFT_TYPE', 'Enum');

const {
schedIn,
Expand Down
20 changes: 1 addition & 19 deletions fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import React, { useEffect, useState } from 'react';
import { useSimVar, useInterval, useInteractionEvent, usePersistentNumberProperty, usePersistentProperty, NavigraphClient, AircraftType } from '@flybywiresim/fbw-sdk';
import { useSimVar, useInterval, useInteractionEvent, usePersistentNumberProperty, usePersistentProperty, NavigraphClient } from '@flybywiresim/fbw-sdk';
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
import { Battery } from 'react-bootstrap-icons';
import { toast, ToastContainer } from 'react-toastify';
Expand Down Expand Up @@ -72,24 +72,6 @@ interface BatteryStatus {

export const usePower = () => React.useContext(PowerContext);

// this returns either `A380_842` or `A320_251N` depending on the aircraft
export function getAirframeType(): AircraftType {
const airframe = new URL(document.querySelectorAll('vcockpit-panel > *')[0].getAttribute('url')).searchParams.get('Airframe');
let airframeType: AircraftType;

switch (airframe) {
case 'A380_842':
airframeType = AircraftType.A380_842;
break;
case 'A320_251N':
default:
airframeType = AircraftType.A320_251N;
break;
}

return airframeType;
}

const Efb = () => {
const [powerState, setPowerState] = useState<PowerStates>(PowerStates.SHUTOFF);
const [absoluteTime] = useSimVar('E:ABSOLUTE TIME', 'seconds', 5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/* eslint-disable max-len */
import React, { useState } from 'react';
import { AircraftType, Units, usePersistentProperty, useSimVar } from '@flybywiresim/fbw-sdk';
import { getAirframeType } from '../../../Efb';
import { A320Payload } from './A320_251N/A320Payload';
import { A380Payload } from './A380_842/A380Payload';
import { useAppSelector } from '../../../Store/store';
Expand All @@ -26,8 +25,9 @@ export const Payload = () => {
const simbriefDataLoaded = isSimbriefDataLoaded();

const [massUnitForDisplay] = useState(Units.usingMetric ? 'KGS' : 'LBS');
const [airframe] = useSimVar('L:A32NX_AIRCRAFT_TYPE', 'Enum');

switch (getAirframeType()) {
switch (airframe) {
case AircraftType.A380_842:
return (
<A380Payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
setGpuButtonState,
setJetWayButtonState,
} from '../../../../Store/features/groundServicePage';
// import { getAirframeType } from '../../../../Efb';

interface ServiceButtonWrapperProps {
className?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

/* eslint-disable no-console */
import React, { useState } from 'react';
import { AircraftType } from '@flybywiresim/fbw-sdk';
import { AircraftType, useSimVar } from '@flybywiresim/fbw-sdk';
import { A380Services } from './Services/A380_842/A380Services';
import { A320Services } from './Services/A320_251N/A320Services';
import { getAirframeType } from '../../Efb';

export const ServicesPage = () => {
const [airframe] = useState(getAirframeType());
const [airframe] = useSimVar('L:A32NX_AIRCRAFT_TYPE', 'Enum')

switch (airframe) {
case AircraftType.A380_842:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import React, { useEffect, useState } from 'react';
import { AircraftType, usePersistentNumberProperty, useSimVar } from '@flybywiresim/fbw-sdk';
import { ExclamationCircleFill } from 'react-bootstrap-icons';
import { getAirframeType } from 'instruments/src/EFB/Efb';
import { t } from '../../translation';
import { Toggle } from '../../UtilComponents/Form/Toggle';
import { SelectGroup, SelectItem, VerticalSelectGroup } from '../../UtilComponents/Form/Select';
Expand Down Expand Up @@ -36,7 +35,7 @@ interface ThrottleConfigProps {
* @constructor
*/
export const ThrottleConfig = ({ isShown, onClose }: ThrottleConfigProps) => {
const [airframe] = useState(getAirframeType());
const [airframe] = useSimVar('L:A32NX_AIRCRAFT_TYPE', 'Enum');

const [axisNum, setAxisNum] = usePersistentNumberProperty('THROTTLE_AXIS', airframe === AircraftType.A380_842 ? 4 : 2);
// this makes sure that the axis number is set to 2 when the A320 is selected when previously the A380 with 4 axis was used
Expand Down Expand Up @@ -64,7 +63,7 @@ export const ThrottleConfig = ({ isShown, onClose }: ThrottleConfigProps) => {
const { showModal } = useModals();

// the number of throttles that are used in the aircraft (2 or 4)
const numberOfThrottles = getAirframeType() === AircraftType.A380_842 ? 4 : 2;
const numberOfThrottles = airframe === AircraftType.A380_842 ? 4 : 2;

// this makes sure that the axis number is set to 2 when the A320 is selected when previously the A380 with 4 axis was used
if (airframe !== AircraftType.A380_842 && axisNum === 4) {
Expand Down
6 changes: 4 additions & 2 deletions fbw-common/src/systems/shared/src/aircraftTypeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: GPL-3.0

export enum AircraftType {
A320_251N = 0,
A380_842 = 1
Unknown = 0,
A320_251N = 1,
A380_842 = 2
}

/**
Expand All @@ -21,6 +22,7 @@ export function getAircraftType(): string {
case AircraftType.A380_842:
aircraft = 'a380x';
break;
case AircraftType.Unknown:
default:
aircraft = 'other';
}
Expand Down

0 comments on commit 1e3f0f0

Please sign in to comment.