1
0
Fork 0
fgdata/Aircraft/Generic/annunciator.nas

84 lines
2.2 KiB
Text
Raw Normal View History

var VOLTS_THRESHOLD = 24.5;
var FUEL_THRESHOLD = 5.0;
var VACUUM_THRESHOLD = 3.0;
var OIL_PRESSURE_THRESHOLD = 20.0;
var ann = {
new : func(p) {
var m = { parents : [ann] };
m.node = props.globals.getNode(p, 1);
m.node.setBoolValue(0);
m.stamp = nil;
m.state = 0;
return m;
},
switch : func(v) {
if (v) {
if (!me.state) {
me.stamp = sec + 10;
me.state = 1;
}
2008-06-04 20:52:09 +00:00
me.node.setBoolValue(sec < me.stamp ? clock : 1);
} else {
2008-06-04 20:52:09 +00:00
if (me.state)
me.node.setBoolValue(me.state = 0);
}
},
};
2008-06-04 20:52:09 +00:00
var volts = props.initNode("/systems/electrical/volts");
var vac_l = props.initNode("/systems/vacuum[0]/suction-inhg");
var vac_r = props.initNode("/systems/vacuum[1]/suction-inhg");
var fuel_l = props.initNode("/consumables/fuel/tank[0]/level-gal_us");
var fuel_r = props.initNode("/consumables/fuel/tank[1]/level-gal_us");
var oil_px = props.initNode("/engines/engine[0]/oil-pressure-psi");
var elapsed = props.initNode("/sim/time/elapsed-sec");
var ann_volts = ann.new("/instrumentation/annunciator/volts");
var ann_vac_l = ann.new("/instrumentation/annunciator/vacuum-left");
var ann_vac_r = ann.new("/instrumentation/annunciator/vacuum-right");
var ann_fuel_l = ann.new("/instrumentation/annunciator/fuel-left");
var ann_fuel_r = ann.new("/instrumentation/annunciator/fuel-right");
var ann_oil_px = ann.new("/instrumentation/annunciator/oil-pressure");
var clock = 0;
var sec = nil;
var main = func {
clock = !clock;
sec = elapsed.getValue();
var v = volts.getValue();
if (v < 5.0 or !serviceable) {
ann_volts.switch(0);
ann_vac_l.switch(0);
ann_vac_r.switch(0);
ann_fuel_l.switch(0);
ann_fuel_r.switch(0);
ann_oil_px.switch(0);
} else {
ann_volts.switch(v < VOLTS_THRESHOLD);
ann_fuel_l.switch(fuel_l.getValue() < FUEL_THRESHOLD);
ann_fuel_r.switch(fuel_r.getValue() < FUEL_THRESHOLD);
ann_vac_l.switch(vac_l.getValue() < VACUUM_THRESHOLD);
ann_vac_r.switch(vac_r.getValue() < VACUUM_THRESHOLD);
ann_oil_px.switch(oil_px.getValue() < OIL_PRESSURE_THRESHOLD);
}
settimer(main, 0.5);
}
var serviceable = nil;
settimer(func {
2008-06-04 20:52:09 +00:00
setlistener("/systems/electrical/serviceable", func(n) serviceable = n.getBoolValue(), 1);
main();
}, 0);