1 contributor
var APClass = {
new : func {
var m = { parents: [ APClass ] };
m.system = 'none';
var ap_systems = { # described AP systems to search, if it returns true system is set
};
foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) {
call(ap_systems[s], [], nil, nil, var errors = []);
if (!size(errors)) {
msg('found autopilot system: ' ~ s);
m.system = s;
break;
}
}
ap_systems = nil;
m.engaged = 0;
if (! contains(data.timers, 'updateAP')) {
data.timers.updateAP = maketimer(1, m, m.systems[m.system].updateDisplay);
data.timers.updateAP.start();
}
if (! contains(data.timers, 'AP_blinking')) {
data.timers.AP_blinking = maketimer(0, m, m._blinking);
data.timers.AP_blinking.singleShot = 1;
}
if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func')
m.systems[m.system].hook();
return m;
},
softkey: func (side, row, a) {
if (a == 0 or me._locked)
return;
var _system = me.systems[me.system];
var _side = _system[side];
_side[row]();
},
_locked: 0, # no status modification while blinking, is it really useful ?
_blinking: func {
autopilot._locked += 1;
var _display = flightdeck['PFD'].display;
var i = math.mod(autopilot._locked, 2);
var delays = [ 0.7, 0.3 ];
_display.screenElements['AP-text'].setVisible(i);
if (autopilot._locked < 11)
data.timers.AP_blinking.restart(delays[i]);
else {
autopilot._locked = 0;
data.timers.AP_blinking.stop();
_display.screenElements['AP-text']
.setVisible(1)
.setText('');
}
},
systems : {
# L: AP FD NAV ALT VS FLC
# R: YD HDG APR VNV UP DN
none: {
updateDisplay: func,
hook: func,
L: [ func, func, func, func, func, func ],
R: [ func, func, func, func, func, func ],
},
}
};