Skip to content

Commit

Permalink
Improve initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkopp authored and ErickSharp committed Mar 20, 2022
1 parent 6da9ff4 commit 784a5ba
Show file tree
Hide file tree
Showing 28 changed files with 2,950 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
1. [MCDU] Implement ground temp on INIT A - @tracernz (Mike)
1. [BLEED] Attached hydraulic reservoirs to both engine bleed systems - @Gurgel100 (Pascal)
1. [COND] More accurately define air conditioning knob rotations - @rare-potato(Rare Potato#9693)
1. [EFB] Presets for Lighting and Aircraft states - @frankkopp (Frank Kopp)

## 0.7.0

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ src/instruments/buildSrc/custom/*
/src/mcdu-server/client/build
!/flybywire-aircraft-a320-neo/CORS SERVER/*
/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/TEXTURE/A320NEO_COCKPIT_DECALSTEXT_ALBD.TIF.dds
<<<<<<< HEAD
=======
src/presets/obj/
>>>>>>> 123249487 (Improve initialization)
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
}
],
"version": 4
}
}
29 changes: 29 additions & 0 deletions docs/a320-simvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,35 @@
0 or greater | Seconds elapsed
-1 | Empty value

- A32NX_LOAD_LIGHTING_PRESET
- Number
- ID for preset
- When set to >0 the corresponding preset will be loaded if defined
- Will be reset to 0 after loading is done

- A32NX_SAVE_LIGHTING_PRESET
- Number
- ID for preset
- When set to >0 the corresponding preset will be overwritten and saved to an ini file
- Will be reset to 0 after saving is done

- A32NX_LOAD_AIRCRAFT_PRESET
- Number
- ID for preset (1..5)
- When set to >0 the corresponding preset will be loaded if defined
- Will be reset to 0 after loading is done
- When set to 0 during loading will stop and cancel the loading process
- Value | Meaning
--- | ---
1 | Cold & Dark
2 | Turnaround
3 | Ready for Pushback
4 | Ready for Taxi
5 | Ready for Takeoff

- A32NX_LOAD_AIRCRAFT_PRESET_PROGRESS
- Number (0.0..1.0)
- While loading a preset this will contain the percentage of the total progress of loading
## EIS Display System

- A32NX_EFIS_{side}_NAVAID_{1|2}_MODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ background_color=0,0,0
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=systems.wasm&wasm_gauge=systems, 0,0,1,1
htmlgauge01=WasmInstrument/WasmInstrument.html?wasm_module=fbw.wasm&wasm_gauge=fbw, 0,0,1,1
htmlgauge02=WasmInstrument/WasmInstrument.html?wasm_module=fadec.wasm&wasm_gauge=FadecGauge, 0,0,1,1
htmlgauge03=WasmInstrument/WasmInstrument.html?wasm_module=presets.wasm&wasm_gauge=Presets, 0,0,1,1

[VPainting01]
size_mm = 2048,512
Expand Down
4 changes: 4 additions & 0 deletions igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default new TaskOfTasks('a32nx', [
'src/fadec/build.sh',
'wasm-opt -O1 -o flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/fadec.wasm flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/fadec.wasm'
], ['src/fadec', 'flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/fadec.wasm']),
new ExecTask('presets', [
'src/presets/build.sh',
'wasm-opt -O1 -o flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/presets.wasm flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/presets.wasm'
], ['src/presets', 'flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/presets.wasm']),
new TaskOfTasks('mcdu-server', [
new ExecTask('client', ['npm run build:mcdu-client'], ['src/mcdu-server/client', 'src/mcdu-server/client/build']),
new ExecTask('server', ['npm run build:mcdu-server'], ['src/mcdu-server', 'flybywire-aircraft-a320-neo/MCDU SERVER/server.exe']),
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build:sentry-client": "rollup -c src/sentry-client/rollup.config.js",
"build:fbw": "cd src/fbw && ./build.sh",
"build:fadec": "cd src/fadec && ./build.sh",
"build:presets": "cd src/presets && ./build.sh",
"build:failures": "rollup -c src/failures/rollup.config.js",
"build:fmgc": "rollup -c src/fmgc/rollup.config.js",
"build:tcas": "rollup -c src/tcas/rollup.config.js",
Expand Down Expand Up @@ -109,8 +110,8 @@
"geolib": "^3.3.3",
"history": "^4.10.1",
"immer": "^9.0.3",
"lodash": "^4.17.20",
"msfs-geo": "^0.1.0-alpha3",
"lodash": "^4.17.20",
"network": "^0.6.1",
"pdf-to-printer": "^5.1.1",
"pdfkit": "^0.13.0",
Expand Down
4 changes: 4 additions & 0 deletions src/instruments/src/EFB/Assets/Efb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
p, div, a, span, button {
@apply text-xl text-theme-text;
}

ul {
@apply list-disc pl-12;
}
}

/* ---- Global Scrollbar ---- */
Expand Down
20 changes: 17 additions & 3 deletions src/instruments/src/EFB/Efb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Navigation } from './Navigation/Navigation';
import { ATC } from './ATC/ATC';
import { Settings } from './Settings/Settings';
import { Failures } from './Failures/Failures';
import { Presets } from './Presets/Presets';

import { clearEfbState, useAppDispatch, useAppSelector } from './Store/store';

Expand Down Expand Up @@ -110,12 +111,21 @@ const Efb = () => {
const [autoSimbriefImport] = usePersistentProperty('CONFIG_AUTO_SIMBRIEF_IMPORT');

const [dc2BusIsPowered] = useSimVar('L:A32NX_ELEC_DC_2_BUS_IS_POWERED', 'bool');
const [batteryLevel, setBatteryLevel] = useState<BatteryStatus>({ level: 100, lastChangeTimestamp: absoluteTime, isCharging: dc2BusIsPowered });
const [batteryLevel, setBatteryLevel] = useState<BatteryStatus>({
level: 100,
lastChangeTimestamp: absoluteTime,
isCharging: dc2BusIsPowered,
});

const [lat] = useSimVar('PLANE LATITUDE', 'degree latitude', 4000);
const [long] = useSimVar('PLANE LONGITUDE', 'degree longitude', 4000);

const { arrivingPosLat, arrivingPosLong, departingPosLat, departingPosLong } = useAppSelector((state) => state.simbrief.data);
const {
arrivingPosLat,
arrivingPosLong,
departingPosLat,
departingPosLong,
} = useAppSelector((state) => state.simbrief.data);

const [theme] = usePersistentProperty('EFB_UI_THEME', 'blue');

Expand Down Expand Up @@ -193,7 +203,10 @@ const Efb = () => {
CHECKLISTS.forEach((checklist, index) => {
dispatch(setChecklistItems({
checklistIndex: index,
itemArr: checklist.items.map((item) => ({ completed: false, hasCondition: item.condition !== undefined })),
itemArr: checklist.items.map((item) => ({
completed: false,
hasCondition: item.condition !== undefined,
})),
}));
});
}
Expand Down Expand Up @@ -302,6 +315,7 @@ const Efb = () => {
<Route path="/failures" component={Failures} />
<Route path="/settings" component={Settings} />
<Route path="/checklists" component={Checklists} />
<Route path="/presets" component={Presets} />
</Switch>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/instruments/src/EFB/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,18 @@ export const ChartViewer = () => {
}));
}
}

if (chartRef.current && ref.current) {
if (chartRef.current.clientWidth === ref.current.clientWidth) {
const width = isFullScreen ? 804 : 1278;

const scale = width / (chartDimensions.width ?? 0);
const height = (chartDimensions.height ?? 0) * scale;

dispatch(editTabProperty({ tab: currentTab, chartDimensions: { width, height } }));
}
}
dispatch(editTabProperty({ tab: currentTab, isFullScreen: !isFullScreen }));
}}
>
{isFullScreen
Expand Down
29 changes: 29 additions & 0 deletions src/instruments/src/EFB/Presets/Presets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { PageLink, PageRedirect, TabRoutes } from '../Utils/routing';
import { Navbar } from '../UtilComponents/Navbar';
import { AircraftPresets } from './Widgets/AircraftPresets';
import { LightPresets } from './Widgets/LightPresets';
import { PresetsHelp } from './Widgets/PresetsHelp';

export const Presets = () => {
const tabs: PageLink[] = [
{ name: 'Lighting', component: <LightPresets /> },
{ name: 'Aircraft', component: <AircraftPresets /> },
{ name: '?', component: <PresetsHelp /> },
];

return (
<div className="w-full">
<div className="relative mb-4">
<h1 className="font-bold">Presets</h1>
<Navbar
className="absolute top-0 right-0"
tabs={tabs}
basePath="/presets"
/>
</div>
<PageRedirect basePath="/presets" tabs={tabs} />
<TabRoutes basePath="/presets" tabs={tabs} />
</div>
);
};
79 changes: 79 additions & 0 deletions src/instruments/src/EFB/Presets/Widgets/AircraftPresets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2022 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

/* eslint-disable max-len */
import React from 'react';
import { useSimVar } from '@instruments/common/simVars';
import { ScrollableContainer } from '../../UtilComponents/ScrollableContainer';

export const AircraftPresets = () => {
// Aircraft presets are handled by a backend WASM module. This frontend will
// use the LVAR A32NX_LOAD_AIRCRAFT_PRESET to signal the backend that the user
// requests a preset to be loaded.
// The backend will reset the LVAR to 0 when done.
// As long as the LVAR is 1 the backend is still applying the preset.
// If the LVAR is set to 0 before the backend is finished applying the preset
// will be stopped by the backend.

const [simOnGround] = useSimVar('SIM ON GROUND', 'number', 200);
const [loadPresetVar, setLoadPresetVar] = useSimVar('L:A32NX_LOAD_AIRCRAFT_PRESET', 'number', 200);
const [loadPresetProgress] = useSimVar('L:A32NX_LOAD_AIRCRAFT_PRESET_PROGRESS', 'number', 100);

// Sets the LVAR to tell the wasm to load the preset into the aircraft
function handleLoadPreset(presetID: number) {
setLoadPresetVar(presetID);
}

// Called by the cancel button to stop and cancel loading of a preset
function handleCancel() {
setLoadPresetVar(0);
}

const AIRCRAFT_PRESETS: { index: number, name: string }[] = [
{ index: 1, name: 'Cold & Dark' },
{ index: 2, name: 'Turnaround' },
{ index: 3, name: 'Ready for Pushback' },
{ index: 4, name: 'Ready for Taxi' },
{ index: 5, name: 'Ready for Takeoff' },
];

return (
<div className="p-4 mt-4 space-y-4 h-content-section-reduced rounded-lg border-2 border-theme-accent">
<div className="flex flex-row justify-center items-center p-2 space-x-2 h-14 rounded-md border-2 border-theme-accent">
{loadPresetVar ? (
<>
<div className="overflow-hidden w-full h-full bg-theme-accent rounded-md">
<div
className="h-full bg-theme-highlight"
style={{ width: `${loadPresetProgress * 100}%`, transition: 'width 0.1s ease' }}
/>
</div>

<div
className="flex items-center px-4 h-full text-theme-body hover:text-theme-highlight bg-theme-highlight hover:bg-theme-body rounded-md border-2 border-theme-highlight transition duration-100"
onClick={() => handleCancel()}
>
Cancel
</div>
</>
) : (
<>
{simOnGround ? 'Select a Preset to Load'
: 'The aircraft must be on the ground to load a preset.'}
</>
)}
</div>

<ScrollableContainer innerClassName="space-y-4" height={52}>
{AIRCRAFT_PRESETS.map(({ index, name }) => (
<div
className={`flex justify-center items-center h-24 rounded-md border-2 transition duration-100 text-theme-text hover:text-theme-body bg-theme-accent hover:bg-theme-highlight border-theme-accent ${(!simOnGround || (loadPresetVar && loadPresetVar !== index)) && 'opacity-50 pointer-events-none'}`}
onClick={() => handleLoadPreset(index)}
>
{name}
</div>
))}
</ScrollableContainer>
</div>
);
};
Loading

0 comments on commit 784a5ba

Please sign in to comment.