Showing 2 changed files with 104 additions and 54 deletions
+9 -6
Nasal/MFD.pages.nas
... ...
@@ -17,12 +17,12 @@ displayClass.MFD = {
17 17
                 {text: 'DATA FIELD NUMBER', type: 'normal'},
18 18
                 {text: '  1 >', type: 'selected|end-of-line', choices: ['  1 >', '< 2 >', '< 3 >', '< 4  ']},
19 19
             ];
20
-            var column = 0;
21
-            var colmax = 5;
22
-            foreach (var text; me.device.display.updateNavigationBox(1)) {
20
+            foreach (var item; keys(me.device.display.navbox)) {
21
+                if (item == 'LEG') # LEG only displayed on PFD navigation box
22
+                    continue;
23 23
                 append(obj_infos, {
24
-                    text: sprintf('%-5s', text),
25
-                    type: 'editable' ~ ((column == colmax) ? '|end-of-line' : ''),
24
+                    text: sprintf('%-3s ', item),
25
+                    type: 'editable',
26 26
                     callback: func (id, selected) {
27 27
                         var field = string.trim(me.device.windows.state[id].objects[3].text,
28 28
                                                 0,
... ...
@@ -31,7 +31,10 @@ displayClass.MFD = {
31 31
                             .setText(string.trim(me.device.windows.state[id].objects[selected].text, 1));
32 32
                     }
33 33
                 });
34
-                column += (column < colmax) ? 1 : -column;
34
+                append(obj_infos, {
35
+                    text: sprintf('(%s)', me.device.display.navbox[item][1]),
36
+                    type: 'normal|end-of-line',
37
+                });
35 38
             }
36 39
             var windowId = 'SYSTEM SETUP';
37 40
             me.device.windows.draw( windowId, obj_infos );
+95 -48
Nasal/display.nas
... ...
@@ -213,6 +213,95 @@ var displayClass = {
213 213
                 left: contains(m.screenElements, 'EIS') ? math.ceil(m.screenElements['EIS'].getTransformedBounds()[2]) : 0,
214 214
             };
215 215
         }
216
+
217
+        m.navbox = {
218
+# {{{ the data to show info in navbox
219
+            DTK: [func {
220
+                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
221
+                if (dtk == nil)
222
+                    return '---°';
223
+                else
224
+                    return sprintf('%03i°', dtk);
225
+            }, 'Desired Track'],
226
+            ETE: [func {
227
+                if (data.fpSize == 0) return '--:--';
228
+                var eta = getprop('/autopilot/route-manager/wp/eta');
229
+                return sprintf('%5s', eta != nil ? eta : '--:--');
230
+            }, 'Estimated Time Enroute'],
231
+            TDR: [func {
232
+                if (data.fpSize == 0) return '---NM';
233
+                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
234
+                if (dist != nil)
235
+                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
236
+                else
237
+                    return '---NM';
238
+            }, 'Total Distance Remaining'],
239
+            DIS: [func {
240
+                if (data.fpSize == 0) return '---NM';
241
+                var dist = getprop('/autopilot/route-manager/wp/dist');
242
+                if (dist != nil)
243
+                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
244
+                else
245
+                    return '---NM';
246
+            }, 'Distance remaining'],
247
+            LEG: [func {
248
+                if (data.fpSize == 0) return '';
249
+                var route = m.device.map.layers.route;
250
+                var wp = route.flightPlan[route.currentLeg.index];
251
+                return sprintf(' %s %s %s', wp[0].name, utf8.chstr(9658), wp[1].name);
252
+            }, ''], # not listed in MFD menu, on PFD only the leg is shown not the item
253
+            LDG: [func {
254
+                var eteSeconds = getprop('/autopilot/route-manager/ete');
255
+                var eteHours = math.floor(eteSeconds / 3600);
256
+                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
257
+                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
258
+            }, 'ETA at Final Destination'],
259
+            END: [func {
260
+                var total_fuel = getprop('/consumables/fuel/total-fuel-gals');
261
+                var gs = getprop('/velocities/groundspeed-kt');
262
+                var consumption = 0;
263
+                foreach(var engine; props.globals.getNode('/engines').getChildren('engine')) {
264
+                    var ec = engine.getValue('fuel-flow-gph');
265
+                    consumption += ec != nil ? ec : 0;
266
+                }
267
+                if (consumption > 0 and gs > 0)
268
+                    return sprintf('%3iNM', (total_fuel * gs) / consumption);
269
+                else
270
+                    return '---NM';
271
+            }, 'Endurance'],
272
+            ETA: [func {
273
+                var eteSeconds = getprop('/autopilot/route-manager/ete');
274
+                var eta_hours = getprop('/sim/time/utc/hour');
275
+                var eteHours = math.floor(eteSeconds / 3600);
276
+                if (eteHours > 12)
277
+                    return '--:--';
278
+                var eta_minutes = int((eteSeconds - (eteHours * 3600)) / 60) + getprop('/sim/time/utc/minute');
279
+                if (eta_minutes > 59) {
280
+                    eta_minutes -= 60;
281
+                    eta_hours += 1;
282
+                }
283
+                eta_hours += eteHours;
284
+                if (eta_hours > 23)
285
+                    eta_hours -= 24;
286
+                return sprintf('%02i:%02i', eta_hours, eta_minutes);
287
+            }, 'Estimated Time of Arrival'],
288
+            GS:  [func return sprintf('%3iKT', getprop('/velocities/groundspeed-kt')), 'Ground Speed'],
289
+            TRK: [func return sprintf('%03i°', getprop('/orientation/track-deg')), 'Track'],
290
+            TAS: [func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')), 'True Air Speed'],
291
+            FOB: [func { return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')); }, 'Fuel on Board'],
292
+#            BRG: [func return '---°', 'Bearing'],
293
+#            ESA: [func return '-----', 'Enroute Safe Altitude'],
294
+#            ISA: [func return '-----', 'ISA Relative Temperature'],
295
+#            MSA: [func return '----ft', 'Minimum Safe Altitude'],
296
+#            TKE: [func return ' ---°', 'Track Angle Error'],
297
+#            VSR: [func return ' ----', 'Vertical Speed Required'],
298
+#            XTK: [func return ' ---NM', 'Crosstrack Error'],
299
+# }}}
300
+        };
301
+        if (m.device.role == 'PFD')
302
+            foreach (var item; keys(m.navbox))
303
+                if (item != 'LEG' and item != 'DIS' and item != 'ETE')
304
+                    delete(m.navbox, item);
216 305
         return m;
217 306
     },
218 307
 #}}}
... ...
@@ -448,67 +537,25 @@ var displayClass = {
448 537
     },
449 538
 #}}}
450 539
 
451
-    updateNavigationBox : func (getDataFields = 0) {
540
+    updateNavigationBox : func {
452 541
 # update Navigation Box on MFD and PFD header {{{
453 542
         var enroute = getprop('/autopilot/route-manager/current-wp') > -1;
454 543
         var route = me.device.map.layers.route;
455
-        var fpSize = size(route.flightPlan);
456
-        var navbox = {
457
-            DTK: func {
458
-                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
459
-                if (dtk == nil)
460
-                    return '---°';
461
-                else
462
-                    return sprintf('%03i°', dtk);
463
-            },
464
-            ETE: func {
465
-                if (fpSize == 0) return '--:--';
466
-                var eteSeconds = getprop('/autopilot/route-manager/ete');
467
-                var eteHours = math.floor(eteSeconds / 3600);
468
-                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
469
-                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
470
-            },
471
-            DIS: func {
472
-                if (fpSize == 0) return '---NM';
473
-                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
474
-                return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
475
-            },
476
-            LEG: func {
477
-                if (fpSize == 0) return '';
478
-                var wp = route.flightPlan[route.currentLeg.index];
479
-                return sprintf(' %s %s %s', wp[0].name, utf8.chstr(9658), wp[1].name);
480
-            },
481
-            GS : func return sprintf('%iKT', getprop('/velocities/groundspeed-kt')),
482
-            TRK: func return sprintf('%03i°', getprop('/orientation/track-deg')),
483
-            TAS: func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')),
484
-            BRG: func return '---°',
485
-            END: func return '---NM',
486
-            ESA: func return '-----',
487
-            ETA: func return '--:--',
488
-            FOB: func return '---lbs',
489
-            ISA: func return '-----',
490
-            LDG: func return '--:--',
491
-            MSA: func return '----ft',
492
-            TKE: func return '---°',
493
-            VSR: func return '----',
494
-            XTK: func return '---NM',
495
-        };
496
-        if (getDataFields)
497
-            return keys(navbox);
544
+        data.fpSize = size(route.flightPlan);
498 545
         if (me.device.role == 'MFD') {
499 546
             for (var i=1; i<=4; i+=1)
500 547
                 me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
501 548
                     .setVisible(enroute)
502 549
                     .setText(
503
-                        navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].setVisible(enroute).get('text')]()
550
+                        me.navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].setVisible(enroute).get('text')][0]()
504 551
                     );
505 552
         }
506 553
         else { # PFD
507 554
             me.screenElements['ETE'].setVisible(enroute);
508 555
             me.screenElements['DIS'].setVisible(enroute);
509
-            me.screenElements['ETE-text'].setVisible(enroute).setText(navbox.ETE());
510
-            me.screenElements['DIS-text'].setVisible(enroute).setText(navbox.DIS());
511
-            me.screenElements['LEG-text'].setVisible(enroute).setText(navbox.LEG());
556
+            me.screenElements['ETE-text'].setVisible(enroute).setText(me.navbox.ETE[0]());
557
+            me.screenElements['DIS-text'].setVisible(enroute).setText(me.navbox.DIS[0]());
558
+            me.screenElements['LEG-text'].setVisible(enroute).setText(me.navbox.LEG[0]());
512 559
         }
513 560
     },
514 561
 #}}}