Skip to content

Commit

Permalink
fixes #31 The values on the CAL pages are now stored persistently
Browse files Browse the repository at this point in the history
  • Loading branch information
falcon71 committed Jul 3, 2024
1 parent 439244d commit e0fec22
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 109 deletions.
57 changes: 1 addition & 56 deletions kln90b/data/VolatileMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {KLNFacilityLoader} from "./navdata/KLNFacilityLoader";
import {Scanlists} from "./navdata/Scanlist";
import {NearestWpt} from "./navdata/NearestList";
import {KLN90BUserSettings} from "../settings/KLN90BUserSettings";
import {Celsius, Degrees, Fahrenheit, Feet, Inhg, Knots, Mph, NauticalMiles, Seconds} from "./Units";
import {Degrees, Feet, Knots, NauticalMiles, Seconds} from "./Units";
import {Flightplan} from "./flightplan/Flightplan";
import {ActiveWaypoint} from "./flightplan/ActiveWaypoint";
import {TimeStamp} from "./Time";
Expand Down Expand Up @@ -103,24 +103,7 @@ export interface TriPageState {
}

export interface CalPageState {
cal12IndicatedAltitude: Feet;
cal12Barometer: Inhg;
cal1SAT: Celsius;

cal2Cas: Knots,
cal2TAT: Celsius;

cal3Tas: Knots,
cal3HeadingMag: Degrees,

cal4GS: Knots,
cal4Fpm: number,
cal4Angle: number,

cal5TempC: Celsius,
cal5TempF: Fahrenheit,
cal5SpeedKt: Knots,
cal5SpeedMph: Mph,

cal6TimeZ: TimeStamp | null,
cal6FromTimezone: number | null,
Expand Down Expand Up @@ -204,25 +187,6 @@ export class VolatileMemory {
};

public readonly calPage: CalPageState = {
cal12IndicatedAltitude: 0,
cal12Barometer: 0, //https://youtu.be/gjmVrkHTdP0?t=27
cal1SAT: 0,

cal2Cas: 0,
cal2TAT: 0,

cal3Tas: 0,
cal3HeadingMag: 0,

cal4GS: 0,
cal4Fpm: 0,
cal4Angle: 0,

cal5TempC: 0,
cal5TempF: 32,
cal5SpeedKt: 0,
cal5SpeedMph: 0,

cal6TimeZ: null,
cal6FromTimezone: null,
cal6ToTimezone: null,
Expand Down Expand Up @@ -284,25 +248,6 @@ export class VolatileMemory {
this.navPage.navmode = NavMode.ENR_LEG;
this.navPage.userMagvar = 0;

this.calPage.cal12IndicatedAltitude = 0;
this.calPage.cal12Barometer = 0; //https://youtu.be/gjmVrkHTdP0?t=27
this.calPage.cal1SAT = 0;

this.calPage.cal2Cas = 0;

this.calPage.cal2TAT = 0;
this.calPage.cal3Tas = 0;
this.calPage.cal3HeadingMag = 0;

this.calPage.cal4GS = 0;
this.calPage.cal4Fpm = 0;
this.calPage.cal4Angle = 0;

this.calPage.cal5TempC = 0;
this.calPage.cal5TempF = 32;
this.calPage.cal5SpeedKt = 0;
this.calPage.cal5SpeedMph = 0;

this.calPage.cal6TimeZ = null;
this.calPage.cal6FromTimezone = null;
this.calPage.cal6ToTimezone = null;
Expand Down
16 changes: 8 additions & 8 deletions kln90b/pages/left/Cal1Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class Cal1Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal1PageTypes>({
indicated: new AltitudeFieldset(this.props.memory.calPage.cal12IndicatedAltitude, this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.memory.calPage.cal12Barometer, this.props.userSettings, this.setBarometer.bind(this)),
indicated: new AltitudeFieldset(this.props.userSettings.getSetting('cal12IndicatedAltitude').get(), this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.userSettings.getSetting('cal12Barometer').get(), this.props.userSettings, this.setBarometer.bind(this)),
pressure: new AltitudeDisplay(null),
sat: new TempFieldset(this.props.memory.calPage.cal1SAT, this.setTemp.bind(this)),
sat: new TempFieldset(this.props.userSettings.getSetting('cal1SAT').get(), this.setTemp.bind(this)),
density: new AltitudeDisplay(null),
});
this.cursorController = new CursorController(this.children);
Expand All @@ -54,24 +54,24 @@ export class Cal1Page extends SixLineHalfPage {
}

protected redraw() {
const pressureAlt = indicatedAlt2PressureAlt(this.props.memory.calPage.cal12IndicatedAltitude, this.props.memory.calPage.cal12Barometer);
const pressureAlt = indicatedAlt2PressureAlt(this.props.userSettings.getSetting('cal12IndicatedAltitude').get(), this.props.userSettings.getSetting('cal12Barometer').get());
this.children.get("pressure").altitude = pressureAlt;
this.children.get("density").altitude = pressureAlt2DensityAlt(pressureAlt, this.props.memory.calPage.cal1SAT);
this.children.get("density").altitude = pressureAlt2DensityAlt(pressureAlt, this.props.userSettings.getSetting('cal1SAT').get());

}

private setIndicatedAltitude(alt: Feet): void {
this.props.memory.calPage.cal12IndicatedAltitude = alt;
this.props.userSettings.getSetting('cal12IndicatedAltitude').set(alt);
this.requiresRedraw = true;
}

private setBarometer(baro: Inhg): void {
this.props.memory.calPage.cal12Barometer = baro;
this.props.userSettings.getSetting('cal12Barometer').set(baro);
this.requiresRedraw = true;
}

private setTemp(temp: Celsius): void {
this.props.memory.calPage.cal1SAT = temp;
this.props.userSettings.getSetting('cal1SAT').set(temp);
this.requiresRedraw = true;
}
}
24 changes: 12 additions & 12 deletions kln90b/pages/left/Cal2Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export class Cal2Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal2PageTypes>({
cas: new SpeedFieldset(this.props.memory.calPage.cal2Cas, this.setCas.bind(this)),
indicated: new AltitudeFieldset(this.props.memory.calPage.cal12IndicatedAltitude, this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.memory.calPage.cal12Barometer, this.props.userSettings, this.setBarometer.bind(this)),
tat: new TempFieldset(this.props.memory.calPage.cal2TAT, this.setTemp.bind(this)),
cas: new SpeedFieldset(this.props.userSettings.getSetting('cal2Cas').get(), this.setCas.bind(this)),
indicated: new AltitudeFieldset(this.props.userSettings.getSetting('cal12IndicatedAltitude').get(), this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.userSettings.getSetting('cal12Barometer').get(), this.props.userSettings, this.setBarometer.bind(this)),
tat: new TempFieldset(this.props.userSettings.getSetting('cal2TAT').get(), this.setTemp.bind(this)),
tas: new SpeedDisplay(null),
});
this.cursorController = new CursorController(this.children);
Expand All @@ -57,36 +57,36 @@ export class Cal2Page extends SixLineHalfPage {
protected redraw(): void {
//we do actually want set the CAL 3 page, when the page is only viewed and no values are changed. This is based on the KLN-89 trainer
const tas = this.calculateTas();
this.props.memory.calPage.cal3Tas = tas;
this.props.userSettings.getSetting('cal3Tas').set(tas);
this.children.get("tas").speed = tas;
}

private setCas(cas: Knots): void {
this.props.memory.calPage.cal2Cas = cas;
this.props.userSettings.getSetting('cal2Cas').set(cas);
this.requiresRedraw = true;
}

private setIndicatedAltitude(alt: Feet): void {
this.props.memory.calPage.cal12IndicatedAltitude = alt;
this.props.userSettings.getSetting('cal12IndicatedAltitude').set(alt);
this.requiresRedraw = true;
}

private setBarometer(baro: Inhg): void {
this.props.memory.calPage.cal12Barometer = baro;
this.props.userSettings.getSetting('cal12Barometer').set(baro);
this.requiresRedraw = true;
}

private setTemp(temp: Celsius): void {
this.props.memory.calPage.cal2TAT = temp;
this.props.userSettings.getSetting('cal2TAT').set(temp);
this.requiresRedraw = true;
}

private calculateTas(): Knots {
const pressureAlt = indicatedAlt2PressureAlt(this.props.memory.calPage.cal12IndicatedAltitude, this.props.memory.calPage.cal12Barometer);
const mach = cas2Mach(this.props.memory.calPage.cal2Cas, pressureAlt);
const pressureAlt = indicatedAlt2PressureAlt(this.props.userSettings.getSetting('cal12IndicatedAltitude').get(), this.props.userSettings.getSetting('cal12Barometer').get());
const mach = cas2Mach(this.props.userSettings.getSetting('cal2Cas').get(), pressureAlt);
let tas = 0;
if (!isNaN(mach)) {
tas = mach2Tas(mach, this.props.memory.calPage.cal2TAT);
tas = mach2Tas(mach, this.props.userSettings.getSetting('cal2TAT').get());
}
return tas;
}
Expand Down
14 changes: 7 additions & 7 deletions kln90b/pages/left/Cal3Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class Cal3Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal3PageTypes>({
tas: new SpeedFieldset(this.props.memory.calPage.cal3Tas, this.setTas.bind(this)),
hdg: new BearingFieldset(this.props.memory.calPage.cal3HeadingMag, this.setHeading.bind(this)),
tas: new SpeedFieldset(this.props.userSettings.getSetting('cal3Tas').get(), this.setTas.bind(this)),
hdg: new BearingFieldset(this.props.userSettings.getSetting('cal3HeadingMag').get(), this.setHeading.bind(this)),
windLabel: new TextDisplay("HDWND"),
windComponent: new SpeedDisplay(null),
windDir: new BearingDisplay(null),
Expand Down Expand Up @@ -81,11 +81,11 @@ export class Cal3Page extends SixLineHalfPage {
if (this.props.planeSettings.input.headingInput) {
hdgTrue = this.props.magvar.magToTrue(this.props.sensors.in.headingGyro!);
} else {
hdgTrue = this.props.magvar.magToTrue(this.props.memory.calPage.cal3HeadingMag);
hdgTrue = this.props.magvar.magToTrue(this.props.userSettings.getSetting('cal3HeadingMag').get());
}

const windSpeed = calculateWindspeed(this.props.memory.calPage.cal3Tas, this.props.sensors.in.gps.groundspeed, hdgTrue, this.props.sensors.in.gps.trackTrue);
const windDir = calculateWindDirection(this.props.memory.calPage.cal3Tas, this.props.sensors.in.gps.groundspeed, hdgTrue, this.props.sensors.in.gps.trackTrue);
const windSpeed = calculateWindspeed(this.props.userSettings.getSetting('cal3Tas').get(), this.props.sensors.in.gps.groundspeed, hdgTrue, this.props.sensors.in.gps.trackTrue);
const windDir = calculateWindDirection(this.props.userSettings.getSetting('cal3Tas').get(), this.props.sensors.in.gps.groundspeed, hdgTrue, this.props.sensors.in.gps.trackTrue);
const headWind = calculateHeadwind(windSpeed, windDir, hdgTrue);

this.children.get("windLabel").text = headWind >= 0 ? "HDWND" : "TLWND";
Expand All @@ -95,12 +95,12 @@ export class Cal3Page extends SixLineHalfPage {
}

private setTas(tas: Knots): void {
this.props.memory.calPage.cal3Tas = tas;
this.props.userSettings.getSetting('cal3Tas').set(tas);
this.requiresRedraw = true;
}

private setHeading(heading: Degrees): void {
this.props.memory.calPage.cal3HeadingMag = heading;
this.props.userSettings.getSetting('cal3HeadingMag').set(heading);
this.requiresRedraw = true;
}

Expand Down
26 changes: 13 additions & 13 deletions kln90b/pages/left/Cal4Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class Cal4Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal4PageTypes>({
gs: new SpeedFieldset(this.props.memory.calPage.cal4GS, this.setGS.bind(this)),
fpm: new FpmFieldset(this.props.memory.calPage.cal4Fpm, this.setFpm.bind(this)),
angle: new VnavAngleFieldset(this.props.memory.calPage.cal4Angle, this.setAngle.bind(this)),
gs: new SpeedFieldset(this.props.userSettings.getSetting('cal4GS').get(), this.setGS.bind(this)),
fpm: new FpmFieldset(this.props.userSettings.getSetting('cal4Fpm').get(), this.setFpm.bind(this)),
angle: new VnavAngleFieldset(this.props.userSettings.getSetting('cal4Angle').get(), this.setAngle.bind(this)),
});

this.cursorController = new CursorController(this.children);
Expand All @@ -50,30 +50,30 @@ export class Cal4Page extends SixLineHalfPage {
}

private setGS(gs: Knots): void {
this.props.memory.calPage.cal4GS = gs;
this.props.userSettings.getSetting('cal4GS').set(gs);
let angle = 0;
if (gs > 0) {
angle = Math.atan(this.props.memory.calPage.cal4Fpm / UnitType.KNOT.convertTo(gs, UnitType.FPM)) * Avionics.Utils.RAD2DEG;
angle = Math.atan(this.props.userSettings.getSetting('cal4Fpm').get() / UnitType.KNOT.convertTo(gs, UnitType.FPM)) * Avionics.Utils.RAD2DEG;
}
this.props.memory.calPage.cal4Angle = angle;
this.props.userSettings.getSetting('cal4Angle').set(angle);
this.children.get("angle").setValue(angle);
}

private setFpm(fpm: number): void {
this.props.memory.calPage.cal4Fpm = fpm;
this.props.userSettings.getSetting('cal4Fpm').set(fpm);
let angle = 0;
if (this.props.memory.calPage.cal4GS > 0) {
angle = Math.atan(fpm / UnitType.KNOT.convertTo(this.props.memory.calPage.cal4GS, UnitType.FPM)) * Avionics.Utils.RAD2DEG;
if (this.props.userSettings.getSetting('cal4GS').get() > 0) {
angle = Math.atan(fpm / UnitType.KNOT.convertTo(this.props.userSettings.getSetting('cal4GS').get(), UnitType.FPM)) * Avionics.Utils.RAD2DEG;
}
this.props.memory.calPage.cal4Angle = angle;
this.props.userSettings.getSetting('cal4Angle').set(angle);
this.children.get("angle").setValue(angle);
}

private setAngle(angle: number): void {
this.props.memory.calPage.cal4Angle = angle;
const fpm = Math.round(UnitType.KNOT.convertTo(this.props.memory.calPage.cal4GS, UnitType.FPM) * Math.tan(angle * Avionics.Utils.DEG2RAD) / 100) * 100;
this.props.userSettings.getSetting('cal4Angle').set(angle);
const fpm = Math.round(UnitType.KNOT.convertTo(this.props.userSettings.getSetting('cal4GS').get(), UnitType.FPM) * Math.tan(angle * Avionics.Utils.DEG2RAD) / 100) * 100;

this.props.memory.calPage.cal4Fpm = fpm;
this.props.userSettings.getSetting('cal4Fpm').set(fpm);
this.children.get("fpm").setFpm(fpm);

}
Expand Down
24 changes: 12 additions & 12 deletions kln90b/pages/left/Cal5Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export class Cal5Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal5PageTypes>({
tempC: new TempFieldset(this.props.memory.calPage.cal5TempC, this.setTempC.bind(this)),
tempF: new TempFieldset(this.props.memory.calPage.cal5TempF, this.setTempF.bind(this)),
speedKt: new SpeedFieldset(this.props.memory.calPage.cal5SpeedKt, this.setSpeedKt.bind(this)),
speedMph: new SpeedFieldset(this.props.memory.calPage.cal5SpeedMph, this.setSpeedMph.bind(this)),
tempC: new TempFieldset(this.props.userSettings.getSetting('cal5TempC').get(), this.setTempC.bind(this)),
tempF: new TempFieldset(this.props.userSettings.getSetting('cal5TempF').get(), this.setTempF.bind(this)),
speedKt: new SpeedFieldset(this.props.userSettings.getSetting('cal5SpeedKt').get(), this.setSpeedKt.bind(this)),
speedMph: new SpeedFieldset(this.props.userSettings.getSetting('cal5SpeedMph').get(), this.setSpeedMph.bind(this)),
});

this.cursorController = new CursorController(this.children);
Expand All @@ -52,30 +52,30 @@ export class Cal5Page extends SixLineHalfPage {
}

private setTempC(tempC: Celsius): void {
this.props.memory.calPage.cal5TempC = tempC;
this.props.userSettings.getSetting('cal5TempC').set(tempC);
const tempF = UnitType.CELSIUS.convertTo(tempC, UnitType.FAHRENHEIT);
this.props.memory.calPage.cal5TempF = tempF;
this.props.userSettings.getSetting('cal5TempF').set(tempF);
this.children.get("tempF").setTemp(tempF);
}

private setTempF(tempF: Celsius): void {
this.props.memory.calPage.cal5TempF = tempF;
this.props.userSettings.getSetting('cal5TempF').set(tempF);
const tempC = UnitType.FAHRENHEIT.convertTo(tempF, UnitType.CELSIUS);
this.props.memory.calPage.cal5TempC = tempC;
this.props.userSettings.getSetting('cal5TempC').set(tempC);
this.children.get("tempC").setTemp(tempC);
}

private setSpeedKt(speedKt: Knots): void {
this.props.memory.calPage.cal5SpeedKt = speedKt;
this.props.userSettings.getSetting('cal5SpeedKt').set(speedKt);
const speedMph = UnitType.KNOT.convertTo(speedKt, UnitType.MPH);
this.props.memory.calPage.cal5SpeedMph = speedMph;
this.props.userSettings.getSetting('cal5SpeedMph').set(speedMph);
this.children.get("speedMph").setSpeed(speedMph);
}

private setSpeedMph(speedMph: Mph): void {
this.props.memory.calPage.cal5SpeedMph = speedMph;
this.props.userSettings.getSetting('cal5SpeedMph').set(speedMph);
const speedKt = UnitType.MPH.convertTo(speedMph, UnitType.KNOT);
this.props.memory.calPage.cal5SpeedKt = speedKt;
this.props.userSettings.getSetting('cal5SpeedKt').set(speedKt);
this.children.get("speedKt").setSpeed(speedKt);
}
}
Loading

0 comments on commit e0fec22

Please sign in to comment.