Skip to content

Commit

Permalink
When Input.ExternalSwitches.LegObsSwitchInstalled is true, then the K…
Browse files Browse the repository at this point in the history
…LN listens to GPS OBS ACTIVE, to switch mode accordingly
  • Loading branch information
falcon71 committed Nov 27, 2023
1 parent 7306a59 commit 5006f55
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 66 deletions.
4 changes: 2 additions & 2 deletions kln90b/KLN90B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class KLN90B extends BaseInstrument {
nearestLists.ndbNearestList,
nearestLists.aptNearestList,
nearestLists.vorNearestList,
new NavCalculator(sensors, memory, magvar, this.userSettings, modeController),
new NavCalculator(sensors, memory, magvar, this.userSettings, modeController, this.planeSettings),
airspaceAlert,
new HtAboveAirportAlert(memory.navPage, this.planeSettings, sensors, this.userSettings),
new AltAlert(memory, this.planeSettings, sensors),
Expand All @@ -287,7 +287,7 @@ class KLN90B extends BaseInstrument {
this.messageHandler,
], this.messageHandler, this.planeSettings);

this.simvarSync = new SimVarSync(this.powerButton, this.planeSettings, this.tickManager);
this.simvarSync = new SimVarSync(this.powerButton, this.planeSettings, this.tickManager, modeController);

const msa = new MSA();

Expand Down
33 changes: 25 additions & 8 deletions kln90b/Sensors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export class SensorsIn implements CalcTickable {
public airdata: Airdata;


constructor(bus: EventBus, private readonly userSettings: KLN90BUserSettings, private readonly options: KLN90PlaneSettings, messageHandler: MessageHandler) {
constructor(bus: EventBus, userSettings: KLN90BUserSettings, private readonly options: KLN90PlaneSettings, messageHandler: MessageHandler) {
this.gps = new GPS(bus, userSettings, options, messageHandler);
this.fuelComputer = new FuelComputer(options);
this.airdata = new Airdata(userSettings, options);
Expand Down Expand Up @@ -652,35 +652,52 @@ export class SensorsOut {
* @param mode
* @param isSelfTestActive For selftest, we set GPS APPROACH MODE to 3, to signal that ARM AND APPR lights should
* both light up on external annunciators. 3 is not used during normal operation
* @param writeObs GPS OBS ACTIVE will become readonly when an external mode switch is installed
*/
public setMode(mode: NavMode, isSelfTestActive: boolean) {
public setMode(mode: NavMode, isSelfTestActive: boolean, writeObs: boolean) {
if (!this.options.output.writeGPSSimVars) {
return;
}

switch (mode) {
case NavMode.ENR_LEG:
SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
if (writeObs) {
//GPS OBS ACTIVE is marked writable in the docs, but appears to be readonly
SimVar.SetSimVarValue('K:GPS_OBS_OFF', SimVarValueType.Bool, true);
//SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
}
SimVar.SetSimVarValue('GPS IS APPROACH ACTIVE', SimVarValueType.Bool, false);
SimVar.SetSimVarValue('GPS APPROACH MODE', SimVarValueType.Enum, isSelfTestActive ? 3 : 0);
break;
case NavMode.ENR_OBS:
SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, true);
if (writeObs) {
SimVar.SetSimVarValue('K:GPS_OBS_ON', SimVarValueType.Bool, true);
//SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, true);
}
SimVar.SetSimVarValue('GPS IS APPROACH ACTIVE', SimVarValueType.Bool, false);
SimVar.SetSimVarValue('GPS APPROACH MODE', SimVarValueType.Enum, isSelfTestActive ? 3 : 0);
break;
case NavMode.ARM_LEG:
SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
if (writeObs) {
SimVar.SetSimVarValue('K:GPS_OBS_OFF', SimVarValueType.Bool, true);
//SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
}
SimVar.SetSimVarValue('GPS IS APPROACH ACTIVE', SimVarValueType.Bool, true);
SimVar.SetSimVarValue('GPS APPROACH MODE', SimVarValueType.Enum, isSelfTestActive ? 3 : 1);
break;
case NavMode.ARM_OBS:
SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, true);
if (writeObs) {
SimVar.SetSimVarValue('K:GPS_OBS_ON', SimVarValueType.Bool, true);
//SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, true);
}
SimVar.SetSimVarValue('GPS IS APPROACH ACTIVE', SimVarValueType.Bool, true);
SimVar.SetSimVarValue('GPS APPROACH MODE', SimVarValueType.Enum, isSelfTestActive ? 3 : 1);
break;
case NavMode.APR_LEG:
SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
if (writeObs) {
SimVar.SetSimVarValue('K:GPS_OBS_OFF', SimVarValueType.Bool, true);
//SimVar.SetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool, false);
}
SimVar.SetSimVarValue('GPS IS APPROACH ACTIVE', SimVarValueType.Bool, true);
SimVar.SetSimVarValue('GPS APPROACH MODE', SimVarValueType.Enum, isSelfTestActive ? 3 : 2);
break
Expand All @@ -707,7 +724,7 @@ export class SensorsOut {
this.setWPIndex(0, 0);
this.setPrevWpt(null);
this.setNextWpt(null);
this.setMode(NavMode.ENR_LEG, false);
this.setMode(NavMode.ENR_LEG, false, !this.options.input.externalSwitches.legObsSwitchInstalled);
}
}

Expand Down
8 changes: 7 additions & 1 deletion kln90b/SimVarSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {PowerButton} from "./PowerButton";
import {KLN90PlaneSettings} from "./settings/KLN90BPlaneSettings";
import {LVAR_DISABLE, LVAR_ELECTRICITY_INDEX, LVAR_GPS_SIMVARS, LVAR_OBS_SOURCE, LVAR_OBS_TARGET} from "./LVars";
import {TickController} from "./TickController";
import {ModeController} from "./services/ModeController";

const SYNC_TICK = 100;

Expand All @@ -13,7 +14,7 @@ export class SimVarSync {

private disabled: boolean = false;

constructor(private readonly powerButton: PowerButton, private readonly settings: KLN90PlaneSettings, private readonly tickController: TickController) {
constructor(private readonly powerButton: PowerButton, private readonly settings: KLN90PlaneSettings, private readonly tickController: TickController, private readonly modeController: ModeController) {
window.setInterval(this.tick.bind(this), SYNC_TICK);
}

Expand All @@ -31,6 +32,11 @@ export class SimVarSync {
const disabled = !!SimVar.GetSimVarValue(LVAR_DISABLE, SimVarValueType.Bool);
this.setDisabled(disabled);

if (this.settings.input.externalSwitches.legObsSwitchInstalled && !disabled) {
//SensorsIn would be a better place for this, but this would create a circle reference between sensors and modecontroller
this.modeController.setExternalObsMode(!!SimVar.GetSimVarValue('GPS OBS ACTIVE', SimVarValueType.Bool));
}

this.settings.input.obsSource = SimVar.GetSimVarValue(LVAR_OBS_SOURCE, SimVarValueType.Number);
this.settings.output.obsTarget = SimVar.GetSimVarValue(LVAR_OBS_TARGET, SimVarValueType.Number);

Expand Down
2 changes: 1 addition & 1 deletion kln90b/Version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.1 B5"; // 6 chars maximum!
export const VERSION = "0.1 B6"; // 6 chars maximum!
3 changes: 2 additions & 1 deletion kln90b/controls/StatusLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class StatusLine extends DisplayComponent<StatusLineProps> implements UiE
constructor(props: StatusLineProps) {
super(props);

this.sub = props.bus.getSubscriber<StatusLineMessageEvents>().on("statusLineMessage").handle(this.showMessage.bind(this));
this.sub = props.bus.getSubscriber<StatusLineMessageEvents>().on("statusLineMessage").handle(this.showMessage.bind(this), true);
this.sub.resume(false); //We don't care about old notifications from ages ago
}

render(): VNode {
Expand Down
5 changes: 3 additions & 2 deletions kln90b/data/navdata/NavCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ModeController} from "../../services/ModeController";
import {KLNFixType} from "../flightplan/Flightplan";
import {KLNMagvar} from "./KLNMagvar";
import {calcDistToDestination} from "../../services/FlightplanUtils";
import {KLN90PlaneSettings} from "../../settings/KLN90BPlaneSettings";


//4-8
Expand All @@ -26,7 +27,7 @@ export class NavCalculator implements CalcTickable {
private lastDistance = 9999;


constructor(private readonly sensors: Sensors, private readonly memory: VolatileMemory, private readonly magvar: KLNMagvar, userSettings: KLN90BUserSettings, private readonly modeController: ModeController) {
constructor(private readonly sensors: Sensors, private readonly memory: VolatileMemory, private readonly magvar: KLNMagvar, userSettings: KLN90BUserSettings, private readonly modeController: ModeController, private readonly planeSettings: KLN90PlaneSettings) {
this.turnAnticipation = userSettings.getSetting("turnAnticipation");
}

Expand Down Expand Up @@ -180,7 +181,7 @@ export class NavCalculator implements CalcTickable {
this.sensors.out.setPrevWpt(nav.activeWaypoint.getFromWpt());
this.sensors.out.setNextWpt(nav.activeWaypoint.getActiveWpt());

this.sensors.out.setMode(nav.navmode, nav.isSelfTestActive);
this.sensors.out.setMode(nav.navmode, nav.isSelfTestActive, !this.planeSettings.input.externalSwitches.legObsSwitchInstalled);
this.sensors.out.setWptAlertLight(nav.waypointAlert); //The manual says flashing, but it's steady in this video (left light) https://youtu.be/S1lt2W95bLA?si=C45kt8pik15Iodoy&t=2245
}

Expand Down
39 changes: 39 additions & 0 deletions kln90b/pages/ObsWarningPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {FSComponent, VNode} from '@microsoft/msfs-sdk';
import {NO_CURSOR_CONTROLLER} from "./CursorController";
import {FourSegmentPage, SixLinePage} from "./FourSegmentPage";
import {NO_CHILDREN, PageProps} from "./Page";
import {AiracPage} from "./AiracPage";


export class ObswarningPage extends SixLinePage {

readonly children = NO_CHILDREN;
public readonly lCursorController = NO_CURSOR_CONTROLLER;
public readonly rCursorController = NO_CURSOR_CONTROLLER;

constructor(props: PageProps) {
super(props);
}

public render(): VNode {
return (<pre>
<br/>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWARNING<br/>
<br/>
&nbspSYSTEM IS IN OBS MODE<br/>
&nbspPRESS GPS CRS BUTTON<br/>
&nbspTO CHANGE TO LEG MODE
</pre>);
}

tick(blink: boolean) {
super.tick(blink);
if (!this.props.modeController.isObsModeActive()) {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new AiracPage(this.props),
});
}
}

}
16 changes: 12 additions & 4 deletions kln90b/pages/VFROnlyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {FourSegmentPage, SixLinePage} from "./FourSegmentPage";
import {PageProps, UIElementChildren} from "./Page";
import {Button} from "../controls/Button";
import {AiracPage} from "./AiracPage";
import {ObswarningPage} from "./ObsWarningPage";


type VFROnlyPageChildTypes = {
Expand Down Expand Up @@ -36,9 +37,16 @@ export class VFROnlyPage extends SixLinePage {


private acknowledge(): void {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new AiracPage(this.props),
});
if (this.props.modeController.isObsModeActive()) {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new ObswarningPage(this.props),
});
} else {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new AiracPage(this.props),
});
}
}
}
7 changes: 5 additions & 2 deletions kln90b/pages/left/Mod1Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export class Mod1Page extends SixLineHalfPage {
}

public isEnterAccepted(): boolean {
return this.props.modeController.isObsModeActive();
return this.props.modeController.isObsModeActive() && !this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled;
}

public enter(): Promise<EnterResult> {
if (!this.props.modeController.isObsModeActive() || this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled) {
return Promise.resolve(EnterResult.Not_Handled);
}
this.props.modeController.switchToEnrLegMode();
return Promise.resolve(EnterResult.Handled_Keep_Focus);
}
Expand All @@ -62,7 +65,7 @@ export class Mod1Page extends SixLineHalfPage {
protected redraw(): void {
if (this.props.modeController.isObsModeActive()) {
if (this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled) {
this.children.get("title1").text = "PRESS GRPS";
this.children.get("title1").text = "PRESS GPS";
this.children.get("title2").text = "CRS FOR";
} else {
this.children.get("title1").text = "PRESS ENT";
Expand Down
7 changes: 5 additions & 2 deletions kln90b/pages/left/Mod2Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export class Mod2Page extends SixLineHalfPage {
}

public isEnterAccepted(): boolean {
return !this.props.modeController.isObsModeActive();
return !this.props.modeController.isObsModeActive() && !this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled;
}

public enter(): Promise<EnterResult> {
if (this.props.modeController.isObsModeActive() || this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled) {
return Promise.resolve(EnterResult.Not_Handled);
}
this.props.modeController.switchToEnrObsMode();
return Promise.resolve(EnterResult.Handled_Keep_Focus);
}
Expand All @@ -74,7 +77,7 @@ export class Mod2Page extends SixLineHalfPage {
this.children.get("title2").text = "";
} else {
if (this.props.planeSettings.input.externalSwitches.legObsSwitchInstalled) {
this.children.get("title1").text = "PRESS GRPS";
this.children.get("title1").text = "PRESS GPS";
this.children.get("title2").text = "CRS FOR";
} else {
this.children.get("title1").text = "PRESS ENT";
Expand Down
3 changes: 1 addition & 2 deletions kln90b/pages/left/Nav5Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ export class Nav5Page extends SixLineHalfPage {


const activeWaypoint = this.props.memory.navPage.activeWaypoint;
const actIdx = activeWaypoint.getActiveFplIdx();

const legs = this.props.memory.fplPage.flightplans[0].getLegs();

if (activeWaypoint.getActiveFplIdx() !== -1 && !this.props.modeController.isObsModeActive()) {
this.drawFlightplan(ctx, legs, activeWaypoint);
}

if (this.props.modeController.isObsModeActive()) {
if (this.props.modeController.isObsModeActive() && activeWaypoint.getActiveWpt() !== null) {
this.drawObs(ctx, activeWaypoint, this.rangeSetting.get());
} else if (activeWaypoint.isDctNavigation()) {
this.drawDirectTo(ctx, activeWaypoint);
Expand Down
12 changes: 7 additions & 5 deletions kln90b/pages/left/SuperNav5Page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
AirportFacility, AirportRunway,
AirportFacility,
AirportRunway,
Facility,
FacilityType,
FSComponent,
GeoPoint,
ICAO, OneWayRunway,
ICAO,
OneWayRunway,
RunwayUtils,
UnitType, UserSetting,
UnitType,
UserSetting,
VNode,
VorClass,
VorFacility,
Expand Down Expand Up @@ -153,7 +156,6 @@ export class SuperNav5Page extends SevenLinePage {
}

const activeWaypoint = this.props.memory.navPage.activeWaypoint;
const actIdx = activeWaypoint.getActiveFplIdx();

const legs = this.props.memory.fplPage.flightplans[0].getLegs();

Expand All @@ -171,7 +173,7 @@ export class SuperNav5Page extends SevenLinePage {
this.drawAirports(ctx, legs, range)
}

if (this.props.modeController.isObsModeActive()) {
if (this.props.modeController.isObsModeActive() && activeWaypoint.getActiveWpt() !== null) {
this.drawObs(ctx, activeWaypoint, range);
} else if (activeWaypoint.isDctNavigation()) {
this.drawDirectTo(ctx, activeWaypoint);
Expand Down
17 changes: 13 additions & 4 deletions kln90b/pages/right/SelfTestRightPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {AiracPage} from "../AiracPage";
import {VFROnlyPage} from "../VFROnlyPage";
import {format} from "numerable";
import {Inhg} from "../../data/Units";
import {ObswarningPage} from "../ObsWarningPage";


type SelftTestRightPageChildTypes = {
Expand Down Expand Up @@ -148,10 +149,18 @@ export class SelfTestRightPage extends SixLineHalfPage {
page: new VFROnlyPage(this.props),
});
} else {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new AiracPage(this.props),
});
if (this.props.modeController.isObsModeActive()) {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new ObswarningPage(this.props),
});
} else {
this.props.pageManager.setCurrentPage(FourSegmentPage, {
...this.props,
page: new AiracPage(this.props),
});
}

}

}
Expand Down
Loading

0 comments on commit 5006f55

Please sign in to comment.