Skip to content

Commit

Permalink
fix(pfd): true flag flashes at slat extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tracernz committed Dec 21, 2022
1 parent 7db3ba6 commit 9756890
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
22 changes: 20 additions & 2 deletions src/instruments/src/PFD/HeadingIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,36 @@ interface TrueFlagProps {
}

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

private readonly slatsExtended = Subject.create(false);

private readonly slatsExtendedWithTrue = Subject.create(false);

private readonly trueFlagRef = FSComponent.createRef<SVGGElement>();

/** @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));
// FIXME this should be 127-11 from FWC
this.props.bus.getSubscriber<PFDSimvars>().on('slatPosLeft').withPrecision(0.25).handle((v) => this.slatsExtended.set(v > 0.4));

this.trueRefActive.sub((trueRef) => this.trueFlagRef.instance.classList.toggle('HiddenElement', !trueRef), true);

this.trueRefActive.sub(this.handleSlatsTrue.bind(this));
this.slatsExtended.sub(this.handleSlatsTrue.bind(this));
this.slatsExtendedWithTrue.sub((flash) => this.trueFlagRef.instance.classList.toggle('Blink10Seconds', flash));
}

private handleSlatsTrue(): void {
this.slatsExtendedWithTrue.set(this.trueRefActive.get() && this.slatsExtended.get());
}

/** @inheritdoc */
render(): VNode {
return (
<g id="TrueRefFlag" visibility={this.trueRefActive ? 'visible' : 'hidden'}>
<g id="TrueRefFlag" ref={this.trueFlagRef}>
<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>
Expand Down
6 changes: 6 additions & 0 deletions src/instruments/src/PFD/animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
animation-iteration-count: 9;
}

.Blink10Seconds {
animation-name: blinking;
animation-duration: 1s;
animation-iteration-count: 10;
}

.OuterMarkerBlink {
animation-name: OuterMarkerAnim;
animation-duration: 460ms;
Expand Down
1 change: 1 addition & 0 deletions src/instruments/src/PFD/instrument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class A32NX_PFD extends BaseInstrument {
this.simVarPublisher.subscribe('irMaintWordRaw');
this.simVarPublisher.subscribe('trueHeadingRaw');
this.simVarPublisher.subscribe('trueTrackRaw');
this.simVarPublisher.subscribe('slatPosLeft');

FSComponent.render(<PFDComponent bus={this.bus} instrument={this} />, document.getElementById('PFD_CONTENT'));
}
Expand Down
10 changes: 6 additions & 4 deletions src/instruments/src/PFD/shared/DisplayManagementComputer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class DisplayManagementComputer {
init(): void {
const pub = this.bus.getPublisher<DisplayManagementComputerEvents>();

this.trueRefActive.sub((v) => pub.pub('trueRefActive', v), true);
this.trueRefActive.sub((v) => {
pub.pub('trueRefActive', v);
this.handleHeading();
}, true);

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

Expand All @@ -54,13 +57,12 @@ export class DisplayManagementComputer {
// and the ADIRU must not be in ATT reversion mode
const trueRequested = this.irMaintWord.get().getBitValueOr(15, false) || this.trueRefPb.get();
this.trueRefActive.set(trueRequested && !this.irMaintWord.get().getBitValueOr(2, false));
this.handleHeading();
}

private handleHeading(): void {
const pub = this.bus.getPublisher<DisplayManagementComputerEvents>();

pub.pub('heading', this.trueRefActive ? this.trueHeading.get() : this.magHeading.get());
pub.pub('track', this.trueRefActive ? this.trueTrack.get() : this.magTrack.get());
pub.pub('heading', this.trueRefActive.get() ? this.trueHeading.get() : this.magHeading.get());
pub.pub('track', this.trueRefActive.get() ? this.trueTrack.get() : this.magTrack.get());
}
}
3 changes: 3 additions & 0 deletions src/instruments/src/PFD/shared/PFDSimvarPublisher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface PFDSimvars {
irMaintWordRaw: number;
trueHeadingRaw: number;
trueTrackRaw: number;
slatPosLeft: number;
}

export enum PFDVars {
Expand Down Expand Up @@ -293,6 +294,7 @@ export enum PFDVars {
irMaintWordRaw = 'L:A32NX_ADIRS_IR_1_MAINT_WORD',
trueHeadingRaw = 'L:A32NX_ADIRS_IR_1_TRUE_HEADING',
trueTrackRaw = 'L:A32NX_ADIRS_IR_1_TRUE_TRACK',
slatPosLeft = 'L:A32NX_LEFT_SLATS_ANGLE',
}

/** A publisher to poll and publish nav/com simvars. */
Expand Down Expand Up @@ -442,6 +444,7 @@ export class PFDSimvarPublisher extends SimVarPublisher<PFDSimvars> {
['irMaintWordRaw', { name: PFDVars.irMaintWordRaw, type: SimVarValueType.Number }],
['trueHeadingRaw', { name: PFDVars.trueHeadingRaw, type: SimVarValueType.Number }],
['trueTrackRaw', { name: PFDVars.trueTrackRaw, type: SimVarValueType.Number }],
['slatPosLeft', { name: PFDVars.slatPosLeft, type: SimVarValueType.Number }],
])

public constructor(bus: EventBus) {
Expand Down

0 comments on commit 9756890

Please sign in to comment.