Skip to content

Commit

Permalink
Add vertical speed to approach statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
hallidave committed Nov 8, 2022
1 parent d68588e commit 361a05b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daves-landing-monitor",
"version": "0.5.1",
"version": "0.6.0",
"description": "",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion project/PackageDefinitions/hallidave-tool-landing.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<AssetPackage Version="0.5.1">
<AssetPackage Version="0.6.0">
<ItemSettings>
<ContentType>MISC</ContentType>
<Title>Landing Monitor</Title>
Expand Down
33 changes: 30 additions & 3 deletions src/ApproachDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@ interface ApproachProps extends ComponentProps {

export class ApproachDisplay extends DisplayComponent<ApproachProps> {

private verticalSpeed = Subject.create<number>(0);
private verticalDirection = Subject.create<"up"|"down">("up");
private heightAgl = Subject.create<number>(0);
private groundSpeed = Subject.create<number>(0);
private flightPathAngle = Subject.create<number>(0);
private windDirection = Subject.create<number>(0);
private windSpeed = Subject.create<number>(0);

private readonly arrowRef = FSComponent.createRef<SVGElement>();
private readonly windArrowRef = FSComponent.createRef<SVGElement>();
private readonly verticalArrowRef = FSComponent.createRef<SVGElement>();

constructor(props: ApproachProps) {
super(props);

const appEvents = props.bus.getSubscriber<ApproachEvents>();

appEvents.on("vertical_speed").withPrecision(0).handle((verticalSpeed) => {
this.verticalSpeed.set(Math.abs(Math.round(verticalSpeed/10)*10));
if (verticalSpeed >= 0) {
this.verticalDirection.set("up");
} else {
this.verticalDirection.set("down");
}
});
appEvents.on("height_agl").withPrecision(0).handle((heightAgl) => {
this.heightAgl.set(heightAgl);
});
Expand All @@ -44,6 +55,15 @@ export class ApproachDisplay extends DisplayComponent<ApproachProps> {
return (
<div id="ApproachDisplay">
<table>
<tr>
<td class="name">{Translate.text("VERTICAL_SPEED")}</td>
<td class="value">
<svg viewBox="0 0 24 24" class="icon">
<path ref={this.verticalArrowRef} d="M12 22.575 4.15 14.7 6.35 12.475 10.425 16.575V1.2H13.575V16.575L17.65 12.5L19.875 14.7Z" />
</svg>{this.verticalSpeed}
</td>
<td class="units">&nbsp;{Translate.text("FPM")}</td>
</tr>
<tr>
<td class="name">{Translate.text("HEIGHT_AGL")}</td>
<td class="value">{this.heightAgl}</td>
Expand All @@ -62,7 +82,7 @@ export class ApproachDisplay extends DisplayComponent<ApproachProps> {
<td class="name">{Translate.text("WIND")}</td>
<td class="value">
<svg viewBox="0 0 24 24" class="icon">
<path ref={this.arrowRef} d="M12 22.575 4.15 14.7 6.35 12.475 10.425 16.575V1.2H13.575V16.575L17.65 12.5L19.875 14.7Z" />
<path ref={this.windArrowRef} d="M12 22.575 4.15 14.7 6.35 12.475 10.425 16.575V1.2H13.575V16.575L17.65 12.5L19.875 14.7Z" />
</svg>{this.windSpeed}
</td>
<td class="units">&nbsp;{Translate.text("UNIT_KNOTS")}</td>
Expand All @@ -74,8 +94,15 @@ export class ApproachDisplay extends DisplayComponent<ApproachProps> {

public onAfterRender(node: VNode): void {
super.onAfterRender(node);
this.verticalDirection.sub(verticalDirection => {
if (verticalDirection === "up") {
this.verticalArrowRef.instance.setAttribute("transform", "rotate(180, 12, 12)");
} else {
this.verticalArrowRef.instance.setAttribute("transform", "rotate(0, 12, 12)");
}
});
this.windDirection.sub(windDirection => {
this.arrowRef.instance.setAttribute("transform", "rotate(" + String(windDirection) + ", 12, 12)");
this.windArrowRef.instance.setAttribute("transform", "rotate(" + String(windDirection) + ", 12, 12)");
});
}
}
5 changes: 4 additions & 1 deletion src/ApproachEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { EventBus, PublishPacer } from "msfssdk/data";
import { EventBus, PublishPacer, SimVarValueType } from "msfssdk/data";
import { BasePublisher } from "msfssdk/instruments";

export interface ApproachEvents {
// Vertical speed in feet per minute
"vertical_speed": number;
// Height above ground level in feet
"height_agl": number;
// Ground speed in knots
Expand All @@ -23,6 +25,7 @@ export class ApproachPublisher extends BasePublisher<ApproachEvents> {
public onUpdate(): void {
super.onUpdate();

this.publish("vertical_speed", SimVar.GetSimVarValue("VELOCITY WORLD Y", SimVarValueType.FPM));
this.publish("height_agl", Simplane.getAltitudeAboveGround());
const groundSpeed = Simplane.getGroundSpeed();
this.publish("ground_speed", groundSpeed);
Expand Down

0 comments on commit 361a05b

Please sign in to comment.