1
0
Fork 0

Merge branch 'dev' into alignND

This commit is contained in:
legoboyvdlp R 2020-11-07 13:59:49 +00:00
commit 21f8f7ea9c
2 changed files with 236 additions and 235 deletions

View file

@ -2,147 +2,167 @@
# Copyright (c) 2020 Josh Davidson (Octal450)
var IESI = nil;
var IESI_display = nil;
var elapsedtime = 0;
var ASI = 0;
var alt = 0;
var altTens = 0;
var airspeed_act = 0;
var mach_act = 0;
# props.nas nodes
var iesi_init = props.globals.initNode("/instrumentation/iesi/iesi-init", 0, "BOOL");
var iesi_reset = props.globals.initNode("/instrumentation/iesi/att-reset", 0, "DOUBLE");
var iesi_brt = props.globals.getNode("/controls/lighting/DU/iesi", 1);
var iesi_rate = props.globals.getNode("/systems/acconfig/options/iesi-rate", 1);
var et = props.globals.getNode("/sim/time/elapsed-sec", 1);
var aconfig = props.globals.getNode("/systems/acconfig/autoconfig-running", 1);
var airspeed = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-speed-kt", 1);
var mach = props.globals.getNode("/instrumentation/airspeed-indicator/indicated-mach", 1);
var pitch = props.globals.getNode("/instrumentation/iesi/pitch-deg", 1);
var skid = props.globals.getNode("/instrumentation/iesi/slip-skid", 1);
var altitude = props.globals.getNode("/instrumentation/altimeter/indicated-altitude-ft", 1);
var altitude_ind = props.globals.getNode("/instrumentation/altimeter/indicated-altitude-ft-pfd", 1);
var altimeter_mode = props.globals.getNode("/instrumentation/altimeter[0]/std", 1);
var qnh_hpa = props.globals.getNode("/instrumentation/altimeter/setting-hpa", 1);
var qnh_inhg = props.globals.getNode("/instrumentation/altimeter/setting-inhg", 1);
var ASI = 0;
var _showIESI = 0;
var _fast = 0;
var _IESITime = 0;
var canvas_IESI_base = {
init: func(canvas_group, file) {
var font_mapper = func(family, weight) {
var canvas_IESI = {
new: func(svg, name) {
var obj = {parents: [canvas_IESI] };
obj.canvas = canvas.new({
"name": "IESI",
"size": [1024, 1024],
"view": [1024, 1024],
"mipmapping": 1,
});
obj.canvas.addPlacement({"node": "iesi.screen"});
obj.group = obj.canvas.createGroup();
obj.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();
canvas.parsesvg(obj.group, svg, {"font-mapper": obj.font_mapper} );
foreach(var key; obj.getKeys()) {
obj[key] = obj.group.getElementById(key);
var clip_el = obj.group.getElementById(key ~ "_clip");
if (clip_el != nil) {
clip_el.setVisible(0);
var tran_rect = clip_el.getTransformedBounds();
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);
}
var clip_rect = sprintf("rect(%d,%d, %d,%d)",
tran_rect[1],
tran_rect[2],
tran_rect[3],
tran_rect[0]);
obj[key].set("clip", clip_rect);
obj[key].set("clip-frame", canvas.Element.PARENT);
}
}
};
obj.AI_horizon_trans = obj["AI_horizon"].createTransform();
obj.AI_horizon_rot = obj["AI_horizon"].createTransform();
me.AI_horizon_trans = me["AI_horizon"].createTransform();
me.AI_horizon_rot = me["AI_horizon"].createTransform();
obj.middleAltOffset = nil;
obj.update_items = [
props.UpdateManager.FromHashValue("airspeed", nil, func(val) {
# Subtract 30, since the scale starts at 30, but don't allow less than 0, or more than 520 knots
if (val <= 30) {
ASI = 0;
} else if (val >= 520) {
ASI = 490;
} else {
ASI = val - 30;
}
obj["ASI_scale"].setTranslation(0, ASI * 8.295);
}),
props.UpdateManager.FromHashList(["altitude","altitude_ind"], nil, func(val) {
if (val.altitude > 50000) {
val.altitude = 50000;
} elsif (val.altitude < -2000) {
val.altitude = -2000;
}
if (val.altitude < 0) {
obj["negText"].show();
obj["negText2"].show();
} else {
obj["negText"].hide();
obj["negText2"].hide();
}
obj.altOffset = (val.altitude / 500) - int(val.altitude / 500);
obj.middleAltText = roundaboutAlt(val.altitude / 100);
if (obj.altOffset > 0.5) {
obj.middleAltOffset = -(obj.altOffset - 1) * 258.5528;
} else {
obj.middleAltOffset = -obj.altOffset * 258.5528;
}
obj["ALT_scale"].setTranslation(0, -obj.middleAltOffset);
obj["ALT_scale"].update();
obj["ALT_five"].setText(sprintf("%03d", abs(obj.middleAltText+10)));
obj["ALT_four"].setText(sprintf("%03d", abs(obj.middleAltText+5)));
obj["ALT_three"].setText(sprintf("%03d", abs(obj.middleAltText)));
obj["ALT_two"].setText(sprintf("%03d", abs(obj.middleAltText-5)));
obj["ALT_one"].setText(sprintf("%03d", abs(obj.middleAltText-10)));
if (val.altitude < 0 and val.altitude_ind > 20) {
val.altitude_ind = 20;
} elsif (val.altitude > 0 and val.altitude_ind > 500) {
val.altitude_ind = 500;
}
obj["ALT_digits"].setText(sprintf("%s", val.altitude_ind));
obj["ALT_meters"].setText(sprintf("%5.0f", math.round(val.altitude * 0.3048, 10)));
obj.altTens = num(right(sprintf("%02d", val.altitude), 2));
obj["ALT_tens"].setTranslation(0, obj.altTens * 3.16);
}),
props.UpdateManager.FromHashValue("mach", nil, func(val) {
if (val >= 0.5) {
obj._machWasAbove50 = 1;
obj["ASI_mach_decimal"].show();
obj["ASI_mach"].show();
} elsif (val >= 0.45 and obj._machWasAbove50) {
obj["ASI_mach_decimal"].show();
obj["ASI_mach"].show();
} else {
obj._machWasAbove50 = 0;
obj["ASI_mach_decimal"].hide();
obj["ASI_mach"].hide();
}
if (val >= 0.999) {
obj["ASI_mach"].setText("99");
} else {
obj["ASI_mach"].setText(sprintf("%2.0f", val * 100));
}
}),
props.UpdateManager.FromHashValue("pitch", nil, func(val) {
obj.AI_horizon_trans.setTranslation(0, val * 16.74);
}),
props.UpdateManager.FromHashValue("roll", nil, func(val) {
obj.AI_horizon_rot.setRotation(-val * D2R, obj["AI_center"].getCenter());
obj["AI_bank"].setRotation(-val * D2R);
}),
props.UpdateManager.FromHashValue("skid", nil, func(val) {
obj["AI_slipskid"].setTranslation(val, 0);
}),
props.UpdateManager.FromHashList(["altimeter_mode","qnh_hpa","qnh_inhg"], nil, func(val) {
obj.updateQNH(val);
}),
];
_showIESI = 0;
_fast = 0;
_IESITime = 0.0;
obj._cachedInhg = nil;
me.page = canvas_group;
return me;
},
getKeys: func() {
return [];
},
update: func() {
cur_time = et.getValue();
# todo consider relay 7XB for power of DC HOT 1
# todo transient max 0.2s
# todo 20W power consumption
if (iesi_reset.getValue() == 1) {
if (iesi_init.getBoolValue() and _IESITime + 90 >= et.getValue()) {
_fast = 1;
} else {
_fast = 0;
}
iesi_init.setBoolValue(0);
}
if (systems.ELEC.Bus.dcEss.getValue() >= 25 or (systems.ELEC.Bus.dcHot1.getValue() >= 25 and airspeed.getValue() >= 50 and cur_time >= 5)) {
_showIESI = 1;
IESI.update();
if (aconfig.getValue() != 1 and iesi_init.getValue() != 1) {
iesi_init.setBoolValue(1);
if (_fast) {
_IESITime = cur_time - 80;
_fast = 0;
} else {
_IESITime = cur_time;
}
} else if (aconfig.getValue() == 1 and iesi_init.getValue() != 1) {
iesi_init.setBoolValue(1);
_IESITime = cur_time - 87;
}
} else {
_showIESI = 0;
iesi_init.setBoolValue(0);
}
if (_showIESI and iesi_brt.getValue() > 0.01) {
IESI.page.show();
} 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);
m._cachedInhg = -99;
m._machWasAbove50 = 0;
m._roll = 0;
return m;
},
return obj;
},
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","negText","negText2","AI_bank_scale"];
},
update: func() {
if (qnh_inhg.getValue() != me._cachedInhg) {
me._cachedInhg = qnh_inhg.getValue();
me.updateQNH();
update: func(notification) {
if (notification.qnh_inhg != me._cachedInhg) {
me._cachedInhg = notification.qnh_inhg;
me.updateQNH(notification);
}
if (_IESITime + 90 >= et.getValue()) {
me.updatePower(notification);
if (me.group.getVisible() == 0) {
return;
}
if (_IESITime + 90 >= notification.elapsed_seconds) {
me["IESI"].hide();
me["IESI_Init"].show();
return;
@ -151,137 +171,119 @@ var canvas_IESI = {
me["IESI"].show();
}
# Airspeed
# Subtract 30, since the scale starts at 30, but don't allow less than 0, or more than 520 knots
airspeed_act = airspeed.getValue();
mach_act = mach.getValue();
if (airspeed_act <= 30) {
ASI = 0;
} else if (airspeed_act >= 520) {
ASI = 490;
} else {
ASI = airspeed_act - 30;
}
me["ASI_scale"].setTranslation(0, ASI * 8.295);
if (mach_act >= 0.5) {
me._machWasAbove50 = 1;
me["ASI_mach_decimal"].show();
me["ASI_mach"].show();
} elsif (mach_act >= 0.45 and me._machWasAbove50) {
me["ASI_mach_decimal"].show();
me["ASI_mach"].show();
} else {
me._machWasAbove50 = 0;
me["ASI_mach_decimal"].hide();
me["ASI_mach"].hide();
}
if (mach_act >= 0.999) {
me["ASI_mach"].setText("99");
} else {
me["ASI_mach"].setText(sprintf("%2.0f", mach_act * 100));
}
# Attitude
me._roll = pts.Orientation.roll.getValue();
me.AI_horizon_trans.setTranslation(0, pitch.getValue() * 16.74);
me.AI_horizon_rot.setRotation(-me._roll * D2R, me["AI_center"].getCenter());
me["AI_slipskid"].setTranslation(skid.getValue(), 0);
me["AI_bank"].setRotation(-me._roll * D2R);
# Altitude
me.altitude = altitude.getValue();
if (me.altitude > 50000) {
me.altitude = 50000;
} elsif (me.altitude < -2000) {
me.altitude = -2000;
}
if (me.altitude < 0) {
me["negText"].show();
me["negText2"].show();
} else {
me["negText"].hide();
me["negText2"].hide();
}
me.altOffset = me.altitude / 500 - int(me.altitude / 500);
me.middleAltText = roundaboutAlt(me.altitude / 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)));
me.altitudeText = altitude_ind.getValue();
if (me.altitude < 0 and me.altitudeText > 20) {
me.altitudeText = 20;
} elsif (me.altitude > 0 and me.altitudeText > 500) {
me.altitudeText = 500;
}
me["ALT_digits"].setText(sprintf("%s", me.altitudeText));
me["ALT_meters"].setText(sprintf("%5.0f", math.round(me.altitude * 0.3048, 10)));
altTens = num(right(sprintf("%02d", me.altitude), 2));
me["ALT_tens"].setTranslation(0, altTens * 3.16);
foreach(var update_item; me.update_items)
{
update_item.update(notification);
}
},
updateQNH: func() {
if (altimeter_mode.getBoolValue()) {
updateQNH: func(notification) {
if (notification.altimeter_mode) {
me["QNH_setting"].hide();
me["QNH_std"].show();
} else {
me["QNH_setting"].setText(sprintf("%4.0f", qnh_hpa.getValue()) ~ "/" ~ sprintf("%2.2f", qnh_inhg.getValue()));
me["QNH_setting"].setText(sprintf("%4.0f", notification.qnh_hpa) ~ "/" ~ sprintf("%2.2f", notification.qnh_inhg));
me["QNH_setting"].show();
me["QNH_std"].hide();
}
}
},
updatePower: func(notification) {
# todo consider relay 7XB for power of DC HOT 1
# todo transient max 0.2s
# todo 20W power consumption
if (notification.attReset == 1) {
if (notification.iesiInit and _IESITime + 90 >= notification.elapsed_seconds) {
_fast = 1;
} else {
_fast = 0;
}
iesi_init.setBoolValue(0);
}
if (notification.dcEss >= 25 or (notification.dcHot1 >= 25 and notification.airspeed >= 50 and notification.elapsed_seconds >= 5)) {
_showIESI = 1;
if (notification.acconfig != 1 and notification.iesiInit != 1) {
iesi_init.setBoolValue(1);
if (_fast) {
_IESITime = notification.elapsed_seconds - 80;
_fast = 0;
} else {
_IESITime = notification.elapsed_seconds;
}
} else if (notification.acconfig == 1 and notification.iesiInit != 1) {
iesi_init.setBoolValue(1);
_IESITime = notification.elapsed_seconds - 87;
}
} else {
_showIESI = 0;
iesi_init.setBoolValue(0);
}
if (_showIESI and notification.iesiBrt > 0.01) {
me.group.setVisible(1);
} else {
me.group.setVisible(0);
}
},
};
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/A320-family/Models/Instruments/IESI/res/iesi.svg");
IESI.updateQNH();
IESI_update.start();
if (iesi_rate.getValue() > 1) {
rateApply();
}
});
var IESIRecipient =
{
new: func(_ident)
{
var IESIRecipient = emesary.Recipient.new(_ident);
IESIRecipient.MainScreen = nil;
IESIRecipient.Receive = func(notification)
{
if (notification.NotificationType == "FrameNotification")
{
if (IESIRecipient.MainScreen == nil) {
IESIRecipient.MainScreen = canvas_IESI.new("Aircraft/A320-family/Models/Instruments/IESI/res/iesi.svg", "A320 IESI");
}
#if (!math.mod(notifications.frameNotification.FrameCount,2)){
IESIRecipient.MainScreen.update(notification);
#}
return emesary.Transmitter.ReceiptStatus_OK;
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;
};
return IESIRecipient;
},
};
setlistener("/instrumentation/altimeter[0]/std", func() { if (IESI != nil) { IESI.updateQNH(); } }, 0, 0);
var A320IESI = IESIRecipient.new("A320 IESI");
emesary.GlobalTransmitter.Register(A320IESI);
var rateApply = func {
IESI_update.restart(0.05 * iesi_rate.getValue());
var input = {
"acconfig": "/systems/acconfig/autoconfig-running",
"airspeed": "/instrumentation/airspeed-indicator[0]/indicated-speed-kt",
"altitude": "/instrumentation/altimeter/indicated-altitude-ft",
"altitude_ind": "/instrumentation/altimeter/indicated-altitude-ft-pfd",
"altimeter_mode": "/instrumentation/altimeter[0]/std",
"attReset": "/instrumentation/iesi/att-reset",
"dcEss": "/systems/electrical/bus/dc-ess",
"dcHot1": "/systems/electrical/bus/dc-hot-1",
"iesiBrt": "/controls/lighting/DU/iesi",
"iesiInit": "/instrumentation/iesi/iesi-init",
"mach": "/instrumentation/airspeed-indicator/indicated-mach",
"pitch": "/instrumentation/iesi/pitch-deg",
"qnh_hpa": "/instrumentation/altimeter[0]/setting-hpa",
"qnh_inhg": "/instrumentation/altimeter[0]/setting-inhg",
"roll": "/orientation/roll-deg",
"skid": "/instrumentation/iesi/slip-skid",
};
foreach (var name; keys(input)) {
emesary.GlobalTransmitter.NotifyAll(notifications.FrameNotificationAddProperty.new("A320 IESI", name, input[name]));
}
var IESI_update = maketimer(0.05, func {
canvas_IESI_base.update();
});
var showIESI = func {
var dlg = canvas.Window.new([256, 256], "dialog").set("resize", 1);
dlg.setCanvas(IESI_display);
var dlg = canvas.Window.new([512, 512], "dialog").set("resize", 1);
dlg.setCanvas(A320IESI.MainScreen.canvas);
}
setlistener("", func() { if (A320IESI.MainScreen != nil) { A320IESI.MainScreen.updateQNH(notification); } }, 0, 0);
var roundabout = func(x) {
var y = x - int(x);
return y < 0.5 ? int(x) : 1 + int(x);

View file

@ -68,6 +68,7 @@ var canvas_upperECAM = {
obj[key].set("clip-frame", canvas.Element.PARENT);
}
};
canvas.parsesvg(obj.test, "Aircraft/A320-family/Models/Instruments/Common/res/du-test.svg", {"font-mapper": obj.font_mapper} );
foreach(var key; obj.getKeysTest()) {
obj[key] = obj.test.getElementById(key);
@ -451,8 +452,6 @@ var canvas_upperECAM = {
obj["ECAMR7"].setFont("LiberationMonoCustom.ttf");
obj["ECAMR8"].setFont("LiberationMonoCustom.ttf");
obj.page = obj.group;
# cache
obj._cachedN1 = [nil, nil];
obj._cachedN2 = [nil, nil];
@ -1090,7 +1089,7 @@ var showUpperECAM = func {
}
setlistener("/systems/electrical/bus/ac-ess", func() {
A320EWD.MainScreen.powerTransient();
if (A320EWD.MainScreen != nil) { A320EWD.MainScreen.powerTransient() }
}, 0, 0);
var slatLockTimer = maketimer(0.50, func {