Showing 1 changed files with 212 additions and 0 deletions
+212
Nasal/MFD.pages.nas
... ...
@@ -49,6 +49,218 @@ displayClass.MFD = {
49 49
             me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
50 50
         },
51 51
     },
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
+    },
52 264
 };
53 265
 
54 266
 displayClass.setMFDPages = func {