1
0
Fork 0

modules/canvas_efis/efis.nas replace typeof(), use log constants, add {}

This commit is contained in:
Henning Stahlke 2020-05-03 13:00:53 +02:00 committed by James Turner
parent 17e3ba6698
commit 49c8dcd442

View file

@ -116,14 +116,14 @@ var EFIS = {
# - hash {<unit_name>: source_id} # - hash {<unit_name>: source_id}
_activateRouting: func(mapping) _activateRouting: func(mapping)
{ {
if (typeof(mapping) == "vector") { if (isvec(mapping)) {
forindex (var unit_id; me.display_units) forindex (var unit_id; me.display_units)
{ {
if (mapping[unit_id] != nil) if (mapping[unit_id] != nil)
me._setDisplaySource(unit_id, mapping[unit_id]); me._setDisplaySource(unit_id, mapping[unit_id]);
} }
} }
elsif (typeof(mapping) == "hash") { elsif (ishash(mapping)) {
foreach (var unit_name; keys(mapping)) foreach (var unit_name; keys(mapping))
{ {
forindex (var unit_id; me.display_names) { forindex (var unit_id; me.display_names) {
@ -137,16 +137,18 @@ var EFIS = {
# Start/stop updates on all sources # Start/stop updates on all sources
_powerOnOff: func(power) { _powerOnOff: func(power) {
if (power) { if (power) {
logprint(3, "EFIS power on"); logprint(LOG_INFO, "EFIS power on");
foreach (var src; me.sources) foreach (var src; me.sources) {
src.startUpdates(); src.startUpdates();
} }
else { }
logprint(3, "EFIS power off."); else {
foreach (var src; me.sources) logprint(LOG_INFO, "EFIS power off.");
src.stopUpdates(); foreach (var src; me.sources) {
src.stopUpdates();
} }
}
}, },
#-- public methods ----------------------- #-- public methods -----------------------
@ -161,11 +163,11 @@ var EFIS = {
}, },
setWindowSize: func(window_size) { setWindowSize: func(window_size) {
if (window_size != nil and typeof(window_size) == "vector") { if (window_size != nil and isvec(window_size)) {
me.window_size = window_size; me.window_size = window_size;
} }
else { else {
logprint(5, "EFIS.setWindowSize(): Error, argument is not a vector."); logprint(DEV_ALERT, "EFIS.setWindowSize(): Error, argument is not a vector.");
} }
}, },
@ -174,12 +176,12 @@ var EFIS = {
}, },
setDUPowerProps: func(power_props, minimum_power=0) { setDUPowerProps: func(power_props, minimum_power=0) {
if (power_props != nil and typeof(power_props) == "vector") { if (power_props != nil and isvec(power_props)) {
forindex (var i; me.display_names) { forindex (var i; me.display_names) {
me.display_units[i].setPowerSource(power_props[i], minimum_power); me.display_units[i].setPowerSource(power_props[i], minimum_power);
} }
} }
else logprint(5, "EFIS.setDUPowerProps(): Error, argument is not a vector."); else logprint(DEV_ALERT, "EFIS.setDUPowerProps(): Error, argument is not a vector.");
}, },
# add a EFISCanvas instance as display source # add a EFISCanvas instance as display source
@ -202,8 +204,8 @@ var EFIS = {
{ {
if (me.controls[ctrl] != nil) return; if (me.controls[ctrl] != nil) return;
ctrlN = props.getNode(ctrl,1); ctrlN = props.getNode(ctrl,1);
if (typeof(mappings) != "vector") { if (!isvec(mappings)) {
logprint(5, "EFIS addDisplayControl: mappings must be a vector."); logprint(DEV_ALERT, "EFIS addDisplayControl: mappings must be a vector.");
return; return;
} }
var listener = func(p) { var listener = func(p) {
@ -225,10 +227,10 @@ var EFIS = {
# sources: optional vector, selected -> source ID (as returned by addSource) # sources: optional vector, selected -> source ID (as returned by addSource)
# defaults to all registered sources # defaults to all registered sources
addSourceSelector: func(selected, target, sources=nil){ addSourceSelector: func(selected, target, sources=nil){
if (typeof(selected) == "scalar") { if (isscalar(selected)) {
selected = props.getNode(selected,1); selected = props.getNode(selected,1);
} }
if (typeof(target) == "scalar") { if (isscalar(target)) {
target = props.getNode(target,1); target = props.getNode(target,1);
} }
if (selected.getValue() == nil) if (selected.getValue() == nil)
@ -246,7 +248,7 @@ var EFIS = {
}, },
setDefaultMapping: func(mapping) { setDefaultMapping: func(mapping) {
if (mapping != nil and (typeof(mapping) == "vector" or typeof(mapping) == "hash")) { if (mapping != nil and (isvec(mapping) or ishash(mapping))) {
me.default_mapping = mapping; me.default_mapping = mapping;
me._activateRouting(me.default_mapping); me._activateRouting(me.default_mapping);
} }