zkv1000 / Nasal / afcs.nas /
Newer Older
179 lines | 7.417kb
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) {
54
        if (a == 0 or me._locked)
55
            return;
56
        var _system = me.systems[me.system];
57
        var _side = _system[side];
58
        _side[row]();
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
        },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
70
        STEC55X: {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
71
            hook : func {
72
                me.trimTarget = 0;
73
            },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
74
            updateDisplay: func {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
75
                var se = flightdeck.PFD.display.screenElements;
76
                se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
77
                se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
78
                if (stec55x.rollMode  != -1) {
79
                    se['LATMOD-Active-text'].setVisible(1).setText('ROL');
80
                    var armed = '';
81
                    foreach (var m; [ 'NAV', 'CNAV', 'REV', 'CREV' ])
82
                        if (stec55x[m]) armed = m;
83
                    if (stec55x.roll.getValue() == 4) armed = 'GPS';
84
                    if (stec55x.APR_annun.getValue()) armed = 'APR';
85
                    if (stec55x.HDG_annun.getValue()) armed = 'HDG';
86
                    se['LATMOD-Armed-text']
87
                        .setVisible(size(armed))
88
                        .setText(armed);
89
                }
90
                else {
91
                    se['LATMOD-Active-text'].setVisible(0);
92
                    se['LATMOD-Armed-text'].setVisible(0);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
93
                }
94

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