1
0
Fork 0

IESI: make certain optimizations (average update loop time is now approximately 0.18ms

This commit is contained in:
Jonathan Redpath 2022-01-15 14:03:14 +00:00
parent a801ea9b4a
commit 8f07302410
2 changed files with 106 additions and 85 deletions

View file

@ -49,52 +49,41 @@ var canvas_IESI = {
obj.AI_horizon_trans = obj["AI_horizon"].createTransform(); obj.AI_horizon_trans = obj["AI_horizon"].createTransform();
obj.AI_horizon_rot = obj["AI_horizon"].createTransform(); obj.AI_horizon_rot = obj["AI_horizon"].createTransform();
obj._aiCenter = obj["AI_center"].getCenter();
obj._cachedInhg = nil; obj._cachedInhg = nil;
obj._excessMotion = 0; obj._cachedMode = nil;
obj._fast = 0; obj._canReset = 0;
obj._excessMotionInInit = 0;
obj._fastInit = 0;
obj._IESITime = 0; obj._IESITime = 0;
obj._showIESI = 0; obj._isNegativeAlt = 0;
obj.ASI = 0; obj._middleAltOffset = nil;
obj.canReset = 0; obj._powerResult = 0;
obj.isNegativeAlt = 0; obj._roll = 0;
obj.middleAltOffset = nil;
obj.update_items = [ obj.update_items = [
props.UpdateManager.FromHashValue("airspeed", nil, func(val) { 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 obj["ASI_scale"].setTranslation(0, math.clamp(val - 30, 0, 490) * 8.295);
if (val <= 30) {
obj.ASI = 0;
} else if (val >= 520) {
obj.ASI = 490;
} else {
obj.ASI = val - 30;
}
obj["ASI_scale"].setTranslation(0, obj.ASI * 8.295);
}), }),
props.UpdateManager.FromHashList(["altitude","altitude_ind"], nil, func(val) { props.UpdateManager.FromHashList(["altitude","altitude_ind"], nil, func(val) {
if (val.altitude > 50000) { val.altitude = math.clamp(val.altitude, -2000, 50000);
val.altitude = 50000;
} elsif (val.altitude < -2000) {
val.altitude = -2000;
}
if (val.altitude < 0) { if (val.altitude < 0) {
obj["negText"].show(); obj["negText"].show();
obj.isNegativeAlt = 1; obj._isNegativeAlt = 1;
} else { } else {
obj["negText"].hide(); obj["negText"].hide();
obj.isNegativeAlt = 0; obj._isNegativeAlt = 0;
} }
obj.altOffset = (val.altitude / 500) - int(val.altitude / 500); obj.altOffset = (val.altitude / 500) - int(val.altitude / 500);
obj.middleAltText = roundaboutAlt(val.altitude / 100); obj.middleAltText = roundaboutAlt(val.altitude / 100);
if (obj.altOffset > 0.5) { if (obj.altOffset > 0.5) {
obj.middleAltOffset = -(obj.altOffset - 1) * 258.5528; obj._middleAltOffset = -(obj.altOffset - 1) * 258.5528;
} else { } else {
obj.middleAltOffset = -obj.altOffset * 258.5528; obj._middleAltOffset = -obj.altOffset * 258.5528;
} }
obj["ALT_scale"].setTranslation(0, -obj.middleAltOffset); obj["ALT_scale"].setTranslation(0, -obj._middleAltOffset);
obj["ALT_scale"].update(); obj["ALT_scale"].update();
obj["ALT_five"].setText(sprintf("%03d", abs(obj.middleAltText+10))); obj["ALT_five"].setText(sprintf("%03d", abs(obj.middleAltText+10)));
obj["ALT_four"].setText(sprintf("%03d", abs(obj.middleAltText+5))); obj["ALT_four"].setText(sprintf("%03d", abs(obj.middleAltText+5)));
@ -114,20 +103,16 @@ var canvas_IESI = {
obj.altTens = num(right(sprintf("%02d", val.altitude), 2)); obj.altTens = num(right(sprintf("%02d", val.altitude), 2));
obj["ALT_tens"].setTranslation(0, obj.altTens * 3.16); obj["ALT_tens"].setTranslation(0, obj.altTens * 3.16);
}), }),
props.UpdateManager.FromHashValue("mach", nil, func(val) { props.UpdateManager.FromHashValue("showMach", nil, func(val) {
if (val >= 0.5) { if (val) {
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_decimal"].show();
obj["ASI_mach"].show(); obj["ASI_mach"].show();
} else { } else {
obj._machWasAbove50 = 0;
obj["ASI_mach_decimal"].hide(); obj["ASI_mach_decimal"].hide();
obj["ASI_mach"].hide(); obj["ASI_mach"].hide();
} }
}),
props.UpdateManager.FromHashValue("mach", nil, func(val) {
if (val >= 0.999) { if (val >= 0.999) {
obj["ASI_mach"].setText("99"); obj["ASI_mach"].setText("99");
} else { } else {
@ -138,8 +123,9 @@ var canvas_IESI = {
obj.AI_horizon_trans.setTranslation(0, val * 16.74); obj.AI_horizon_trans.setTranslation(0, val * 16.74);
}), }),
props.UpdateManager.FromHashValue("roll", nil, func(val) { props.UpdateManager.FromHashValue("roll", nil, func(val) {
obj.AI_horizon_rot.setRotation(-val * D2R, obj["AI_center"].getCenter()); obj._roll = -val * D2R;
obj["AI_bank"].setRotation(-val * D2R); obj.AI_horizon_rot.setRotation(obj._roll, obj._aiCenter);
obj["AI_bank"].setRotation(obj._roll);
}), }),
props.UpdateManager.FromHashValue("skid", nil, func(val) { props.UpdateManager.FromHashValue("skid", nil, func(val) {
if (abs(val) >= 84.99) { if (abs(val) >= 84.99) {
@ -149,9 +135,6 @@ var canvas_IESI = {
obj["AI_slipskid"].show(); obj["AI_slipskid"].show();
} }
}), }),
props.UpdateManager.FromHashList(["altimeter_mode","qnh_hpa","qnh_inhg"], nil, func(val) {
obj.updateQNH(val);
}),
]; ];
return obj; return obj;
}, },
@ -159,22 +142,21 @@ var canvas_IESI = {
return ["IESI","IESI_Init","attRst","attRstRect","att90s","ATTflag","ATTflag_rect","ATTflag_text","ALTwarn","SPDwarn","ASI_scale","ASI_mach","ASI_mach_decimal","AI_center","AI_index","AI_horizon","AI_sky_bank","AI_bank","AI_bank_center","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","metricM","metricBox"]; return ["IESI","IESI_Init","attRst","attRstRect","att90s","ATTflag","ATTflag_rect","ATTflag_text","ALTwarn","SPDwarn","ASI_scale","ASI_mach","ASI_mach_decimal","AI_center","AI_index","AI_horizon","AI_sky_bank","AI_bank","AI_bank_center","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","metricM","metricBox"];
}, },
update: func(notification) { update: func(notification) {
if (notification.qnh_inhg != me._cachedInhg) { me._powerResult = me.updatePower(notification);
me._cachedInhg = notification.qnh_inhg; if (me._powerResult == 0) { return; }
me.updateQNH(notification);
}
me.updatePower(notification); if (notification.qnh_inhg != me._cachedInhg or notification.altimeter_mode != me._cachedMode) {
if (me.group.getVisible() == 0) { me._cachedInhg = notification.qnh_inhg;
return; me._cachedMode = notification.altimeter_mode;
me.updateQNH(notification);
} }
if (me._IESITime + 90 >= notification.elapsedTime) { if (me._IESITime + 90 >= notification.elapsedTime) {
if (notification.groundspeed > 2) { if (notification.groundspeed > 2) {
me._excessMotion = 1; me._excessMotionInInit = 1;
} }
if (me._fast) { if (me._fastInit) {
me["IESI"].show(); me["IESI"].show();
me["IESI_Init"].hide(); me["IESI_Init"].hide();
me["AI_bank"].hide(); me["AI_bank"].hide();
@ -203,7 +185,7 @@ var canvas_IESI = {
me["metricM"].show(); me["metricM"].show();
me["metricBox"].show(); me["metricBox"].show();
if (me.isNegativeAlt) { if (me._isNegativeAlt) {
me["negText2"].show(); me["negText2"].show();
} else { } else {
me["negText2"].hide(); me["negText2"].hide();
@ -215,7 +197,7 @@ var canvas_IESI = {
me["negText2"].hide(); me["negText2"].hide();
} }
if (!me._excessMotion) { if (!me._excessMotionInInit) {
me["IESI_Init"].hide(); me["IESI_Init"].hide();
me["IESI"].show(); me["IESI"].show();
me["AI_bank"].show(); me["AI_bank"].show();
@ -260,57 +242,41 @@ var canvas_IESI = {
} else { } else {
me["QNH_setting"].setText(sprintf("%4.0f", notification.qnh_hpa)); me["QNH_setting"].setText(sprintf("%4.0f", notification.qnh_hpa));
} }
me["QNH_setting"].show();
me["QNH_std"].hide(); me["QNH_std"].hide();
me["QNH_setting"].show();
} }
}, },
_transientVar: 0,
updatePower: func(notification) { updatePower: func(notification) {
# todo 20W power consumption if (notification.attReset == 1 and me._canReset) {
if (notification.attReset == 1 and me.canReset) { me._canReset = 0;
me.canReset = 0; me._excessMotionInInit = 0;
me._excessMotion = 0; me._fastInit = 1;
me._fast = 1;
iesi_init.setBoolValue(0); iesi_init.setBoolValue(0);
} else if (me._IESITime + 90 < notification.elapsedTime and notification.iesiInit and !me.canReset) { } else if (me._IESITime + 90 < notification.elapsedTime and notification.iesiInit and !me._canReset) {
me.canReset = 1; me._canReset = 1;
} }
if (notification.dcEss >= 25 or (notification.relay7XB and notification.dcHot1703 >= 25)) { if (notification.iesiPowered) {
me._showIESI = 1;
if (notification.acconfig != 1 and notification.iesiInit != 1) { if (notification.acconfig != 1 and notification.iesiInit != 1) {
iesi_init.setBoolValue(1); iesi_init.setBoolValue(1);
if (me._fast) { me._IESITime = notification.elapsedTime - (me._fastInit ? 80 : 0);
me._IESITime = notification.elapsedTime - 80;
} else {
me._IESITime = notification.elapsedTime;
}
} else if (notification.acconfig == 1 and notification.iesiInit != 1) { } else if (notification.acconfig == 1 and notification.iesiInit != 1) {
iesi_init.setBoolValue(1); iesi_init.setBoolValue(1);
me._IESITime = notification.elapsedTime - 87; me._IESITime = notification.elapsedTime - 87;
} }
} elsif (notification.iesiInit) { } elsif (notification.iesiInit) {
if (!me._transientVar) { me._canReset = 0;
me._transientVar = 1; me._excessMotionInInit = 0;
settimer(func() { me._fastInit = 0;
if (systems.ELEC.Bus.dcEss.getValue() >= 25 or (systems.ELEC.Bus.dcHot1703.getValue() >= 25 and systems.ELEC.Relay.relay7XB.getValue())) { iesi_init.setBoolValue(0);
me._transientVar = 0;
} else {
me.canReset = 0;
me._excessMotion = 0;
me._fast = 0;
me._showIESI = 0;
me._transientVar = 0;
iesi_init.setBoolValue(0);
}
}, 0.2); # 200ms delay power transients
}
} }
if (me._showIESI and notification.iesiBrt > 0.01) { if (notification.iesiPowered and notification.iesiBrt > 0.01) {
me.group.setVisible(1); me.group.setVisible(1);
return 1;
} else { } else {
me.group.setVisible(0); me.group.setVisible(0);
return 0;
} }
}, },
}; };
@ -352,13 +318,14 @@ var input = {
"attReset": "/instrumentation/iesi/att-reset", "attReset": "/instrumentation/iesi/att-reset",
"iesiBrt": "/controls/lighting/DU/iesi", "iesiBrt": "/controls/lighting/DU/iesi",
"iesiInit": "/instrumentation/iesi/iesi-init", "iesiInit": "/instrumentation/iesi/iesi-init",
"iesiPowered": "/instrumentation/iesi/power/power-on",
"mach": "/instrumentation/airspeed-indicator/indicated-mach", "mach": "/instrumentation/airspeed-indicator/indicated-mach",
"pitch": "/instrumentation/iesi/pitch-deg", "pitch": "/instrumentation/iesi/pitch-deg",
"qnh_hpa": "/instrumentation/altimeter[6]/setting-hpa", "qnh_hpa": "/instrumentation/altimeter[6]/setting-hpa",
"qnh_inhg": "/instrumentation/altimeter[6]/setting-inhg", "qnh_inhg": "/instrumentation/altimeter[6]/setting-inhg",
"roll": "/orientation/roll-deg", "roll": "/orientation/roll-deg",
"skid": "/instrumentation/iesi/slip-skid", "skid": "/instrumentation/iesi/slip-skid",
"relay7XB": "/systems/electrical/sources/si-1/inverter-control/relay-7xb", "showMach": "/instrumentation/iesi/display/show-mach",
}; };
foreach (var name; keys(input)) { foreach (var name; keys(input)) {

View file

@ -502,7 +502,7 @@
</channel> </channel>
<channel name="FMGC"> <channel name="FMGC" execrate="8">
<fcs_function name="/FMGC/internal/kts-to-mach-factor"> <fcs_function name="/FMGC/internal/kts-to-mach-factor">
<function> <function>
@ -524,4 +524,58 @@
</channel> </channel>
<channel name="IESI" execrate="8">
<switch name="/instrumentation/iesi/display/show-mach">
<default value="0"/>
<test logic="OR" value="1">
/instrumentation/airspeed-indicator/indicated-mach ge 0.5
</test>
<test logic="AND" value="1">
/instrumentation/airspeed-indicator/indicated-mach ge 0.45
/instrumentation/iesi/display/show-mach eq 1
</test>
</switch>
<switch name="/instrumentation/iesi/power/power-command">
<default value="0"/>
<test logic="OR" value="1">
/systems/electrical/bus/dc-ess ge 25
<test logic="AND">
/systems/electrical/sources/si-1/inverter-control/relay-7xb ne 0
/systems/electrical/bus/sub-bus/dc-hot-1-703 ge 25
</test>
</test>
</switch>
<actuator name="/instrumentation/iesi/power/power-transient-timer">
<input>/instrumentation/iesi/power/power-command</input>
<rate_limit sense="decr">5</rate_limit>
<rate_limit sene="incr">100</rate_limit>
</actuator>
<switch name="/instrumentation/iesi/power/power-on">
<default value="0"/>
<test logic="OR" value="1">
/instrumentation/iesi/power/power-transient-timer ne 0
</test>
</switch>
<fcs_function name="/instrumentation/iesi/power/power-consumption-w">
<function>
<sum>
<product>
<value>16</value>
<property>/instrumentation/iesi/power/power-on</property>
</product>
<product>
<value>4</value>
<property>/controls/lighting/DU/iesi</property>
</product>
</sum>
</function>
</fcs_function>
</channel>
</system> </system>