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

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

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

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

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

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