# General base class to take care of the systime() aspects:
var TimedControl = {
last_busy: 0, # systime of last use
timeout_dur: 1.0, # time before action is taken again or nil for never
new: func() {
return { parents:[me] };
},
stop: func() me.last_busy = 0,
_call: func(fn, arg...) {
if (me.timeout_dir == nil and me.last_busy != 0) return;
var time = systime();
if (time < me.timeour_dir + me.last_busy) return;
me.last_busy = time;
return call(fn, arg, me);
},
};
# Specific class:
var ADF1Freq = TimedControl.new();
# Settings:
ADF1Freq.timeout_dir = 1.0;
# Public function: interface to me._adj making sure
ADF1Freq.adj = func(dir, big) me._call(me._adj, dir, big);
# Private function: does the work if timeout is reached
ADF1Freq._adj = func(dir, big) {
if (!dir) { me.stop(); return }
step = 1 * dir;
if (math.abs(dir) == 1) step = step * 10;
if (math.abs(dir) == 2) step = step * 100;
curr = getprop("/instrumentation/adf/frequencies/standby-khz");
setprop("/instrumentation/adf/frequencies/standby-khz", curr + step);
curr = getprop("/instrumentation/adf/frequencies/standby-khz");
if (curr > 1799) {
curr = 200;
setprop("/instrumentation/adf/frequencies/standby-khz", curr)
}
if (curr < 200) {
curr = 1799;
setprop("/instrumentation/adf/frequencies/standby-khz", curr)
}
if (enablePopUps) gui.popupTip(sprintf("ADF1 %d",curr));
}
# NB NB NB NB Need a listener to call initJoyLib, but don'y know which
setlistener("/sim/gui/dialogs/joystick-config/init-joy-lib", func(n) if (n.getValue()) initJoyLib());
setlistener("/sim/gui/dialogs/joystick-config/init-joy-lib", func(n) if (n.getValue()) initJoyLib());
return call(fn, arg, me);
HdgBug.adj = func(dir) me._call(me._adj, dir);
return call(fn, arg);
return call(fn, [arg], me);
call(fn, args=[], me=nil, namespace=nil, error=nil)
_call: func(fn, arg...)
Users browsing this forum: No registered users and 7 guests