Skip to content

Commit

Permalink
fixes #33 Reworked propagation of values on the calculator pages base…
Browse files Browse the repository at this point in the history
…d on the KLN-89 trainer
  • Loading branch information
falcon71 committed Jul 2, 2024
1 parent 2b06e54 commit 439244d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
18 changes: 6 additions & 12 deletions kln90b/data/VolatileMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ export interface TriPageState {
}

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

cal2Cas: Knots,
cal2IndicatedAltitude: Feet;
cal2Barometer: Inhg;
cal2TAT: Celsius;

cal3Tas: Knots,
Expand Down Expand Up @@ -206,13 +204,11 @@ export class VolatileMemory {
};

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

cal2Cas: 0,
cal2IndicatedAltitude: 0,
cal2Barometer: 0,
cal2TAT: 0,

cal3Tas: 0,
Expand Down Expand Up @@ -288,13 +284,11 @@ export class VolatileMemory {
this.navPage.navmode = NavMode.ENR_LEG;
this.navPage.userMagvar = 0;

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

this.calPage.cal2Cas = 0;
this.calPage.cal2IndicatedAltitude = 0;
this.calPage.cal2Barometer = 0;

this.calPage.cal2TAT = 0;
this.calPage.cal3Tas = 0;
Expand Down
12 changes: 5 additions & 7 deletions kln90b/pages/left/Cal1Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class Cal1Page extends SixLineHalfPage {
super(props);

this.children = new UIElementChildren<Cal1PageTypes>({
indicated: new AltitudeFieldset(this.props.memory.calPage.cal1IndicatedAltitude, this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.memory.calPage.cal1Barometer, this.props.userSettings, this.setBarometer.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)),
pressure: new AltitudeDisplay(null),
sat: new TempFieldset(this.props.memory.calPage.cal1SAT, this.setTemp.bind(this)),
density: new AltitudeDisplay(null),
Expand All @@ -54,21 +54,19 @@ export class Cal1Page extends SixLineHalfPage {
}

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

}

private setIndicatedAltitude(alt: Feet): void {
this.props.memory.calPage.cal1IndicatedAltitude = alt;
this.props.memory.calPage.cal2IndicatedAltitude = alt;
this.props.memory.calPage.cal12IndicatedAltitude = alt;
this.requiresRedraw = true;
}

private setBarometer(baro: Inhg): void {
this.props.memory.calPage.cal1Barometer = baro;
this.props.memory.calPage.cal2Barometer = baro;
this.props.memory.calPage.cal12Barometer = baro;
this.requiresRedraw = true;
}

Expand Down
35 changes: 13 additions & 22 deletions kln90b/pages/left/Cal2Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class Cal2Page extends SixLineHalfPage {

this.children = new UIElementChildren<Cal2PageTypes>({
cas: new SpeedFieldset(this.props.memory.calPage.cal2Cas, this.setCas.bind(this)),
indicated: new AltitudeFieldset(this.props.memory.calPage.cal2IndicatedAltitude, this.setIndicatedAltitude.bind(this)),
baro: BaroFieldsetFactory.createBaroFieldSet(this.props.memory.calPage.cal2Barometer, this.props.userSettings, this.setBarometer.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)),
tas: new SpeedDisplay(null),
});
Expand All @@ -55,43 +55,34 @@ export class Cal2Page extends SixLineHalfPage {
}

protected redraw(): void {
//we don't set the CAL 3 page, when the page is only viewed and no values are changed
this.children.get("tas").speed = this.calculateTas();
//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.children.get("tas").speed = tas;
}

private setCas(cas: Knots): void {
this.props.memory.calPage.cal2Cas = cas;
const tas = this.calculateTas();
this.props.memory.calPage.cal3Tas = tas;
this.children.get("tas").speed = tas;
this.requiresRedraw = true;
}

private setIndicatedAltitude(alt: Feet): void {
this.props.memory.calPage.cal2IndicatedAltitude = alt;

const tas = this.calculateTas();
this.props.memory.calPage.cal3Tas = tas;
this.children.get("tas").speed = tas;
this.props.memory.calPage.cal12IndicatedAltitude = alt;
this.requiresRedraw = true;
}

private setBarometer(baro: Inhg): void {
this.props.memory.calPage.cal2Barometer = baro;

const tas = this.calculateTas();
this.props.memory.calPage.cal3Tas = tas;
this.children.get("tas").speed = tas;
this.props.memory.calPage.cal12Barometer = baro;
this.requiresRedraw = true;
}

private setTemp(temp: Celsius): void {
this.props.memory.calPage.cal2TAT = temp;

const tas = this.calculateTas();
this.props.memory.calPage.cal3Tas = tas;
this.children.get("tas").speed = tas;
this.requiresRedraw = true;
}

private calculateTas(): Knots {
const pressureAlt = indicatedAlt2PressureAlt(this.props.memory.calPage.cal2IndicatedAltitude, this.props.memory.calPage.cal2Barometer);
const pressureAlt = indicatedAlt2PressureAlt(this.props.memory.calPage.cal12IndicatedAltitude, this.props.memory.calPage.cal12Barometer);
const mach = cas2Mach(this.props.memory.calPage.cal2Cas, pressureAlt);
let tas = 0;
if (!isNaN(mach)) {
Expand Down

0 comments on commit 439244d

Please sign in to comment.