zkv1000 / Nasal / MFD.pages.nas /
Newer Older
364 lines | 15.58kb
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,
37
                {x: 720, y: 758 - ((lines + 3) * 24), w: 300, l: lines, sep: 1},
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, {
74
                        text: sprintf(' %s DST %2dNM CRS %03d', utf8.chstr(9658), distance / 1852.0, course),
75
                        type: 'normal|end-of-line',
76
                        scrollgroup: idx
77
                    }
78
                );
79
            }
80
            append(obj_infos, {type: 'separator'});
81
            var windowId = 'NEAREST AIRPORTS';
82
            var obj_s = size(obj_infos);
83
            var lines = 9;
84
            me.device.windows.draw(
85
                windowId,
86
                {x: 1014 - (name_max_length * 10), y: 778 - ((lines + 3) * 24), w: name_max_length * 10, l: lines, sep: 1},
87
                obj_infos,
88
                {lines: 4, columns: 1}
89
            );
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
            me.device.buttons.ENT = func (a = 0) {
100
                if (a) return;
101
                me.device.windows.del(windowId);
102
                var (_, selected) = split('-', me.device.windows.selected);
103
                var (airport_id, _) = split(" ", obj_infos[selected].text);
104
                call(me.device.display.MFD._ShowAirportInfo, [airport_id], me);
105
            };
106
        },
107
        'NEAREST INTERSECTIONS': func {
108
            call(me.device.display.MFD._NearestNavaids, ['fix'], me);
109
        },
110
        'NEAREST NDB': func {
111
            call(me.device.display.MFD._NearestNavaids, ['ndb'], me);
112
        },
113
        'NEAREST VOR': func {
114
            call(me.device.display.MFD._NearestNavaids, ['vor'], me);
115
        },
116
    },
117
    _NearestNavaids: func (navaid_type) {
118
        var navaids = findNavaidsWithinRange(99.99, navaid_type);
119
        var obj_infos = [
120
            {text: size(navaids) ~ ' NEAREST ' ~ string.uc(navaid_type), type: 'title'},
121
            {type: 'separator'},
122
        ];
123
        var idx = 0;
124
        var name_max_length = 20;
125
        foreach (var navaid; navaids) {
126
            var (course, distance) = courseAndDistance(navaid);
127
            var name = navaid.id ~ ' (' ~ navaid.name ~ ')';
128
            if (size(name) > name_max_length)
129
                name_max_length = size(name);
130

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

            
246
            foreach (var f; sort(keys(freqs), string.icmp))
247
                append(obj_infos, {text: sprintf('%-15s %.3f', f, freqs[f]), type: 'normal|end-of-line'});
248
        }
249
        var lines = size(obj_infos) - sep; # minus the separators
250
        var windowId = 'AIRPORT INFORMATIONS';
251
        me.device.windows.draw(
252
            windowId,
253
            {x: 720, y: 758 - ((lines + 3) * 24), w: 300, l: lines, sep: 1},
254
            obj_infos
255
        );
256
        me.device.buttons.CLR = func {
257
            me.device.windows.del(windowId);
258
            me.device.buttons.ENT = func;
259
            me.device.buttons.CLR = func;
260
            me.device.knobs.FmsInner = func;
261
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
262
        }
263
    },
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
264
};
265

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

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