zkv1000 / Nasal / MFD.pages.nas /
Newer Older
328 lines | 14.47kb
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 column = 0;
12
            var colmax = 5;
13
            foreach (var text; me.device.display.updateNavigationBox(1)) {
14
                append(obj_infos, {
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
15
                    text: sprintf('%-5s', text),
16
                    type: 'editable' ~ ((column == colmax) ? '|end-of-line' : ''),
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
17
                    callback: func (id, selected) {
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
18
                        var field = string.trim(me.device.windows.state[id].objects[3].text,
19
                                                0,
20
                                                func (c) c == `<` or c == `>` or c == ` `);
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
21
                        me.device.display.screenElements['DATA-FIELD' ~ field ~ '-ID-text']
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
22
                            .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
23
                    }
24
                });
improve MFD system settings ...
Sébastien MARQUE authored on 2020-05-03
25
                column += (column < colmax) ? 1 : -column;
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
26
            }
27
            var windowId = 'SYSTEM SETUP';
make use of new window drawi...
Sébastien MARQUE authored on 2020-05-03
28
            me.device.windows.draw( windowId, obj_infos );
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
29
            me.device.buttons.CLR = func {
30
                me.device.windows.del(windowId);
31
                me.device.buttons.ENT = func;
32
                me.device.buttons.CLR = func;
33
                me.device.knobs.FmsInner = func;
34
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
35
            }
36
            me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
37
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
38
            me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
39
        },
40
    },
add MFD pages for nearest ai...
Sébastien MARQUE authored on 2020-04-27
41
    NRST : {
42
        'NEAREST AIRPORTS': func {
43
            var airports = findAirportsWithinRange(99.99);
44
            var obj_infos = [
45
                {text: size(airports) ~ ' NEAREST AIRPORTS', type: 'title'},
46
                {type: 'separator'},
47
            ];
48
            var name_max_length = 0;
49
            forindex (var idx; airports) {
50
                var info = airportinfo(airports[idx].id);
51
                var (course, distance) = courseAndDistance(info);
52
                var name = sprintf('%s (%s)', airports[idx].id, airports[idx].name);
53
                if (size(name) > name_max_length)
54
                    name_max_length = size(name);
55

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

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

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

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

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