zkv1000 / Nasal / MFD.pages.nas /
Newer Older
357 lines | 14.981kb
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: {
4
        'SYSTEM SETUP' : func {
5
            var obj_infos = [
6
                {text: 'NAV BOX DATA FIELDS', type: 'title'},
7
                {type: 'separator'},
8
                {text: 'DATA FIELD NUMBER', type: 'normal'},
9
                {text: '  1 >', type: 'selected|end-of-line', choices: ['  1 >', '< 2 >', '< 3 >', '< 4  ']},
10
            ];
11
            var lines = 2;
12
            var column = 0;
13
            var colmax = 5;
14
            foreach (var text; me.device.display.updateNavigationBox(1)) {
15
                append(obj_infos, {
16
                    text: text,
17
                    type: column == colmax ? 'editable|end-of-line' : 'editable',
18
                    callback: func (id, selected) {
19
                        var field = me.device.windows.state[id].objects[3].text;
20
                        field = substr(field, 2);
21
                        field = substr(field, 0, size(field) - 2);
22
                        field = string.trim(field);
23
                        me.device.display.screenElements['DATA-FIELD' ~ field ~ '-ID-text']
24
                            .setText(me.device.windows.state[id].objects[selected].text);
25
                    }
26
                });
27
                if (column < colmax) column += 1;
28
                else {
29
                    column = 0;
30
                    lines += 1;
31
                }
32
            }
33
            var windowId = 'SYSTEM SETUP';
34
            var obj_s = size(obj_infos);
35
            me.device.windows.draw(
36
                windowId,
apply autogeom for some entr...
Sébastien MARQUE authored on 2020-05-02
37
                {autogeom: 1},
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
38
                obj_infos
39
            );
40
            me.device.buttons.CLR = func {
41
                me.device.windows.del(windowId);
42
                me.device.buttons.ENT = func;
43
                me.device.buttons.CLR = func;
44
                me.device.knobs.FmsInner = func;
45
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
46
            }
47
            me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
48
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
49
            me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
50
        },
51
    },
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
52
    NRST : {
53
        'NEAREST AIRPORTS': func {
54
            var airports = findAirportsWithinRange(99.99);
55
            var obj_infos = [
56
                {text: size(airports) ~ ' NEAREST AIRPORTS', type: 'title'},
57
                {type: 'separator'},
58
            ];
59
            var name_max_length = 0;
60
            forindex (var idx; airports) {
61
                var info = airportinfo(airports[idx].id);
62
                var (course, distance) = courseAndDistance(info);
63
                var name = sprintf('%s (%s)', airports[idx].id, airports[idx].name);
64
                if (size(name) > name_max_length)
65
                    name_max_length = size(name);
66

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

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

            
239
            foreach (var f; sort(keys(freqs), string.icmp))
240
                append(obj_infos, {text: sprintf('%-15s %.3f', f, freqs[f]), type: 'normal|end-of-line'});
241
        }
242
        var lines = size(obj_infos) - sep; # minus the separators
243
        var windowId = 'AIRPORT INFORMATIONS';
244
        me.device.windows.draw(
245
            windowId,
apply autogeom for some entr...
Sébastien MARQUE authored on 2020-05-02
246
            {autogeom: 1},
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
247
            obj_infos
248
        );
249
        me.device.buttons.CLR = func {
250
            me.device.windows.del(windowId);
251
            me.device.buttons.ENT = func;
252
            me.device.buttons.CLR = func;
253
            me.device.knobs.FmsInner = func;
254
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
255
        }
256
    },
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
257
};
258

            
259
displayClass.setMFDPages = func {
just moves some code in more...
Sébastien MARQUE authored on 2017-07-17
260
    me.device.data['page selection'] = [
261
# list of pages, by group {{{
262
        {
263
            name: 'MAP',
264
            objects: [
265
                {text: 'NAVIGATION MAP'},
266
                {text: 'TRAFFIC MAP'},
267
                {text: 'STORMSCOPE'},
268
                {text: 'WEATHER DATA LINK'},
269
                {text: 'TAWS-B'},
270
            ],
271
        },
272
        {
273
            name: 'WPT',
274
            objects: [
275
                {text: 'AIRPORT INFORMATION'},
276
                {text: 'AIRPORT DIRECTORY'},
277
                {text: 'DEPARTURE INFORMATION'},
278
                {text: 'ARRIVAL INFORMATION'},
279
                {text: 'APPROACH INFORMATION'},
280
                {text: 'WEATHER INFORMATION'},
281
                {text: 'INTERSECTION INFORMATION'},
282
                {text: 'NDB INFORMATION'},
283
                {text: 'VOR INFORMATION'},
284
                {text: 'USER WAYPOINT INFORMATION'},
285
            ],
286
        },
287
        {
288
            name: 'AUX',
289
            objects: [
290
                {text: 'TRIP PLANNING'},
291
                {text: 'UTILITY'},
292
                {text: 'GPS STATUS'},
293
                {text: 'SYSTEM SETUP'},
294
            ],
295
        },
296
        {
297
            name: 'FPL',
298
            objects: [
299
                {text: 'ACTIVE FLIGHT PLAN'},
300
                {text: 'WIDE VIEW, NARROW VIEW'},
301
                {text: 'FLIGHT PLAN CATALOG'},
302
            ],
303
        },
304
        {
305
            name: 'PROC',
306
            objects: [
307
                {text: 'DEPARTURE LOADING'},
308
                {text: 'ARRIVAL LOADING'},
309
                {text: 'APPROACH LOADING'},
310
            ],
311
        },
312
        {
313
            name: 'NRST',
314
            objects: [
315
                {text: 'NEAREST AIRPORTS'},
316
                {text: 'NEAREST INTERSECTIONS'},
317
                {text: 'NEAREST NDB'},
318
                {text: 'NEAREST VOR'},
319
                {text: 'NEAREST USER WAYPOINTS'},
320
                {text: 'NEAREST FREQUENCIES'},
321
                {text: 'NEAREST AIRSPACES'},
322
            ],
323
        },
324
# }}}
325
    ];
326

            
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
327
    foreach (var g; me.device.data['page selection']) {
328
        var obj_s = size(g.objects);
329
        # build specific geometry per page, depending of number of sub-pages
330
        g.geometry = {x: 720, y: 758 - ((obj_s + 3) * 24), w: 300, l: obj_s + 1, sep: 1};
331
        # complete the hash with reccurrent elements type and callback
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
332
        var firstEntry = 1;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
333
        foreach (var o; g.objects) {
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
334
            if (contains(me.MFD, g.name) and contains(me.MFD[g.name], o.text)) {
335
                o.type = firstEntry ? 'selected' : 'editable';
336
                o.type ~= '|end-of-line';
337
                o.callback = me.device.buttons.MFD_page_wrapper;
make first menu item selecte...
Sébastien MARQUE authored on 2020-04-27
338
                firstEntry = 0;
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
339
            }
340
            else
341
                o.type = 'normal|end-of-line';
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
342
        }
343
    }
344
    # build the available groups line, at the bottom
345
    forindex (var g; me.device.data['page selection']) {
346
        append(me.device.data['page selection'][g].objects, {type: 'separator'});
347
        for (var i = 0; i < g; i+=1)
348
            append(me.device.data['page selection'][g].objects,
349
                {text: me.device.data['page selection'][i].name, type: 'normal'});
350
        append(me.device.data['page selection'][g].objects,
351
            {text: me.device.data['page selection'][i].name, type: 'highlighted'});
352
        for (var i = g+1; i < size(me.device.data['page selection']); i+=1)
353
            append(me.device.data['page selection'][g].objects,
354
                {text: me.device.data['page selection'][i].name, type: 'normal'});
355
    }
356
    me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
357
};