zkv1000 / Nasal / afcs.nas /
Newer Older
178 lines | 7.405kb
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
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
7
            STEC55X: func contains(stec55x, 'ITAF'),
adds AFCS
Sébastien MARQUE authored on 2020-05-06
8
        };
9
        foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) {
10
            call(ap_systems[s], [], nil, nil, var errors = []);
11
            if (!size(errors)) {
12
                msg('found autopilot system: ' ~ s);
13
                m.system = s;
14
                break;
15
            }
16
        }
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

            
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
30
        var ap_annun = [
31
            'LATMOD-Armed-text',  'LATMOD-Active-text',
32
            'AP-Status-text',     'YD-Status-text',
33
            'VERMOD-Active-text', 'VERMOD-Reference-text', 'VERMOD-Armed-text'
34
        ];
35
        foreach (var elem; ap_annun) {
36
            var color = (elem == 'LATMOD-Armed-text' or elem == 'VERMOD-Armed-text') ? 'white' : 'green';
37
            flightdeck.PFD.display.screenElements[elem]
38
                .setColor(flightdeck.PFD.display.colors[color])
39
                .setVisible(0);
40
        }
41
        foreach (var ap; [ 'AP', 'YD' ])
42
            flightdeck.PFD.display.screenElements[ap ~ '-Status-text']
43
                .setText(ap);
44

            
45
        ap_annun = nil;
46
        ap_systems = nil;
47

            
adds AFCS
Sébastien MARQUE authored on 2020-05-06
48
        if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func')
49
                m.systems[m.system].hook();
50

            
51
        return m;
52
    },
53
    softkey: func (side, row, a) {
small stuff
Sébastien MARQUE authored on 2020-05-08
54
        if (a or me._locked)
adds AFCS
Sébastien MARQUE authored on 2020-05-06
55
            return;
56
        var _system = me.systems[me.system];
57
        var _side = _system[side];
58
        _side[row]();
59
    },
60
    systems : {
61
        # L: AP FD  NAV ALT VS FLC
62
        # R: YD HDG APR VNV UP DN
63
        none: {
64
            updateDisplay: func,
65
            hook: func,
66
            L: [ func, func, func, func, func, func ],
67
            R: [ func, func, func, func, func, func ],
68
        },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
69
        STEC55X: {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
70
            hook : func {
71
                me.trimTarget = 0;
72
            },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
73
            updateDisplay: func {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
74
                var se = flightdeck.PFD.display.screenElements;
75
                se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
76
                se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
77
                if (stec55x.rollMode  != -1) {
78
                    se['LATMOD-Active-text'].setVisible(1).setText('ROL');
79
                    var armed = '';
80
                    foreach (var m; [ 'NAV', 'CNAV', 'REV', 'CREV' ])
81
                        if (stec55x[m]) armed = m;
82
                    if (stec55x.roll.getValue() == 4) armed = 'GPS';
83
                    if (stec55x.APR_annun.getValue()) armed = 'APR';
84
                    if (stec55x.HDG_annun.getValue()) armed = 'HDG';
85
                    se['LATMOD-Armed-text']
86
                        .setVisible(size(armed))
87
                        .setText(armed);
88
                }
89
                else {
90
                    se['LATMOD-Active-text'].setVisible(0);
91
                    se['LATMOD-Armed-text'].setVisible(0);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
92
                }
93

            
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
94
                if (stec55x.pitchMode != 1) {
95
                    var armed     = '';
96
                    var active    = '';
97
                    var reference = '';
98
                    if (stec55x.ALT_annun.getBoolValue()) {
99
                        if (abs(data.alt - afcs.getValue('selected-alt-ft')) < 150) {
100
                            active    = 'ALT';
101
                            reference = sprintf('%5d ft', afcs.getValue('selected-alt-ft'));
102
                            armed     = 'ALTS'
103
                        }
104
                        else {
105
                            active    = 'ALT';
106
                            reference = sprintf('%5d ft', math.round(data.alt, 10));
107
                            armed     = 'ALT';
108
                        }
109
                    }
110
                    elsif (stec55x.VS_annun.getBoolValue()) {
111
                        active    = 'VS';
112
                        reference = sprintf('%s%4d fpm',
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
113
                                        utf8.chstr(stec55x.vs.getValue() > 0 ? 9650 : 9660),
114
                                        math.abs(math.round(stec55x.vs.getValue(), 10)));
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
115
                    }
116
                    elsif (stec55x.GSArmed.getBoolValue()) {
117
                        armed  = 'VPATH';
118
                        active = 'GS';
119
                    }
120
# TODO: ask Octal450 which prop or variable can be used here
121
#                    elsif (stec55x.???) {
122
#                        armed  = 'PIT';
123
#                        active = 'ALT';
124
#                        reference = sprintf("%d°", autopilot.systems.STEC55X.trim);
125
#                    }
126
                    se['VERMOD-Active-text'].setVisible(size(active)).setText(active);
127
                    se['VERMOD-Armed-text'].setVisible(size(armed)).setText(armed);
128
                    se['VERMOD-Reference-text'].setVisible(size(reference)).setText(reference);
129
                }
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
130
            },
131
            L: [
132
                func {
133
                    var ap_master_sw = '/it-stec55x/input/ap-master-sw';
134
                    setprop(ap_master_sw, !getprop(ap_master_sw));
135
                },
136
                func {
137
                    var apfd_master_sw = '/it-stec55x/input/apfd-master-sw';
138
                    setprop(apfd_master_sw, !getprop(apfd_master_sw));
139
                },
140
                func {
141
                    call(stec55x.button.NAV, [], nil, stec55x);
142
                },
143
                func {
144
                    call(stec55x.button.ALT, [], nil, stec55x);
145
                },
146
                func {
147
                    call(stec55x.button.VS, [], nil, stec55x);
148
                },
149
                func,
150
            ],
151
            R: [
152
                func {
153
                    var yaw_dumper_sw = '/it-stec55x/input/yaw-damper-sw';
154
                    setprop(yaw_dumper_sw, !getprop(yaw_dumper_sw));
155
                },
156
                func {
157
                    call(stec55x.button.HDG, [], nil, stec55x);
158
                },
159
                func {
160
                    call(stec55x.button.APR, [], nil, stec55x);
161
                },
162
                func,
163
                func { # UP (trim)
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
164
                    if (autopilot.systems.STEC55X.trimTarget > -15)
165
                        autopilot.systems.STEC55X.trimTarget -= 1;
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
166
                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: -1});
167
                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value:  0});
168
                },
169
                func { # DN (trim)
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
170
                    if (autopilot.systems.STEC55X.trimTarget < 20)
171
                        autopilot.systems.STEC55X.trimTarget += 1;
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
172
                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 1});
173
                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 0});
174
                },
175
            ],
176
        }
adds AFCS
Sébastien MARQUE authored on 2020-05-06
177
    }
178
};