Skip to content

Commit

Permalink
Implement OANS performance mode: Auto-hide when inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
flogross89 committed Jan 29, 2025
1 parent db8dbd4 commit 5c7e902
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 16 deletions.
1 change: 1 addition & 0 deletions fbw-a32nx/src/systems/instruments/src/EFB/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ render(
registrationDecal: true,
wheelChocks: true,
cabinLighting: false,
oansPerformanceMode: false,
},
throttle: {
numberOfAircraftThrottles: 2,
Expand Down
1 change: 1 addition & 0 deletions fbw-a380x/src/systems/instruments/src/EFB/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ render(
registrationDecal: false, // TODO FIXME: Enable when dynamic registration decal is completed
wheelChocks: false,
cabinLighting: true,
oansPerformanceMode: true,
},
throttle: {
numberOfAircraftThrottles: 4,
Expand Down
73 changes: 62 additions & 11 deletions fbw-a380x/src/systems/instruments/src/ND/OansControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
FSComponent,
MapSubject,
MappedSubject,
MappedSubscribable,
SimVarValueType,
Subject,
Subscribable,
Expand Down Expand Up @@ -44,6 +43,7 @@ import {
FmsOansData,
MathUtils,
NXDataStore,
NXLogicConfirmNode,
Runway,
} from '@flybywiresim/fbw-sdk';

Expand Down Expand Up @@ -73,7 +73,7 @@ export interface OansProps extends ComponentProps {
const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];

export class OansControlPanel extends DisplayComponent<OansProps> {
private readonly subs: (Subscription | MappedSubscribable<any>)[] = [];
private readonly subs: Subscription[] = [];

private readonly sub = this.props.bus.getSubscriber<
ClockEvents & FmsOansData & AdirsSimVars & NDSimvars & BtvData & OansControlEvents & ResetPanelSimvars
Expand All @@ -84,6 +84,12 @@ export class OansControlPanel extends DisplayComponent<OansProps> {

private readonly oansResetPulled = ConsumerSubject.create(this.sub.on('a380x_reset_panel_arpt_nav'), false);

private oansPerformanceModeSettingSub = () => {};
private readonly oansPerformanceMode = Subject.create(false);
private showOans = false;
private lastUpdateTime: number | null = null;
private readonly oansPerformanceModeAndMovedOutOfZoomRange = new NXLogicConfirmNode(60, true);

private readonly oansAvailable = MappedSubject.create(
([ng, reset]) => ng && !reset,
this.navigraphAvailable,
Expand Down Expand Up @@ -294,13 +300,17 @@ export class OansControlPanel extends DisplayComponent<OansProps> {
this.subs.push(
this.oansResetPulled.sub((v) => {
if (v) {
this.props.bus.getPublisher<OansControlEvents>().pub('oans_display_airport', '', true);
this.store.loadedAirport.set(null);
this.store.isAirportSelectionPending.set(false);
this.unloadCurrentAirport();
}
}, true),
);

this.oansPerformanceModeSettingSub = NXDataStore.getAndSubscribe(
'CONFIG_A380X_OANS_PERFORMANCE_MODE',
(_, v) => this.oansPerformanceMode.set(v === '1'),
'0',
);

this.subs.push(
this.fmsDataStore.landingRunway.sub(async (it) => {
// Set control panel display
Expand All @@ -314,11 +324,38 @@ export class OansControlPanel extends DisplayComponent<OansProps> {
}),
);

this.subs.push(
this.sub
.on('nd_show_oans')
.whenChanged()
.handle((showOans) => {
if (this.props.side === showOans.side) {
this.showOans = showOans.show;
}
}),
);

this.subs.push(
this.sub
.on('realTime')
.atFrequency(1)
.handle(() => this.autoLoadAirport()),
.atFrequency(0.5)
.handle((time) => {
this.oansPerformanceModeAndMovedOutOfZoomRange.write(
this.oansPerformanceMode.get() && !this.showOans,
this.lastUpdateTime === null ? 0 : time - this.lastUpdateTime,
);
this.props.bus.getPublisher<OansControlEvents>().pub(
'oans_performance_mode_hide',
{
side: this.props.side,
hide: this.oansPerformanceModeAndMovedOutOfZoomRange.read(),
},
true,
);
this.autoLoadAirport();

this.lastUpdateTime = time;
}),
);

this.subs.push(
Expand Down Expand Up @@ -566,15 +603,21 @@ export class OansControlPanel extends DisplayComponent<OansProps> {
}
}

private autoLoadAirport() {
// If we don't have ppos, do not try to auto load
if (this.presentPosNotAvailable.get()) {
return;
private unloadCurrentAirport() {
if (this.store.loadedAirport.get()) {
this.props.bus.getPublisher<OansControlEvents>().pub('oans_display_airport', '', true);
this.store.loadedAirport.set(null);
this.store.isAirportSelectionPending.set(false);
}
}

private autoLoadAirport() {
// If we don't have ppos or airport unloaded due to performance reasons, do not try to auto load
// If airport has been manually selected, do not auto load.
// FIXME reset manualAirportSelection after a while, to enable auto-load for destination even if departure was selected manually
if (
this.presentPosNotAvailable.get() ||
this.oansPerformanceModeAndMovedOutOfZoomRange.read() ||
this.manualAirportSelection === true ||
this.store.loadedAirport.get() !== this.store.selectedAirport.get() ||
this.store.airports.length === 0 ||
Expand Down Expand Up @@ -645,6 +688,14 @@ export class OansControlPanel extends DisplayComponent<OansProps> {
}
}

destroy(): void {
for (const s of this.subs) {
s.destroy();
}
this.oansPerformanceModeSettingSub();
super.destroy();
}

render(): VNode {
return (
<>
Expand Down
2 changes: 2 additions & 0 deletions fbw-common/src/systems/instruments/src/EFB/AircraftContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface SimOptions {
registrationDecal: boolean;
wheelChocks: boolean;
cabinLighting: boolean;
oansPerformanceMode: boolean;
}

interface ThrottleOptions {
Expand Down Expand Up @@ -102,6 +103,7 @@ export const AircraftContext = createContext<AircraftEfbContext>({
registrationDecal: false,
wheelChocks: false,
cabinLighting: false,
oansPerformanceMode: false,
},
throttle: {
numberOfAircraftThrottles: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@
"Left": "Left",
"LoadOnly": "Load Only",
"None": "None",
"OansPerformanceMode": "OANS Performance Mode (Un-Load Airport Map When Not Used)",
"Off": "Off",
"PilotSeat": "Pilot Seat for Control",
"Right": "Right",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const SimOptionsPage = () => {
const [cabinManualBrightness, setCabinManualBrightness] = usePersistentNumberProperty('CABIN_MANUAL_BRIGHTNESS', 0);
const [pilotSeat, setPilotSeat] = usePersistentProperty('CONFIG_PILOT_SEAT', DefaultPilotSeatConfig);

const [oansPerformanceMode, setOansPerformanceMode] = usePersistentNumberProperty(
'CONFIG_A380X_OANS_PERFORMANCE_MODE',
0,
);

const defaultBaroButtons: ButtonType[] = [
{ name: t('Settings.SimOptions.Auto'), setting: 'AUTO' },
{ name: t('Settings.SimOptions.inHg'), setting: 'IN HG' },
Expand Down Expand Up @@ -281,6 +286,12 @@ export const SimOptionsPage = () => {
)}
</SettingGroup>
)}

{aircraftContext.settingsPages.sim.oansPerformanceMode && (
<SettingItem name={t('Settings.SimOptions.OansPerformanceMode')}>
<Toggle value={!!oansPerformanceMode} onToggle={(value) => setOansPerformanceMode(value ? 1 : 0)} />
</SettingItem>
)}
</SettingsPage>
)}
<ThrottleConfig isShown={showThrottleSettings} onClose={() => setShowThrottleSettings(false)} />
Expand Down
38 changes: 33 additions & 5 deletions fbw-common/src/systems/instruments/src/OANC/Oanc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ export class Oanc<T extends number> extends DisplayComponent<OancProps<T>> {
this.pleaseWaitFlagVisible,
);

private readonly oansPerformanceModeHide = Subject.create(false);

public getZoomLevelInverseScale() {
const multiplier = this.overlayNDModeSub.get() === EfisNdMode.ROSE_NAV ? 0.5 : 1;

Expand Down Expand Up @@ -453,9 +455,30 @@ export class Oanc<T extends number> extends DisplayComponent<OancProps<T>> {
.on('oans_display_airport')
.whenChanged()
.handle((airport) => {
this.loadAirportMap(airport);
if (this.oansPerformanceModeHide.get()) {
this.dataAirportIcao.set(airport);
} else {
this.loadAirportMap(airport);
}
});

this.sub
.on('oans_performance_mode_hide')
.whenChanged()
.handle((perfHide) => {
if (this.props.side === perfHide.side) {
this.oansPerformanceModeHide.set(perfHide.hide);
}
});

this.oansPerformanceModeHide.sub((hide) => {
if (hide) {
this.unloadAirportMap();
} else if (this.dataAirportIcao.get()) {
this.loadAirportMap(this.dataAirportIcao.get());
}
});

this.sub.on('oans_center_on_acft').handle(() => this.centerOnAcft());
this.sub.on('oans_center_map_on').handle((coords) => this.centerMapOn(coords));
this.sub.on('oans_add_cross_at_feature').handle((f) => this.markerManager.addCrossAtFeature(f.id, f.feattype));
Expand Down Expand Up @@ -598,25 +621,30 @@ export class Oanc<T extends number> extends DisplayComponent<OancProps<T>> {
this.markerManager.eraseAllFlags();
this.clearMap();
this.clearData();

this.arpCoordinates.set(undefined);
this.data = undefined;
this.aircraftWithinAirport.set(false);
}

/**
*
* @param icao four letter ICAO code of airport to load
* @returns
*/
public async loadAirportMap(icao: string) {
this.dataLoading = true;

this.airportLoading.set(true);

this.unloadAirportMap();

if (!icao) {
this.dataLoading = false;
this.airportLoading.set(false);
this.arpCoordinates.set(undefined);

this.data = undefined;
this.dataAirportName.set('');
this.dataAirportIcao.set('');
this.dataAirportIata.set('');
this.aircraftWithinAirport.set(false);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Position } from '@turf/turf';

export interface OansControlEvents {
nd_show_oans: { side: EfisSide; show: boolean };
oans_performance_mode_hide: { side: EfisSide; hide: boolean };
oans_display_airport: string;
oans_not_avail: boolean;
oans_center_map_on: Position;
Expand Down

0 comments on commit 5c7e902

Please sign in to comment.