zkv1000 / Nasal / afcs.nas /
Newer Older
71 lines | 2.232kb
adds AFCS
Sébastien MARQUE authored on 2020-05-06
1
var APClass = {
2
    new : func {
3
        var m = { parents: [ APClass ] };
4

            
5
        m.system = 'none';
6
        var ap_systems = { # described AP systems to search, if it returns true system is set
7
        };
8
        foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) {
9
            call(ap_systems[s], [], nil, nil, var errors = []);
10
            if (!size(errors)) {
11
                msg('found autopilot system: ' ~ s);
12
                m.system = s;
13
                break;
14
            }
15
        }
16
        ap_systems = nil;
17

            
18
        m.engaged = 0;
19

            
20
        if (! contains(data.timers, 'updateAP')) {
21
            data.timers.updateAP = maketimer(1, m, m.systems[m.system].updateDisplay);
22
            data.timers.updateAP.start();
23
        }
24

            
25
        if (! contains(data.timers, 'AP_blinking')) {
26
            data.timers.AP_blinking = maketimer(0, m,  m._blinking);
27
            data.timers.AP_blinking.singleShot = 1;
28
        }
29

            
30
        if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func')
31
                m.systems[m.system].hook();
32

            
33
        return m;
34
    },
35
    softkey: func (side, row, a) {
36
        if (a == 0 or me._locked)
37
            return;
38
        var _system = me.systems[me.system];
39
        var _side = _system[side];
40
        _side[row]();
41
    },
42
    _locked: 0, # no status modification while blinking, is it really useful ?
43
    _blinking: func {
44
        autopilot._locked += 1;
45
        var _display = flightdeck['PFD'].display;
46
        var i = math.mod(autopilot._locked, 2);
47
        var delays = [ 0.7, 0.3 ];
48

            
49
        _display.screenElements['AP-text'].setVisible(i);
50
        
51
        if (autopilot._locked < 11)
52
            data.timers.AP_blinking.restart(delays[i]);
53
        else {
54
            autopilot._locked = 0;
55
            data.timers.AP_blinking.stop();
56
            _display.screenElements['AP-text']
57
                .setVisible(1)
58
                .setText('');
59
        }
60
    },
61
    systems : {
62
        # L: AP FD  NAV ALT VS FLC
63
        # R: YD HDG APR VNV UP DN
64
        none: {
65
            updateDisplay: func,
66
            hook: func,
67
            L: [ func, func, func, func, func, func ],
68
            R: [ func, func, func, func, func, func ],
69
        },
70
    }
71
};