zkv1000 / Nasal / MFD.pages.nas /
Newer Older
337 lines | 14.908kb
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
            ];
20
            var column = 0;
21
            var colmax = 5;
22
            foreach (var text; me.device.display.updateNavigationBox(1)) {
23
                append(obj_infos, {
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
24
                    text: sprintf('%-5s', text),
25
                    type: 'editable' ~ ((column == colmax) ? '|end-of-line' : ''),
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
                });
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
34
                column += (column < colmax) ? 1 : -column;
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
35
            }
36
            var windowId = 'SYSTEM SETUP';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
37
            me.device.windows.draw( windowId, obj_infos );
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
38
            me.device.buttons.CLR = func {
39
                me.device.windows.del(windowId);
40
                me.device.buttons.ENT = func;
41
                me.device.buttons.CLR = func;
42
                me.device.knobs.FmsInner = func;
43
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
44
            }
45
            me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
46
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
47
            me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
48
        },
49
    },
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
50
    NRST : {
51
        'NEAREST AIRPORTS': func {
52
            var airports = findAirportsWithinRange(99.99);
53
            var obj_infos = [
54
                {text: size(airports) ~ ' NEAREST AIRPORTS', type: 'title'},
55
                {type: 'separator'},
56
            ];
57
            var name_max_length = 0;
58
            forindex (var idx; airports) {
59
                var info = airportinfo(airports[idx].id);
60
                var (course, distance) = courseAndDistance(info);
61
                var name = sprintf('%s (%s)', airports[idx].id, airports[idx].name);
62
                if (size(name) > name_max_length)
63
                    name_max_length = size(name);
64

            
65
                append(obj_infos, {
66
                        text: name,
67
                        type: (idx ? 'editable' : 'selected') ~ '|immediate|end-of-line',
68
                        scrollgroup: idx,
69
                    }
70
                );
71
                append(obj_infos, {
fix bad distance display for...
Sébastien MARQUE authored on 2020-05-02
72
                        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
73
                        type: 'normal|end-of-line',
74
                        scrollgroup: idx
75
                    }
76
                );
77
            }
78
            append(obj_infos, {type: 'separator'});
79
            var windowId = 'NEAREST AIRPORTS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
80
            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
81
            me.device.buttons.CLR = func {
82
                me.device.windows.del(windowId);
83
                me.device.buttons.ENT = func;
84
                me.device.buttons.CLR = func;
85
                me.device.knobs.FmsInner = func;
86
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
87
            }
88
            me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
89
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
90
            me.device.buttons.ENT = func (a = 0) {
91
                if (a) return;
92
                me.device.windows.del(windowId);
93
                var (_, selected) = split('-', me.device.windows.selected);
94
                var (airport_id, _) = split(" ", obj_infos[selected].text);
95
                call(me.device.display.MFD._ShowAirportInfo, [airport_id], me);
96
            };
97
        },
98
        'NEAREST INTERSECTIONS': func {
99
            call(me.device.display.MFD._NearestNavaids, ['fix'], me);
100
        },
101
        'NEAREST NDB': func {
102
            call(me.device.display.MFD._NearestNavaids, ['ndb'], me);
103
        },
104
        'NEAREST VOR': func {
105
            call(me.device.display.MFD._NearestNavaids, ['vor'], me);
106
        },
107
    },
108
    _NearestNavaids: func (navaid_type) {
109
        var navaids = findNavaidsWithinRange(99.99, navaid_type);
110
        var obj_infos = [
111
            {text: size(navaids) ~ ' NEAREST ' ~ string.uc(navaid_type), type: 'title'},
112
            {type: 'separator'},
113
        ];
114
        var idx = 0;
115
        foreach (var navaid; navaids) {
116
            var (course, distance) = courseAndDistance(navaid);
117
            var name = navaid.id ~ ' (' ~ navaid.name ~ ')';
118

            
119
            append(obj_infos, {
120
                    text: navaid.id ~ ' (' ~ navaid.name ~ ')',
121
                    type: (idx ? 'editable' : 'selected') ~ '|immediate|end-of-line',
122
                    scrollgroup: idx,
123
                }
124
            );
125
            append(obj_infos, {
126
                    text: sprintf(' %s DST %2dNM CRS %03d', utf8.chstr(9658), distance, course),
127
                    type: 'normal|end-of-line',
128
                    scrollgroup: idx
129
                }
130
            );
131
            idx += 1;
132
        }
133
        append(obj_infos, {type: 'separator'});
134
        var windowId = obj_infos[0].text;
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
135
        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
136
        me.device.buttons.CLR = func {
137
            me.device.windows.del(windowId);
138
            me.device.buttons.ENT = func;
139
            me.device.buttons.CLR = func;
140
            me.device.knobs.FmsInner = func;
141
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
142
        }
143
        me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
144
        me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
145
        me.device.buttons.ENT = func (a = 0) {
146
            if (a) return;
147
            me.device.windows.del(windowId);
148
            var (_, selected) = split('-', me.device.windows.selected);
149
            var (navaid_id, _) = split(" ", obj_infos[selected].text);
150
            if (navaid_type == 'airport')
151
                call(me.device.display.MFD._ShowAirportInfo, [navaid_id], me);
152
            else
153
                call(me.device.display.MFD._ShowNavaidInfo, [navaid_id, navaid_type], me);
154
        };
155
    },
156
    _ShowNavaidInfo: func (navaid_id, navaid_type) {
157
        var info = findNavaidsByID(navaid_id, navaid_type);
158
        if (size(info) == 0) return;
159
        me.device.knobs.FmsInner = func;
160
        me.device.knobs.FmsOuter = func;
161
        me.device.buttons.ENT    = func;
162
        print(typeof(info[0]));
163
        var obj_infos = [
164
            {text: info[0].id ~ ' INFORMATION', type: 'title'},
165
            {type: 'separator'},
166
            {text: 'ID    ' ~ info[0].id, type: 'normal|end-of-line'},
167
            {text: 'NAME  ' ~ info[0].name, type: 'normal|end-of-line'},
168
            {text: 'TYPE  ' ~ info[0].type, type: 'normal|end-of-line'},
169
            {text: sprintf('LON   %.3f %s', abs(info[0].lon), info[0].lon > 0 ? 'E' : 'W'), type: 'normal|end-of-line'},
170
            {text: sprintf('LAT   %.3f %s', abs(info[0].lat), info[0].lat > 0 ? 'N' : 'S'), type: 'normal|end-of-line'},
171
        ];
172
        call(func {return info[0].range }, [], nil, nil, var errors = []);
173
        if (!size(errors))
174
            append(obj_infos, {text: sprintf('RANGE %i NM', info[0].range * 1.852), type: 'normal|end-of-line'});
175
        call(func {return info[0].frequency }, [], nil, nil, var errors = []);
176
        if (!size(errors))
177
            append(obj_infos, {text: sprintf('FREQ  %.2f kHz', info[0].frequency / 100), type: 'normal|end-of-line'});
178
        var lines = size(obj_infos);
179
        var windowId = 'NAVAID INFORMATIONS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
180
        me.device.windows.draw( windowId, obj_infos );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
181
        me.device.buttons.CLR = func {
182
            me.device.windows.del(windowId);
183
            me.device.buttons.ENT = func;
184
            me.device.buttons.CLR = func;
185
            me.device.knobs.FmsInner = func;
186
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
187
        }
188
    },
189
    _ShowAirportInfo: func (airport_id) {
190
        me.device.knobs.FmsInner = func;
191
        me.device.knobs.FmsOuter = func;
192
        me.device.buttons.ENT    = func;
193
        var info = airportinfo(airport_id);
194
        var obj_infos = [
195
            {text: airport_id ~ ' INFORMATION', type: 'title'},
196
            {type: 'separator'},
197
            {text: sprintf('ELEVATION %.0d FT', info.elevation * 3.28), type: 'normal|end-of-line'},
198
            {text: sprintf('LON: %.3f %s', abs(info.lon), info.lon > 0 ? 'E' : 'W'), type: 'normal|end-of-line'},
199
            {text: sprintf('LAT: %.3f %s', abs(info.lat), info.lat > 0 ? 'N' : 'S'), type: 'normal|end-of-line'},
200
            {type: 'separator'},
201
            {text: 'RUNWAYS', type: 'title'},
202
        ];
203
        foreach (var rwy; sort(keys(info.runways), string.icmp)) {
204
            var rwyInfo = sprintf("%-3s %4.0dm %3.0d°",
205
                                  rwy,
206
                                  info.runways[rwy].length,
207
                                  info.runways[rwy].heading);
208
            if (info.runways[rwy].ils != nil) {
209
                rwyInfo = sprintf("%s %3.3f Mhz", rwyInfo, info.runways[rwy].ils.frequency / 100);
210
            }
211
            append(obj_infos, {text: rwyInfo, type: 'normal|end-of-line'});
212
        }
213
        var sep = 2; # to count separators, already two printed
214
        if (size(info.comms()) > 0) {
215
# TODO: find nearby freqs if none found for airport
216
            append(obj_infos, {type: 'separator'}); sep += 1;
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
217
            append(obj_infos, {text: 'COMMS FREQUENCIES', type: 'title'});
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
218
            var freqs = {};
219
            var comms = info.comms();
220
            foreach (var c; comms)
221
                freqs[c.ident] = sprintf("%.3f", c.frequency);
222

            
223
            foreach (var f; sort(keys(freqs), string.icmp))
224
                append(obj_infos, {text: sprintf('%-15s %.3f', f, freqs[f]), type: 'normal|end-of-line'});
225
        }
226
        var lines = size(obj_infos) - sep; # minus the separators
227
        var windowId = 'AIRPORT INFORMATIONS';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
228
        me.device.windows.draw( windowId, obj_infos );
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
229
        me.device.buttons.CLR = func {
230
            me.device.windows.del(windowId);
231
            me.device.buttons.ENT = func;
232
            me.device.buttons.CLR = func;
233
            me.device.knobs.FmsInner = func;
234
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
235
        }
236
    },
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
237
};
238

            
239
displayClass.setMFDPages = func {
just moves some code in more...
Sébastien MARQUE authored on 2017-07-17
240
    me.device.data['page selection'] = [
241
# list of pages, by group {{{
242
        {
243
            name: 'MAP',
244
            objects: [
245
                {text: 'NAVIGATION MAP'},
246
                {text: 'TRAFFIC MAP'},
247
                {text: 'STORMSCOPE'},
248
                {text: 'WEATHER DATA LINK'},
249
                {text: 'TAWS-B'},
250
            ],
251
        },
252
        {
253
            name: 'WPT',
254
            objects: [
255
                {text: 'AIRPORT INFORMATION'},
256
                {text: 'AIRPORT DIRECTORY'},
257
                {text: 'DEPARTURE INFORMATION'},
258
                {text: 'ARRIVAL INFORMATION'},
259
                {text: 'APPROACH INFORMATION'},
260
                {text: 'WEATHER INFORMATION'},
261
                {text: 'INTERSECTION INFORMATION'},
262
                {text: 'NDB INFORMATION'},
263
                {text: 'VOR INFORMATION'},
264
                {text: 'USER WAYPOINT INFORMATION'},
265
            ],
266
        },
267
        {
268
            name: 'AUX',
269
            objects: [
270
                {text: 'TRIP PLANNING'},
271
                {text: 'UTILITY'},
272
                {text: 'GPS STATUS'},
273
                {text: 'SYSTEM SETUP'},
274
            ],
275
        },
276
        {
277
            name: 'FPL',
278
            objects: [
279
                {text: 'ACTIVE FLIGHT PLAN'},
280
                {text: 'WIDE VIEW, NARROW VIEW'},
281
                {text: 'FLIGHT PLAN CATALOG'},
282
            ],
283
        },
284
        {
285
            name: 'PROC',
286
            objects: [
287
                {text: 'DEPARTURE LOADING'},
288
                {text: 'ARRIVAL LOADING'},
289
                {text: 'APPROACH LOADING'},
290
            ],
291
        },
292
        {
293
            name: 'NRST',
294
            objects: [
295
                {text: 'NEAREST AIRPORTS'},
296
                {text: 'NEAREST INTERSECTIONS'},
297
                {text: 'NEAREST NDB'},
298
                {text: 'NEAREST VOR'},
299
                {text: 'NEAREST USER WAYPOINTS'},
300
                {text: 'NEAREST FREQUENCIES'},
301
                {text: 'NEAREST AIRSPACES'},
302
            ],
303
        },
304
# }}}
305
    ];
306

            
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
307
    foreach (var g; me.device.data['page selection']) {
308
        var obj_s = size(g.objects);
309
        # build specific geometry per page, depending of number of sub-pages
310
        g.geometry = {x: 720, y: 758 - ((obj_s + 3) * 24), w: 300, l: obj_s + 1, sep: 1};
311
        # complete the hash with reccurrent elements type and callback
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
312
        var firstEntry = 1;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
313
        foreach (var o; g.objects) {
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
314
            if (contains(me.MFD, g.name) and contains(me.MFD[g.name], o.text)) {
315
                o.type = firstEntry ? 'selected' : 'editable';
316
                o.type ~= '|end-of-line';
317
                o.callback = me.device.buttons.MFD_page_wrapper;
make first menu item selecte...
Sébastien MARQUE authored on 2020-04-27
318
                firstEntry = 0;
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
319
            }
320
            else
321
                o.type = 'normal|end-of-line';
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
322
        }
323
    }
324
    # build the available groups line, at the bottom
325
    forindex (var g; me.device.data['page selection']) {
326
        append(me.device.data['page selection'][g].objects, {type: 'separator'});
327
        for (var i = 0; i < g; i+=1)
328
            append(me.device.data['page selection'][g].objects,
329
                {text: me.device.data['page selection'][i].name, type: 'normal'});
330
        append(me.device.data['page selection'][g].objects,
331
            {text: me.device.data['page selection'][i].name, type: 'highlighted'});
332
        for (var i = g+1; i < size(me.device.data['page selection']); i+=1)
333
            append(me.device.data['page selection'][g].objects,
334
                {text: me.device.data['page selection'][i].name, type: 'normal'});
335
    }
336
    me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
337
};