This repository has been archived on 2021-09-26. You can view files and clone it, but cannot push or open issues or pull requests.
IDG-A32X/Models/Instruments/IESI/IESI.nas

234 lines
7.3 KiB
Text
Raw Normal View History

# A3XX IESI
# Joshua Davidson (it0uchpods)
##############################################
# Copyright (c) Joshua Davidson (it0uchpods) #
##############################################
var IESI = nil;
var IESI_display = nil;
var elapsedtime = 0;
var ASI = 0;
var alt = 0;
var altTens = 0;
2018-09-08 16:27:16 +00:00
# props.nas nodes
var iesi_init = props.globals.initNode("/instrumentation/iesi/iesi-init", 0, "BOOL");
var iesi_time = props.globals.initNode("/instrumentation/iesi/iesi-init-time", 0.0, "DOUBLE");
var iesi_rate = props.globals.getNode("/systems/acconfig/options/iesi-rate");
var et = props.globals.getNode("/sim/time/elapsed-sec");
var aconfig = props.globals.getNode("/systems/acconfig/autoconfig-running");
var dcbat = props.globals.getNode("/systems/electrical/bus/dcbat");
var dc1 = props.globals.getNode("/systems/electrical/bus/dc1");
var dc2 = props.globals.getNode("/systems/electrical/bus/dc2");
var airspeed = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-speed-kt");
var mach = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-mach");
var pitch = props.globals.getNode("/orientation/pitch-deg");
var roll = props.globals.getNode("/orientation/roll-deg");
var skid = props.globals.getNode("/instrumentation/slip-skid-ball/indicated-slip-skid");
var altitude = props.globals.getNode("/instrumentation/altimeter/indicated-altitude-ft");
var altitude_ind = props.globals.getNode("/instrumentation/altimeter/indicated-altitude-ft-pfd");
var altimeter_mode = props.globals.getNode("/modes/altimeter/std");
var qnh_hpa = props.globals.getNode("/instrumentation/altimeter/setting-hpa");
var qnh_inhg = props.globals.getNode("/instrumentation/altimeter/setting-inhg");
var canvas_IESI_base = {
init: func(canvas_group, file) {
var font_mapper = func(family, weight) {
return "LiberationFonts/LiberationSans-Regular.ttf";
};
canvas.parsesvg(canvas_group, file, {"font-mapper": font_mapper});
var svg_keys = me.getKeys();
foreach(var key; svg_keys) {
me[key] = canvas_group.getElementById(key);
var svg_keys = me.getKeys();
foreach (var key; svg_keys) {
me[key] = canvas_group.getElementById(key);
var clip_el = canvas_group.getElementById(key ~ "_clip");
if (clip_el != nil) {
clip_el.setVisible(0);
var tran_rect = clip_el.getTransformedBounds();
var clip_rect = sprintf("rect(%d,%d, %d,%d)",
tran_rect[1], # 0 ys
tran_rect[2], # 1 xe
tran_rect[3], # 2 ye
tran_rect[0]); #3 xs
# coordinates are top,right,bottom,left (ys, xe, ye, xs) ref: l621 of simgear/canvas/CanvasElement.cxx
me[key].set("clip", clip_rect);
me[key].set("clip-frame", canvas.Element.PARENT);
}
}
}
me.AI_horizon_trans = me["AI_horizon"].createTransform();
me.AI_horizon_rot = me["AI_horizon"].createTransform();
me.page = canvas_group;
return me;
},
getKeys: func() {
return [];
},
update: func() {
2018-09-08 16:27:16 +00:00
if (dcbat.getValue() >= 25 or dc1.getValue() >= 25 or dc2.getValue() >= 25) {
IESI.page.show();
IESI.update();
if (aconfig.getValue() != 1 and iesi_init.getValue() != 1) {
iesi_init.setBoolValue(1);
cur_time = et.getValue();
iesi_time.setValue(cur_time);
} else if (aconfig.getValue() == 1 and iesi_init.getValue() != 1) {
iesi_init.setBoolValue(1);
cur_time = et.getValue() - 87;
iesi_time.setValue(cur_time);
}
} else {
2018-09-08 16:27:16 +00:00
iesi_init.setBoolValue(0);
}
2018-09-08 16:27:16 +00:00
if (dcbat.getValue() >= 25 or dc1.getValue() >= 25 or dc2.getValue() >= 25) {
IESI.page.show();
IESI.update();
} else {
IESI.page.hide();
}
},
};
var canvas_IESI = {
new: func(canvas_group, file) {
var m = {parents: [canvas_IESI, canvas_IESI_base]};
m.init(canvas_group, file);
return m;
},
getKeys: func() {
return ["IESI","IESI_Init","ASI_scale","ASI_mach","ASI_mach_decimal","AI_center","AI_horizon","AI_bank","AI_slipskid","ALT_scale","ALT_one","ALT_two","ALT_three","ALT_four","ALT_five","ALT_digits","ALT_tens","ALT_meters","QNH_setting","QNH_std"];
},
update: func() {
2018-09-08 16:27:16 +00:00
if (iesi_time.getValue() + 90 >= et.getValue()) {
me["IESI"].hide();
me["IESI_Init"].show();
} else {
me["IESI_Init"].hide();
me["IESI"].show();
}
# Airspeed
# Subtract 30, since the scale starts at 30, but don"t allow less than 0, or more than 420 situations
2018-09-08 16:27:16 +00:00
if (airspeed.getValue() <= 30) {
ASI = 0;
2018-09-08 16:27:16 +00:00
} else if (airspeed.getValue() >= 420) {
ASI = 390;
} else {
2018-09-08 16:27:16 +00:00
ASI = airspeed.getValue() - 30;
}
me["ASI_scale"].setTranslation(0, ASI * 8.295);
2018-09-08 16:27:16 +00:00
if (mach.getValue() >= 0.5) {
me["ASI_mach_decimal"].show();
me["ASI_mach"].show();
} else {
me["ASI_mach_decimal"].hide();
me["ASI_mach"].hide();
}
2018-09-08 16:27:16 +00:00
if (mach.getValue() >= 0.999) {
me["ASI_mach"].setText("99");
} else {
2018-09-08 16:27:16 +00:00
me["ASI_mach"].setText(sprintf("%2.0f", mach.getValue() * 100));
}
# Attitude
2018-09-08 16:27:16 +00:00
me.AI_horizon_trans.setTranslation(0, pitch.getValue() * 16.74);
me.AI_horizon_rot.setRotation(-roll.getValue() * D2R, me["AI_center"].getCenter());
2018-09-08 16:27:16 +00:00
me["AI_slipskid"].setTranslation(math.clamp(skid.getValue(), -7, 7) * -15, 0);
me["AI_bank"].setRotation(-roll.getValue() * D2R);
# Altitude
2018-09-08 16:27:16 +00:00
me.altOffset = altitude.getValue() / 500 - int(altitude.getValue() / 500);
me.middleAltText = roundaboutAlt(altitude.getValue() / 100);
me.middleAltOffset = nil;
if (me.altOffset > 0.5) {
me.middleAltOffset = -(me.altOffset - 1) * 258.5528;
} else {
me.middleAltOffset = -me.altOffset * 258.5528;
}
me["ALT_scale"].setTranslation(0, -me.middleAltOffset);
me["ALT_scale"].update();
me["ALT_five"].setText(sprintf("%03d", abs(me.middleAltText+10)));
me["ALT_four"].setText(sprintf("%03d", abs(me.middleAltText+5)));
me["ALT_three"].setText(sprintf("%03d", abs(me.middleAltText)));
me["ALT_two"].setText(sprintf("%03d", abs(me.middleAltText-5)));
me["ALT_one"].setText(sprintf("%03d", abs(me.middleAltText-10)));
2018-09-08 16:27:16 +00:00
me["ALT_digits"].setText(sprintf("%s", altitude_ind.getValue()));
me["ALT_meters"].setText(sprintf("%5.0f", altitude.getValue() * 0.3048));
altTens = num(right(sprintf("%02d", altitude_ind.getValue()), 2));
me["ALT_tens"].setTranslation(0, altTens * 3.16);
# QNH
2018-09-08 16:27:16 +00:00
if (altimeter_mode.getValue() == 1) {
me["QNH_setting"].hide();
me["QNH_std"].show();
} else {
2018-09-08 16:27:16 +00:00
me["QNH_setting"].setText(sprintf("%4.0f", qnh_hpa.getValue()) ~ "/" ~ sprintf("%2.2f", qnh_inhg.getValue()));
me["QNH_setting"].show();
me["QNH_std"].hide();
}
},
};
setlistener("sim/signals/fdm-initialized", func {
IESI_display = canvas.new({
"name": "IESI",
"size": [1024, 1024],
"view": [1024, 1024],
"mipmapping": 1
});
IESI_display.addPlacement({"node": "iesi.screen"});
var group_IESI = IESI_display.createGroup();
IESI = canvas_IESI.new(group_IESI, "Aircraft/IDG-A32X/Models/Instruments/IESI/res/iesi.svg");
IESI_update.start();
2018-09-08 16:27:16 +00:00
if (iesi_rate.getValue() > 1) {
rateApply();
}
});
var rateApply = func {
2018-09-08 16:27:16 +00:00
IESI_update.restart(0.07 * iesi_rate.getValue());
}
var IESI_update = maketimer(0.07, func {
canvas_IESI_base.update();
});
var showIESI = func {
var dlg = canvas.Window.new([256, 256], "dialog").set("resize", 1);
dlg.setCanvas(IESI_display);
}
var roundabout = func(x) {
var y = x - int(x);
return y < 0.5 ? int(x) : 1 + int(x);
};
var roundaboutAlt = func(x) {
var y = x * 0.2 - int(x * 0.2);
return y < 0.5 ? 5 * int(x*0.2) : 5 + 5 * int(x*0.2);
};