Skip to content

Commit

Permalink
refactor(fcu): modernize FCU avionics-framework code (flybywiresim#9544)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecologne authored Nov 23, 2024
1 parent f484bde commit a526ab6
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 360 deletions.
78 changes: 53 additions & 25 deletions fbw-a32nx/src/systems/instruments/src/FCU/Components/AfsDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { ComponentProps, DisplayComponent, EventBus, FSComponent, Subject, VNode } from '@microsoft/msfs-sdk';
import {
ComponentProps,
ConsumerSubject,
DisplayComponent,
EventBus,
FSComponent,
MappedSubject,
Subject,
SubscribableMapFunctions,
VNode,
} from '@microsoft/msfs-sdk';
import { FcuSimvars } from '../shared/FcuSimvarPublisher';
import { HdgDisplay } from './HdgDisplay';
import { SpdDisplay } from './SpdDisplay';
Expand All @@ -9,13 +19,20 @@ interface AfsDisplayProps extends ComponentProps {
}

export class AfsDisplay extends DisplayComponent<AfsDisplayProps> {
private lightsTest = false;
private lightsTest = Subject.create(false);

private trkFpaMode = false;
private trkFpaMode = ConsumerSubject.create(null, false);

private trkFpaLabelSub = Subject.create('');

private hdgVsLabelSub = Subject.create('');
private trkFpaLabelSub = MappedSubject.create(
([trkFpa, lightsTest]) => trkFpa || lightsTest,
this.trkFpaMode,
this.lightsTest,
);
private hdgVsLabelSub = MappedSubject.create(
([trkFpa, lightsTest]) => !trkFpa || lightsTest,
this.trkFpaMode,
this.lightsTest,
);

public onAfterRender(node: VNode): void {
super.onAfterRender(node);
Expand All @@ -26,23 +43,10 @@ export class AfsDisplay extends DisplayComponent<AfsDisplayProps> {
.on('lightsTest')
.whenChanged()
.handle((value) => {
this.lightsTest = value === 0;

this.handleLabels();
});

sub
.on('afsDisplayTrkFpaMode')
.whenChanged()
.handle((value) => {
this.trkFpaMode = value;
this.handleLabels();
this.lightsTest.set(value === 0);
});
}

private handleLabels() {
this.trkFpaLabelSub.set(this.trkFpaMode || this.lightsTest ? 'Active' : 'Inactive');
this.hdgVsLabelSub.set(!this.trkFpaMode || this.lightsTest ? 'Active' : 'Inactive');
this.trkFpaMode.setConsumer(sub.on('afsDisplayTrkFpaMode'));
}

public render(): VNode {
Expand All @@ -53,19 +57,43 @@ export class AfsDisplay extends DisplayComponent<AfsDisplayProps> {

<HdgDisplay bus={this.props.bus} x={512} y={0} />

<text id="HDG" class={this.hdgVsLabelSub} x="1229" y="96" text-anchor="end" alignment-baseline="middle">
<text
id="HDG"
class={{ Active: this.hdgVsLabelSub, Inactive: this.hdgVsLabelSub.map(SubscribableMapFunctions.not()) }}
x="1229"
y="96"
text-anchor="end"
alignment-baseline="middle"
>
HDG
</text>
<text id="TRK" class={this.trkFpaLabelSub} x="1229" y="163" text-anchor="end">
<text
id="TRK"
class={{ Active: this.trkFpaLabelSub, Inactive: this.trkFpaLabelSub.map(SubscribableMapFunctions.not()) }}
x="1229"
y="163"
text-anchor="end"
>
TRK
</text>
</g>

<g transform="translate(0 224)">
<text id="VS" class={this.hdgVsLabelSub} x="51" y="96" alignment-baseline="middle">
<text
id="VS"
class={{ Active: this.hdgVsLabelSub, Inactive: this.hdgVsLabelSub.map(SubscribableMapFunctions.not()) }}
x="51"
y="96"
alignment-baseline="middle"
>
V/S
</text>
<text id="FPA" class={this.trkFpaLabelSub} x="51" y="163">
<text
id="FPA"
class={{ Active: this.trkFpaLabelSub, Inactive: this.trkFpaLabelSub.map(SubscribableMapFunctions.not()) }}
x="51"
y="163"
>
FPA
</text>

Expand Down
139 changes: 70 additions & 69 deletions fbw-a32nx/src/systems/instruments/src/FCU/Components/EisDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ComponentProps, DisplayComponent, EventBus, FSComponent, Subject, VNode } from '@microsoft/msfs-sdk';
import {
ComponentProps,
ConsumerSubject,
DisplayComponent,
EventBus,
FSComponent,
MappedSubject,
Subject,
VNode,
} from '@microsoft/msfs-sdk';
import { FcuSimvars } from '../shared/FcuSimvarPublisher';

interface EisDisplayProps extends ComponentProps {
Expand All @@ -9,19 +18,62 @@ interface EisDisplayProps extends ComponentProps {
}

export class EisDisplay extends DisplayComponent<EisDisplayProps> {
private baroValueMode = 0;

private baroValue = 0;

private baroMode = 0;

private lightsTest = false;

private baroValueSub = Subject.create('');

private qnhLabelSub = Subject.create('');

private qfeLabelSub = Subject.create('');
private baroValueMode = ConsumerSubject.create(null, 0);

private baroValue = ConsumerSubject.create(null, 0);

private baroMode = ConsumerSubject.create(null, 0);

private lightsTest = Subject.create(false);

private baroValueSub = MappedSubject.create(
([lightsTest, baroValueMode, baroValue]) => {
if (lightsTest) {
return '88.88';
} else if (baroValueMode === 0) {
return 'Std';
} else if (baroValueMode === 1) {
return Math.round(baroValue).toString();
} else {
return baroValue.toFixed(2);
}
},
this.lightsTest,
this.baroValueMode,
this.baroValue,
);

private qnhLabelSub = MappedSubject.create(
([lightsTest, baroMode]) => {
if (lightsTest) {
return 'Active';
} else if (baroMode === 0) {
return 'Inactive';
} else if (baroMode === 1) {
return 'Active';
} else {
return 'Inactive';
}
},
this.lightsTest,
this.baroMode,
);

private qfeLabelSub = MappedSubject.create(
([lightsTest, baroMode]) => {
if (lightsTest) {
return 'Active';
} else if (baroMode === 0) {
return 'Inactive';
} else if (baroMode === 1) {
return 'Inactive';
} else {
return 'Active';
}
},
this.lightsTest,
this.baroMode,
);

public onAfterRender(node: VNode): void {
super.onAfterRender(node);
Expand All @@ -32,65 +84,14 @@ export class EisDisplay extends DisplayComponent<EisDisplayProps> {
.on('lightsTest')
.whenChanged()
.handle((value) => {
this.lightsTest = value === 0;

this.handleLabels();
this.handleValue();
});

sub
.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroValueMode`)
.whenChanged()
.handle((newVal) => {
this.baroValueMode = newVal;
this.handleLabels();
this.handleValue();
});

sub
.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroValue`)
.whenChanged()
.handle((newVal) => {
this.baroValue = newVal;
this.handleValue();
this.lightsTest.set(value === 0);
});

sub
.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroMode`)
.whenChanged()
.handle((newVal) => {
this.baroMode = newVal;
this.handleLabels();
this.handleValue();
});
}
this.baroValueMode.setConsumer(sub.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroValueMode`));

private handleValue() {
if (this.lightsTest) {
this.baroValueSub.set('88.88');
} else if (this.baroValueMode === 0) {
this.baroValueSub.set('Std');
} else if (this.baroValueMode === 1) {
this.baroValueSub.set(Math.round(this.baroValue).toString());
} else {
this.baroValueSub.set(this.baroValue.toFixed(2));
}
}
this.baroValue.setConsumer(sub.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroValue`));

private handleLabels() {
if (this.lightsTest) {
this.qfeLabelSub.set('Active');
this.qnhLabelSub.set('Active');
} else if (this.baroMode === 0) {
this.qfeLabelSub.set('Inactive');
this.qnhLabelSub.set('Inactive');
} else if (this.baroMode === 1) {
this.qfeLabelSub.set('Inactive');
this.qnhLabelSub.set('Active');
} else {
this.qfeLabelSub.set('Active');
this.qnhLabelSub.set('Inactive');
}
this.baroMode.setConsumer(sub.on(`eisDisplay${this.props.isCaptSide ? 'Left' : 'Right'}BaroMode`));
}

public render(): VNode {
Expand Down
Loading

0 comments on commit a526ab6

Please sign in to comment.