Skip to content

Commit

Permalink
feat(pfd): true ref
Browse files Browse the repository at this point in the history
Still QFU dagger to be done (I think)
  • Loading branch information
tracernz committed Dec 7, 2022
1 parent 9a69586 commit 21ad292
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 43 deletions.
5 changes: 3 additions & 2 deletions src/instruments/src/PFD/AttitudeIndicatorHorizon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ClockEvents, DisplayComponent, EventBus, FSComponent, Subject, Subscribable, VNode } from 'msfssdk';
import { Arinc429Word } from '@shared/arinc429';

import { DisplayManagementComputerEvents } from 'instruments/src/PFD/shared/DisplayManagementComputer';
import {
calculateHorizonOffsetFromPitch,
calculateVerticalOffsetFromRoll,
Expand Down Expand Up @@ -44,7 +45,7 @@ class HeadingBug extends DisplayComponent<{bus: EventBus, isCaptainSide: boolean
onAfterRender(node: VNode): void {
super.onAfterRender(node);

const sub = this.props.bus.getSubscriber<PFDSimvars & SimplaneValues & Arinc429Values>();
const sub = this.props.bus.getSubscriber<DisplayManagementComputerEvents & PFDSimvars & SimplaneValues & Arinc429Values>();

sub.on('selectedHeading').whenChanged().handle((s) => {
this.selectedHeading = s;
Expand All @@ -53,7 +54,7 @@ class HeadingBug extends DisplayComponent<{bus: EventBus, isCaptainSide: boolean
}
});

sub.on('headingAr').handle((h) => {
sub.on('heading').handle((h) => {
this.heading = h;
if (this.isActive) {
this.calculateAndSetOffset();
Expand Down
34 changes: 30 additions & 4 deletions src/instruments/src/PFD/HeadingIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisplayComponent, EventBus, FSComponent, HEvent, Subject, Subscribable, VNode } from 'msfssdk';
import { DisplayManagementComputerEvents } from 'instruments/src/PFD/shared/DisplayManagementComputer';
import { HorizontalTape } from './HorizontalTape';
import { getSmallestAngle } from './PFDUtils';
import { PFDSimvars } from './shared/PFDSimvarPublisher';
Expand Down Expand Up @@ -60,9 +61,9 @@ export class HeadingOfftape extends DisplayComponent<{ bus: EventBus, failed: Su
onAfterRender(node: VNode): void {
super.onAfterRender(node);

const sub = this.props.bus.getSubscriber<PFDSimvars & Arinc429Values & HEvent>();
const sub = this.props.bus.getSubscriber<DisplayManagementComputerEvents & PFDSimvars & Arinc429Values & HEvent>();

sub.on('headingAr').handle((h) => {
sub.on('heading').handle((h) => {
this.heading.set(h.value);

if (h.isNormalOperation()) {
Expand Down Expand Up @@ -99,6 +100,7 @@ export class HeadingOfftape extends DisplayComponent<{ bus: EventBus, failed: Su
<QFUIndicator heading={this.heading} ILSCourse={this.ILSCourse} lsPressed={this.lsPressed} />
<path class="Fill Yellow" d="m69.61 147.31h-1.5119v-8.0635h1.5119z" />
<GroundTrackBug bus={this.props.bus} heading={this.heading} />
<TrueFlag bus={this.props.bus} />
</g>
</>
);
Expand Down Expand Up @@ -207,9 +209,9 @@ class GroundTrackBug extends DisplayComponent<GroundTrackBugProps> {
onAfterRender(node: VNode): void {
super.onAfterRender(node);

const sub = this.props.bus.getSubscriber<Arinc429Values>();
const sub = this.props.bus.getSubscriber<DisplayManagementComputerEvents>();

sub.on('groundTrackAr').handle((groundTrack) => {
sub.on('track').handle((groundTrack) => {
// if (groundTrack.isNormalOperation()) {
const offset = getSmallestAngle(groundTrack.value, this.props.heading.get()) * DistanceSpacing / ValueSpacing;
this.trackIndicator.instance.style.display = 'inline';
Expand Down Expand Up @@ -339,3 +341,27 @@ class QFUIndicator extends DisplayComponent<{ ILSCourse: Subscribable<number>, h
);
}
}

interface TrueFlagProps {
bus: EventBus;
}

class TrueFlag extends DisplayComponent<TrueFlagProps> {
private trueRefActive = Subject.create(false);

/** @inheritdoc */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onAfterRender(node: VNode): void {
this.props.bus.getSubscriber<DisplayManagementComputerEvents>().on('trueRefActive').whenChanged().handle((v) => this.trueRefActive.set(v));
}

/** @inheritdoc */
render(): VNode {
return (
<g id="TrueRefFlag" visibility={this.trueRefActive ? 'visible' : 'hidden'}>
<rect x="62.439" y="134.468" width="12.935" height="4.575" class="Cyan NormalStroke" />
<text x="68.9065" y="137.008" text-anchor="middle" alignment-baseline="middle" class="FontSmallest Cyan">TRUE</text>
</g>
);
}
}
5 changes: 3 additions & 2 deletions src/instruments/src/PFD/HorizontalTape.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DisplayManagementComputerEvents } from 'instruments/src/PFD/shared/DisplayManagementComputer';
import { EventBus, DisplayComponent, FSComponent, NodeReference, VNode, Subscribable } from 'msfssdk';
import { Arinc429Values } from './shared/ArincValueProvider';

Expand Down Expand Up @@ -118,14 +119,14 @@ export class HorizontalTape extends DisplayComponent<HorizontalTapeProps> {
onAfterRender(node: VNode): void {
super.onAfterRender(node);

const pf = this.props.bus.getSubscriber<Arinc429Values>();
const pf = this.props.bus.getSubscriber<Arinc429Values & DisplayManagementComputerEvents>();

this.props.yOffset?.sub((yOffset) => {
this.yOffset = yOffset;
this.refElement.instance.style.transform = `translate3d(${this.tapeOffset}px, ${yOffset}px, 0px)`;
});

pf.on('headingAr').handle((newVal) => {
pf.on('heading').handle((newVal) => {
const multiplier = 100;
const currentValueAtPrecision = Math.round(newVal.value * multiplier) / multiplier;
const tapeOffset = -currentValueAtPrecision % 10 * this.props.distanceSpacing / this.props.valueSpacing;
Expand Down
1 change: 1 addition & 0 deletions src/instruments/src/PFD/LandingSystemIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Arinc429Values } from './shared/ArincValueProvider';
import { PFDSimvars } from './shared/PFDSimvarPublisher';
import { LagFilter } from './PFDUtils';

// TODO true ref
export class LandingSystem extends DisplayComponent<{ bus: EventBus, instrument: BaseInstrument }> {
private lsButtonPressedVisibility = false;

Expand Down
39 changes: 32 additions & 7 deletions src/instruments/src/PFD/PFD.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/instruments/src/PFD/PFD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { A320Failure, FailuresConsumer } from '@flybywiresim/failures';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { ClockEvents, ComponentProps, DisplayComponent, EventBus, FSComponent, Subject, VNode } from 'msfssdk';
import { Arinc429Word } from '@shared/arinc429';
import { DisplayManagementComputerEvents } from 'instruments/src/PFD/shared/DisplayManagementComputer';
import { LagFilter } from './PFDUtils';
import { Arinc429Values } from './shared/ArincValueProvider';
import { DisplayUnit } from './shared/displayUnit';
Expand Down Expand Up @@ -54,9 +55,9 @@ export class PFDComponent extends DisplayComponent<PFDProps> {

this.failuresConsumer.register(getDisplayIndex() === 1 ? A320Failure.LeftPfdDisplay : A320Failure.RightPfdDisplay);

const sub = this.props.bus.getSubscriber<Arinc429Values & ClockEvents>();
const sub = this.props.bus.getSubscriber<Arinc429Values & ClockEvents & DisplayManagementComputerEvents>();

sub.on('headingAr').handle((h) => {
sub.on('heading').handle((h) => {
if (this.headingFailed.get() !== h.isNormalOperation()) {
this.headingFailed.set(!h.isNormalOperation());
}
Expand Down
15 changes: 11 additions & 4 deletions src/instruments/src/PFD/instrument.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DisplayManagementComputer } from 'instruments/src/PFD/shared/DisplayManagementComputer';
import { Clock, FSComponent, EventBus, HEventPublisher } from 'msfssdk';
import { PFDComponent } from './PFD';
import { AdirsValueProvider } from './shared/AdirsValueProvider';
Expand All @@ -22,6 +23,8 @@ class A32NX_PFD extends BaseInstrument {

private readonly adirsValueProvider: AdirsValueProvider;

private readonly displayManagementComputer: DisplayManagementComputer;

/**
* "mainmenu" = 0
* "loading" = 1
Expand All @@ -39,6 +42,7 @@ class A32NX_PFD extends BaseInstrument {
this.simplaneValueProvider = new SimplaneValueProvider(this.bus);
this.clock = new Clock(this.bus);
this.adirsValueProvider = new AdirsValueProvider(this.bus, this.simVarPublisher);
this.displayManagementComputer = new DisplayManagementComputer(this.bus);
}

get templateID(): string {
Expand All @@ -58,6 +62,7 @@ class A32NX_PFD extends BaseInstrument {

this.arincProvider.init();
this.clock.init();
this.displayManagementComputer.init();

this.simVarPublisher.subscribe('elec');
this.simVarPublisher.subscribe('elecFo');
Expand All @@ -67,7 +72,7 @@ class A32NX_PFD extends BaseInstrument {
this.simVarPublisher.subscribe('potentiometerFo');
this.simVarPublisher.subscribe('pitch');
this.simVarPublisher.subscribe('roll');
this.simVarPublisher.subscribe('heading');
this.simVarPublisher.subscribe('magHeadingRaw');
this.simVarPublisher.subscribe('altitude');
this.simVarPublisher.subscribe('speed');
this.simVarPublisher.subscribe('noseGearCompressed');
Expand Down Expand Up @@ -122,13 +127,11 @@ class A32NX_PFD extends BaseInstrument {
this.simVarPublisher.subscribe('transAlt');
this.simVarPublisher.subscribe('transAltAppr');

this.simVarPublisher.subscribe('groundTrack');
this.simVarPublisher.subscribe('magTrackRaw');
this.simVarPublisher.subscribe('showSelectedHeading');
this.simVarPublisher.subscribe('altConstraint');
this.simVarPublisher.subscribe('trkFpaActive');
this.simVarPublisher.subscribe('aoa');
this.simVarPublisher.subscribe('groundHeadingTrue');
this.simVarPublisher.subscribe('groundTrackTrue');

this.simVarPublisher.subscribe('selectedFpa');
this.simVarPublisher.subscribe('targetSpeedManaged');
Expand Down Expand Up @@ -214,6 +217,10 @@ class A32NX_PFD extends BaseInstrument {
this.simVarPublisher.subscribe('fac2EstimatedBetaRaw');
this.simVarPublisher.subscribe('fac1BetaTargetRaw');
this.simVarPublisher.subscribe('fac2BetaTargetRaw');
this.simVarPublisher.subscribe('trueRefPushbutton');
this.simVarPublisher.subscribe('irMaintWordRaw');
this.simVarPublisher.subscribe('trueHeadingRaw');
this.simVarPublisher.subscribe('trueTrackRaw');

FSComponent.render(<PFDComponent bus={this.bus} instrument={this} />, document.getElementById('PFD_CONTENT'));
}
Expand Down
7 changes: 5 additions & 2 deletions src/instruments/src/PFD/shared/AdirsValueProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export class AdirsValueProvider {
this.pfdSimvar.updateSimVarSource('vsInert', { name: `L:A32NX_ADIRS_IR_${inertialSource}_VERTICAL_SPEED`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('pitch', { name: `L:A32NX_ADIRS_IR_${inertialSource}_PITCH`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('roll', { name: `L:A32NX_ADIRS_IR_${inertialSource}_ROLL`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('heading', { name: `L:A32NX_ADIRS_IR_${inertialSource}_HEADING`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('groundTrack', { name: `L:A32NX_ADIRS_IR_${inertialSource}_TRACK`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('magHeadingRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_HEADING`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('magTrackRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_TRACK`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('fpaRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_FLIGHT_PATH_ANGLE`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('daRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_DRIFT_ANGLE`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('latAccRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_BODY_LATERAL_ACC`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('irMaintWordRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_MAINT_WORD`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('trueHeadingRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_TRUE_HEADING`, type: SimVarValueType.Number });
this.pfdSimvar.updateSimVarSource('trueTrackRaw', { name: `L:A32NX_ADIRS_IR_${inertialSource}_TRUE_TRACK`, type: SimVarValueType.Number });
});

sub.on('airKnob').whenChanged().handle((a) => {
Expand Down
31 changes: 23 additions & 8 deletions src/instruments/src/PFD/shared/ArincValueProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface Arinc429Values {
pitchAr: Arinc429Word;
rollAr: Arinc429Word;
altitudeAr: Arinc429Word;
groundTrackAr: Arinc429Word;
headingAr: Arinc429Word;
magTrack: Arinc429Word;
magHeading: Arinc429Word;
speedAr: Arinc429Word;
machAr: Arinc429Word;
vs: Arinc429Word;
Expand Down Expand Up @@ -40,13 +40,16 @@ export interface Arinc429Values {
vLs: Arinc429Word;
estimatedBeta: Arinc429Word;
betaTarget: Arinc429Word;
irMaintWord: Arinc429Word;
trueHeading: Arinc429Word;
trueTrack: Arinc429Word;
}
export class ArincValueProvider {
private roll = new Arinc429Word(0);

private pitch = new Arinc429Word(0);

private groundTrack = new Arinc429Word(0);
private magTrack = new Arinc429Word(0);

private heading = new Arinc429Word(0);

Expand Down Expand Up @@ -112,13 +115,13 @@ export class ArincValueProvider {
this.roll = new Arinc429Word(p);
publisher.pub('rollAr', this.roll);
});
subscriber.on('groundTrack').handle((gt) => {
this.groundTrack = new Arinc429Word(gt);
publisher.pub('groundTrackAr', this.groundTrack);
subscriber.on('magTrackRaw').handle((gt) => {
this.magTrack = new Arinc429Word(gt);
publisher.pub('magTrack', this.magTrack);
});
subscriber.on('heading').handle((h) => {
subscriber.on('magHeadingRaw').handle((h) => {
this.heading = new Arinc429Word(h);
publisher.pub('headingAr', this.heading);
publisher.pub('magHeading', this.heading);
});

subscriber.on('speed').handle((s) => {
Expand Down Expand Up @@ -482,6 +485,18 @@ export class ArincValueProvider {
publisher.pub('betaTarget', new Arinc429Word(word));
}
});

subscriber.on('irMaintWordRaw').handle((word) => {
publisher.pub('irMaintWord', new Arinc429Word(word));
});

subscriber.on('trueHeadingRaw').handle((word) => {
publisher.pub('trueHeading', new Arinc429Word(word));
});

subscriber.on('trueTrackRaw').handle((word) => {
publisher.pub('trueTrack', new Arinc429Word(word));
});
}

private determineAndPublishChosenRadioAltitude(publisher: Publisher<Arinc429Values>) {
Expand Down
Loading

0 comments on commit 21ad292

Please sign in to comment.