zkv1000 / Nasal / MFD.pages.nas /
Newer Older
387 lines | 17.771kb
just moves some code in more...
Sébastien MARQUE authored on 2017-07-17
1
# vim: set foldmethod=marker foldmarker={{{,}}} :
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
2
displayClass.MFD = {
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
3
    AUX: {
add flight planning menu
Sébastien MARQUE authored on 2020-05-04
4
        'TRIP PLANNING' : func {
5
            me.device.buttons.CLR = func {
6
                me.device.buttons.CLR = func;
7
                fgcommand('dialog-close', { 'dialog-name' : 'route-manager' });
8
                fgcommand('dialog-close', { 'dialog-name' : 'map' });
9
            };
10
            fgcommand('dialog-show', { 'dialog-name' : 'map' });
11
            fgcommand('dialog-show', { 'dialog-name' : 'route-manager' });
12
        },
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
13
        'SYSTEM SETUP' : func {
14
            var obj_infos = [
15
                {text: 'NAV BOX DATA FIELDS', type: 'title'},
16
                {type: 'separator'},
17
                {text: 'DATA FIELD NUMBER', type: 'normal'},
18
                {text: '  1 >', type: 'selected|end-of-line', choices: ['  1 >', '< 2 >', '< 3 >', '< 4  ']},
19
            ];
navigation box content
Sébastien MARQUE authored on 2020-05-12
20
            foreach (var item; keys(me.device.display.navbox)) {
21
                if (item == 'LEG') # LEG only displayed on PFD navigation box
22
                    continue;
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
23
                append(obj_infos, {
navigation box content
Sébastien MARQUE authored on 2020-05-12
24
                    text: sprintf('%-3s ', item),
25
                    type: 'editable',
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
26
                    callback: func (id, selected) {
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
27
                        var field = string.trim(me.device.windows.state[id].objects[3].text,
28
                                                0,
29
                                                func (c) c == `<` or c == `>` or c == ` `);
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
30
                        me.device.display.screenElements['DATA-FIELD' ~ field ~ '-ID-text']
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
31
                            .setText(string.trim(me.device.windows.state[id].objects[selected].text, 1));
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
32
                    }
33
                });
navigation box content
Sébastien MARQUE authored on 2020-05-12
34
                append(obj_infos, {
35
                    text: sprintf('(%s)', me.device.display.navbox[item][1]),
36
                    type: 'normal|end-of-line',
37
                });
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
38
            }
39
            var windowId = 'SYSTEM SETUP';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
40
            me.device.windows.draw( windowId, obj_infos );
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
41
            me.device.buttons.CLR = func {
42
                me.device.windows.del(windowId);
43
                me.device.buttons.ENT = func;
44
                me.device.buttons.CLR = func;
45
                me.device.knobs.FmsInner = func;
46
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
47
            }
48
            me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
49
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
50
            me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
51
        },
52
    },
add flightplan display
Sébastien MARQUE authored on 2020-05-04
53
    FPL : {
54
        'ACTIVE FLIGHT PLAN' : func {
55
            me.device.windows.del(id);
56
            var flightplan = props.globals.getNode('/autopilot/route-manager');
57
            var route = flightplan.getNode('route');
58
            var obj_infos = [
59
                {text: 'ACTIVE FLIGTHPLAN', type: 'title'},
60
                {type: 'separator'},
61
            ];
62
            if (route.getValue('num')) {
63
                append(obj_infos, {text: sprintf('DEP: %s', flightplan.getNode('departure').getValue('airport')), type: 'normal|end-of-line'});
64
                append(obj_infos, {text: sprintf('ARR: %s', flightplan.getNode('destination').getValue('airport')), type: 'normal|end-of-line'});
65
                append(obj_infos, {text: sprintf('DIS: %dnm', flightplan.getValue('total-distance')), type: 'normal|end-of-line'});
66
                append(obj_infos, {type: 'separator'});
67
                var current_wp = flightplan.getValue('current-wp');
68
                var firstEntry = 1;
69
                for (var n = 1; n < route.getValue('num'); n += 1) {
70
                    var wp = route.getChild('wp', n);
71
                    append(obj_infos, {text: sprintf('%1s %-7s  %3d°  %3dnm %s',
72
                                                    n == current_wp ? utf8.chstr(9658) : ' ',
73
                                                    wp.getValue('id'),
74
                                                    math.round(wp.getValue('leg-bearing-true-deg')),
75
                                                    math.round(wp.getValue('leg-distance-nm')),
76
                                                    wp.getValue('altitude-ft') > -100 ? ' ' ~ wp.getValue('altitude-ft') ~ 'ft': ''
77
                                            ),
78
                                       type: (firstEntry ? 'selected' : 'editable') ~ '|end-of-line',
79
                                       scrollgroup: n
80
                    });
81
                    firstEntry = 0;
82
                }
83
                append(obj_infos, {type: 'separator'});
84
            }
85
            else {
86
                append(obj_infos, {text: 'NO FP LOADED', type: 'normal|end-of-line'});
87
            }
88
            var windowId = 'ACTIVE FLIGTH PLAN';
89
            me.device.windows.draw( windowId, obj_infos, {lines: 6, columns: 1} );
90
            me.device.buttons.CLR = func {
91
                me.device.windows.del(windowId);
92
                me.device.buttons.ENT = func;
93
                me.device.buttons.CLR = func;
94
                me.device.knobs.FmsInner = func;
95
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
96
            }
97
            me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
98
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
99
        },
100
    },
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
101
    NRST : {
102
        'NEAREST AIRPORTS': func {
103
            var airports = findAirportsWithinRange(99.99);
104
            var obj_infos = [
105
                {text: size(airports) ~ ' NEAREST AIRPORTS', type: 'title'},
106
                {type: 'separator'},
107
            ];
108
            var name_max_length = 0;
109
            forindex (var idx; airports) {
110
                var info = airportinfo(airports[idx].id);
111
                var (course, distance) = courseAndDistance(info);
112
                var name = sprintf('%s (%s)', airports[idx].id, airports[idx].name);
113
                if (size(name) > name_max_length)
114
                    name_max_length = size(name);
115

            
116
                append(obj_infos, {
117
                        text: name,
118
                        type: (idx ? 'editable' : 'selected') ~ '|immediate|end-of-line',
119
                        scrollgroup: idx,
120
                    }
121
                );
122
                append(obj_infos, {
fix bad distance display for...
Sébastien MARQUE authored on 2020-05-02
123
                        text: sprintf(' %s DST %2dNM CRS %03d', utf8.chstr(9658), distance, course),
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
124
                        type: 'normal|end-of-line',
125
                        scrollgroup: idx
126
                    }
127
                );
128
            }
129
            append(obj_infos, {type: 'separator'});
130
            var windowId = 'NEAREST AIRPORTS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
131
            me.device.windows.draw( windowId, obj_infos, {lines: 4, columns: 1} );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
132
            me.device.buttons.CLR = func {
133
                me.device.windows.del(windowId);
134
                me.device.buttons.ENT = func;
135
                me.device.buttons.CLR = func;
136
                me.device.knobs.FmsInner = func;
137
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
138
            }
139
            me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
140
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
141
            me.device.buttons.ENT = func (a = 0) {
142
                if (a) return;
143
                me.device.windows.del(windowId);
144
                var (_, selected) = split('-', me.device.windows.selected);
145
                var (airport_id, _) = split(" ", obj_infos[selected].text);
146
                call(me.device.display.MFD._ShowAirportInfo, [airport_id], me);
147
            };
148
        },
149
        'NEAREST INTERSECTIONS': func {
150
            call(me.device.display.MFD._NearestNavaids, ['fix'], me);
151
        },
152
        'NEAREST NDB': func {
153
            call(me.device.display.MFD._NearestNavaids, ['ndb'], me);
154
        },
155
        'NEAREST VOR': func {
156
            call(me.device.display.MFD._NearestNavaids, ['vor'], me);
157
        },
158
    },
159
    _NearestNavaids: func (navaid_type) {
160
        var navaids = findNavaidsWithinRange(99.99, navaid_type);
161
        var obj_infos = [
162
            {text: size(navaids) ~ ' NEAREST ' ~ string.uc(navaid_type), type: 'title'},
163
            {type: 'separator'},
164
        ];
165
        var idx = 0;
166
        foreach (var navaid; navaids) {
167
            var (course, distance) = courseAndDistance(navaid);
168
            var name = navaid.id ~ ' (' ~ navaid.name ~ ')';
169

            
170
            append(obj_infos, {
171
                    text: navaid.id ~ ' (' ~ navaid.name ~ ')',
172
                    type: (idx ? 'editable' : 'selected') ~ '|immediate|end-of-line',
173
                    scrollgroup: idx,
174
                }
175
            );
176
            append(obj_infos, {
177
                    text: sprintf(' %s DST %2dNM CRS %03d', utf8.chstr(9658), distance, course),
178
                    type: 'normal|end-of-line',
179
                    scrollgroup: idx
180
                }
181
            );
182
            idx += 1;
183
        }
184
        append(obj_infos, {type: 'separator'});
185
        var windowId = obj_infos[0].text;
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
186
        me.device.windows.draw( windowId, obj_infos, {lines: 4, columns: 1} );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
187
        me.device.buttons.CLR = func {
188
            me.device.windows.del(windowId);
189
            me.device.buttons.ENT = func;
190
            me.device.buttons.CLR = func;
191
            me.device.knobs.FmsInner = func;
192
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
193
        }
194
        me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
195
        me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
196
        me.device.buttons.ENT = func (a = 0) {
197
            if (a) return;
198
            me.device.windows.del(windowId);
199
            var (_, selected) = split('-', me.device.windows.selected);
200
            var (navaid_id, _) = split(" ", obj_infos[selected].text);
201
            if (navaid_type == 'airport')
202
                call(me.device.display.MFD._ShowAirportInfo, [navaid_id], me);
203
            else
204
                call(me.device.display.MFD._ShowNavaidInfo, [navaid_id, navaid_type], me);
205
        };
206
    },
207
    _ShowNavaidInfo: func (navaid_id, navaid_type) {
208
        var info = findNavaidsByID(navaid_id, navaid_type);
209
        if (size(info) == 0) return;
210
        me.device.knobs.FmsInner = func;
211
        me.device.knobs.FmsOuter = func;
212
        me.device.buttons.ENT    = func;
213
        var obj_infos = [
214
            {text: info[0].id ~ ' INFORMATION', type: 'title'},
215
            {type: 'separator'},
216
            {text: 'ID    ' ~ info[0].id, type: 'normal|end-of-line'},
217
            {text: 'NAME  ' ~ info[0].name, type: 'normal|end-of-line'},
218
            {text: 'TYPE  ' ~ info[0].type, type: 'normal|end-of-line'},
219
            {text: sprintf('LON   %.3f %s', abs(info[0].lon), info[0].lon > 0 ? 'E' : 'W'), type: 'normal|end-of-line'},
220
            {text: sprintf('LAT   %.3f %s', abs(info[0].lat), info[0].lat > 0 ? 'N' : 'S'), type: 'normal|end-of-line'},
221
        ];
222
        call(func {return info[0].range }, [], nil, nil, var errors = []);
223
        if (!size(errors))
224
            append(obj_infos, {text: sprintf('RANGE %i NM', info[0].range * 1.852), type: 'normal|end-of-line'});
225
        call(func {return info[0].frequency }, [], nil, nil, var errors = []);
226
        if (!size(errors))
227
            append(obj_infos, {text: sprintf('FREQ  %.2f kHz', info[0].frequency / 100), type: 'normal|end-of-line'});
228
        var lines = size(obj_infos);
229
        var windowId = 'NAVAID INFORMATIONS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
230
        me.device.windows.draw( windowId, obj_infos );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
231
        me.device.buttons.CLR = func {
232
            me.device.windows.del(windowId);
233
            me.device.buttons.ENT = func;
234
            me.device.buttons.CLR = func;
235
            me.device.knobs.FmsInner = func;
236
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
237
        }
238
    },
239
    _ShowAirportInfo: func (airport_id) {
240
        me.device.knobs.FmsInner = func;
241
        me.device.knobs.FmsOuter = func;
242
        me.device.buttons.ENT    = func;
243
        var info = airportinfo(airport_id);
244
        var obj_infos = [
245
            {text: airport_id ~ ' INFORMATION', type: 'title'},
246
            {type: 'separator'},
247
            {text: sprintf('ELEVATION %.0d FT', info.elevation * 3.28), type: 'normal|end-of-line'},
248
            {text: sprintf('LON: %.3f %s', abs(info.lon), info.lon > 0 ? 'E' : 'W'), type: 'normal|end-of-line'},
249
            {text: sprintf('LAT: %.3f %s', abs(info.lat), info.lat > 0 ? 'N' : 'S'), type: 'normal|end-of-line'},
250
            {type: 'separator'},
251
            {text: 'RUNWAYS', type: 'title'},
252
        ];
253
        foreach (var rwy; sort(keys(info.runways), string.icmp)) {
254
            var rwyInfo = sprintf("%-3s %4.0dm %3.0d°",
255
                                  rwy,
256
                                  info.runways[rwy].length,
257
                                  info.runways[rwy].heading);
258
            if (info.runways[rwy].ils != nil) {
259
                rwyInfo = sprintf("%s %3.3f Mhz", rwyInfo, info.runways[rwy].ils.frequency / 100);
260
            }
261
            append(obj_infos, {text: rwyInfo, type: 'normal|end-of-line'});
262
        }
263
        var sep = 2; # to count separators, already two printed
264
        if (size(info.comms()) > 0) {
265
# TODO: find nearby freqs if none found for airport
266
            append(obj_infos, {type: 'separator'}); sep += 1;
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
267
            append(obj_infos, {text: 'COMMS FREQUENCIES', type: 'title'});
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
268
            var freqs = {};
269
            var comms = info.comms();
270
            foreach (var c; comms)
271
                freqs[c.ident] = sprintf("%.3f", c.frequency);
272

            
273
            foreach (var f; sort(keys(freqs), string.icmp))
274
                append(obj_infos, {text: sprintf('%-15s %.3f', f, freqs[f]), type: 'normal|end-of-line'});
275
        }
276
        var lines = size(obj_infos) - sep; # minus the separators
277
        var windowId = 'AIRPORT INFORMATIONS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
278
        me.device.windows.draw( windowId, obj_infos );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
279
        me.device.buttons.CLR = func {
280
            me.device.windows.del(windowId);
281
            me.device.buttons.ENT = func;
282
            me.device.buttons.CLR = func;
283
            me.device.knobs.FmsInner = func;
284
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
285
        }
286
    },
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
287
};
288

            
289
displayClass.setMFDPages = func {
just moves some code in more...
Sébastien MARQUE authored on 2017-07-17
290
    me.device.data['page selection'] = [
291
# list of pages, by group {{{
292
        {
293
            name: 'MAP',
294
            objects: [
295
                {text: 'NAVIGATION MAP'},
296
                {text: 'TRAFFIC MAP'},
297
                {text: 'STORMSCOPE'},
298
                {text: 'WEATHER DATA LINK'},
299
                {text: 'TAWS-B'},
300
            ],
301
        },
302
        {
303
            name: 'WPT',
304
            objects: [
305
                {text: 'AIRPORT INFORMATION'},
306
                {text: 'AIRPORT DIRECTORY'},
307
                {text: 'DEPARTURE INFORMATION'},
308
                {text: 'ARRIVAL INFORMATION'},
309
                {text: 'APPROACH INFORMATION'},
310
                {text: 'WEATHER INFORMATION'},
311
                {text: 'INTERSECTION INFORMATION'},
312
                {text: 'NDB INFORMATION'},
313
                {text: 'VOR INFORMATION'},
314
                {text: 'USER WAYPOINT INFORMATION'},
315
            ],
316
        },
317
        {
318
            name: 'AUX',
319
            objects: [
320
                {text: 'TRIP PLANNING'},
321
                {text: 'UTILITY'},
322
                {text: 'GPS STATUS'},
323
                {text: 'SYSTEM SETUP'},
324
            ],
325
        },
326
        {
327
            name: 'FPL',
328
            objects: [
329
                {text: 'ACTIVE FLIGHT PLAN'},
330
                {text: 'WIDE VIEW, NARROW VIEW'},
331
                {text: 'FLIGHT PLAN CATALOG'},
332
            ],
333
        },
334
        {
335
            name: 'PROC',
336
            objects: [
337
                {text: 'DEPARTURE LOADING'},
338
                {text: 'ARRIVAL LOADING'},
339
                {text: 'APPROACH LOADING'},
340
            ],
341
        },
342
        {
343
            name: 'NRST',
344
            objects: [
345
                {text: 'NEAREST AIRPORTS'},
346
                {text: 'NEAREST INTERSECTIONS'},
347
                {text: 'NEAREST NDB'},
348
                {text: 'NEAREST VOR'},
349
                {text: 'NEAREST USER WAYPOINTS'},
350
                {text: 'NEAREST FREQUENCIES'},
351
                {text: 'NEAREST AIRSPACES'},
352
            ],
353
        },
354
# }}}
355
    ];
356

            
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
357
    foreach (var g; me.device.data['page selection']) {
358
        var obj_s = size(g.objects);
359
        # build specific geometry per page, depending of number of sub-pages
360
        g.geometry = {x: 720, y: 758 - ((obj_s + 3) * 24), w: 300, l: obj_s + 1, sep: 1};
361
        # complete the hash with reccurrent elements type and callback
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
362
        var firstEntry = 1;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
363
        foreach (var o; g.objects) {
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
364
            if (contains(me.MFD, g.name) and contains(me.MFD[g.name], o.text)) {
365
                o.type = firstEntry ? 'selected' : 'editable';
366
                o.type ~= '|end-of-line';
367
                o.callback = me.device.buttons.MFD_page_wrapper;
make first menu item selecte...
Sébastien MARQUE authored on 2020-04-27
368
                firstEntry = 0;
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
369
            }
370
            else
371
                o.type = 'normal|end-of-line';
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
372
        }
373
    }
374
    # build the available groups line, at the bottom
375
    forindex (var g; me.device.data['page selection']) {
376
        append(me.device.data['page selection'][g].objects, {type: 'separator'});
377
        for (var i = 0; i < g; i+=1)
378
            append(me.device.data['page selection'][g].objects,
379
                {text: me.device.data['page selection'][i].name, type: 'normal'});
380
        append(me.device.data['page selection'][g].objects,
381
            {text: me.device.data['page selection'][i].name, type: 'highlighted'});
382
        for (var i = g+1; i < size(me.device.data['page selection']); i+=1)
383
            append(me.device.data['page selection'][g].objects,
384
                {text: me.device.data['page selection'][i].name, type: 'normal'});
385
    }
386
    me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
387
};