Showing 3 changed files with 115 additions and 46 deletions
+51 -10
Nasal/buttons.nas
... ...
@@ -180,7 +180,7 @@ var buttonsClass = {
180 180
             {text: 'UNITS', type: 'title'},
181 181
             {type: 'separator'},
182 182
             {text: 'Pressure  :', type: 'normal'},
183
-            {text: data.settings.units.pressure == 'hpa' ? '  inHg >' : '<  hPa  ',
183
+            {text: data.settings.units.pressure == 'inhg' ? '  inHg >' : '<  hPa  ',
184 184
                 type: 'editable|end-of-line',
185 185
                 choices: [ '  inHg >', '<  hPa  '],
186 186
                 callback: func (id, selected) {
... ...
@@ -189,42 +189,83 @@ var buttonsClass = {
189 189
                         data.settings.units.pressure = 'inhg';
190 190
                     else
191 191
                         data.settings.units.pressure = 'hpa';
192
+                    me.device.display.updateBARO();
192 193
                 }
193 194
             },
194 195
             {text: 'Altitude  :', type: 'normal'},
195
-            {text: data.settings.units.altitude == 'ft' ? '   feet  >' : '< meters  ',
196
+            {text: units.altitude.from_ft == 1 ? '   feet  >' : '< meters  ',
196 197
                 type: 'editable|end-of-line',
197 198
                 choices: [ '   feet  >', '< meters  ' ],
198 199
                 callback: func (id, selected) {
199 200
                     var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
200
-                    if (u == 'feet')
201
+                    if (u == 'feet') {
201 202
                         data.settings.units.altitude = 'ft';
202
-                    else
203
+                        units.altitude.from_ft = 1;
204
+                        units.altitude.from_m  = M2FT;
205
+                    }
206
+                    else {
203 207
                         data.settings.units.altitude = 'm';
208
+                        units.altitude.from_ft = FT2M;
209
+                        units.altitude.from_m  = 1;
210
+                    }
211
+                }
212
+            },
213
+            {text: 'Distance  :', type: 'normal'},
214
+            {text: units.distance.from_nm == 1 ? '  NM >' : '< km  ',
215
+                type: 'editable|end-of-line',
216
+                choices: ['  NM >', '< km  '],
217
+                callback: func (id, selected) {
218
+                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
219
+                    if (u == 'NM') {
220
+                        data.settings.units.distance = 'nm';
221
+                        units.distance.from_nm = 1;
222
+                        units.distance.from_m  = M2NM * 1000;
223
+                    }
224
+                    else {
225
+                        data.settings.units.distance = 'km';
226
+                        units.distance.from_nm = NM2M / 1000;
227
+                        units.distance.from_m  = 0.001;
228
+                    }
204 229
                 }
205 230
             },
206 231
             {text: 'Speed     :', type: 'normal'},
207
-            {text: data.settings.units.speed == 'kt' ? '  knots  >' : '<  km/h   ',
232
+            {text: units.speed.from_kt == 1 ? '  knots  >' : '<  km/h   ',
208 233
                 type: 'editable|end-of-line',
209 234
                 choices: [ '  knots  >', '<  km/h   ' ],
210 235
                 callback: func (id, selected) {
211 236
                     var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
212
-                    if (u == 'knots')
237
+                    if (u == 'knots') {
213 238
                         data.settings.units.altitude = 'kt';
214
-                    else
239
+                        units.speed.from_kt  = 1;
240
+                        units.speed.from_kmh = MPS2KT / 3.6;
241
+                    }
242
+                    else {
215 243
                         data.settings.units.altitude = 'kmh';
244
+                        units.speed.from_kt  = KT2MPS * 3.6;
245
+                        units.speed.from_kmh = 1;
246
+                    }
247
+                    foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide', 'Vne']) {
248
+                        var speed = alerts.getValue(v) * units.speed.from_kt;
249
+                        data[v] = speed != nil ? speed : 9999;
250
+                    }
216 251
                 }
217 252
             },
218 253
             {text: 'Vert. Spd :', type: 'normal'},
219
-            {text: data.settings.units.altitude == 'fpm' ? '  ft/min >' : '<  m/min  ',
254
+            {text: units.vspeed.from_fpm == 1 ? '  ft/min >' : '<  m/min  ',
220 255
                 type: 'editable|end-of-line',
221 256
                 choices: [ '  ft/min >', '<  m/min  ' ],
222 257
                 callback: func (id, selected) {
223 258
                     var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
224
-                    if (u == 'ft/min')
259
+                    if (u == 'ft/min') {
225 260
                         data.settings.units.altitude = 'fpm';
226
-                    else
261
+                        units.vspeed.from_fpm = 1;
262
+                        units.vspeed.from_mpm = M2FT;
263
+                    }
264
+                    else {
227 265
                         data.settings.units.altitude = 'mpm';
266
+                        units.vspeed.from_fpm = FT2M;
267
+                        units.vspeed.from_mpm = 1;
268
+                    }
228 269
                 }
229 270
             },
230 271
             {type: 'separator'},
+41 -32
Nasal/display.nas
... ...
@@ -229,20 +229,22 @@ var displayClass = {
229 229
                 return sprintf('%5s', eta != nil ? eta : '--:--');
230 230
             }, 'Estimated Time Enroute'],
231 231
             TDR: [func {
232
-                if (data.fpSize == 0) return '---NM';
233
-                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
232
+                var unit = units.distance.from_nm == 1 ? 'NM' : 'km';
233
+                if (data.fpSize == 0) return '---' ~ unit;
234
+                var dist = getprop('/autopilot/route-manager/distance-remaining-nm') * units.distance.from_nm;
234 235
                 if (dist != nil)
235
-                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
236
+                    return sprintf(dist < 100 ? '%2.1f%s' : '%3i%s', dist, unit);
236 237
                 else
237
-                    return '---NM';
238
+                    return '---' ~ unit;
238 239
             }, 'Total Distance Remaining'],
239 240
             DIS: [func {
240
-                if (data.fpSize == 0) return '---NM';
241
-                var dist = getprop('/autopilot/route-manager/wp/dist');
241
+                var unit = units.distance.from_nm == 1 ? 'NM' : 'km';
242
+                if (data.fpSize == 0) return '---' ~ unit;
243
+                var dist = getprop('/autopilot/route-manager/wp/dist') * units.distance.from_nm;
242 244
                 if (dist != nil)
243
-                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
245
+                    return sprintf(dist < 100 ? '%2.1f%s' : '%3i%s', dist, unit);
244 246
                 else
245
-                    return '---NM';
247
+                    return '---' ~ unit;
246 248
             }, 'Distance remaining'],
247 249
             LEG: [func {
248 250
                 if (data.fpSize == 0) return '';
... ...
@@ -264,10 +266,11 @@ var displayClass = {
264 266
                     var ec = engine.getValue('fuel-flow-gph');
265 267
                     consumption += ec != nil ? ec : 0;
266 268
                 }
269
+                var unit = units.distance.from_nm == 1 ? 'NM' : 'km';
267 270
                 if (consumption > 0 and gs > 0)
268
-                    return sprintf('%3iNM', (total_fuel * gs) / consumption);
271
+                    return sprintf('%3i%s', (total_fuel * gs) / consumption * units.distance.from_nm, unit);
269 272
                 else
270
-                    return '---NM';
273
+                    return '---' ~ unit;
271 274
             }, 'Endurance'],
272 275
             ETA: [func {
273 276
                 var eteSeconds = getprop('/autopilot/route-manager/ete');
... ...
@@ -286,26 +289,31 @@ var displayClass = {
286 289
                     eta[0] -= 24;
287 290
                 return sprintf('%02i:%02i', eta[0], eta[1]);
288 291
             }, 'Estimated Time of Arrival'],
289
-            GS:  [func return sprintf('%3iKT', getprop('/velocities/groundspeed-kt')), 'Ground Speed'],
292
+            GS:  [func return sprintf('%3i%s', getprop('/velocities/groundspeed-kt') * units.speed.from_kt,
293
+                                      units.speed.from_kt == 1 ? 'KT' : 'km/h'),
294
+                 'Ground Speed'],
290 295
             TRK: [func return sprintf('%03i°', getprop('/orientation/track-deg')), 'Track'],
291
-            TAS: [func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')), 'True Air Speed'],
296
+            TAS: [func return sprintf('%i%s', getprop('/instrumentation/airspeed-indicator/true-speed-kt') * units.speed.from_kt,
297
+                                      units.speed.from_kt == 1 ? 'KT' : 'km/h' == 1),
298
+                 'True Air Speed'],
292 299
             FOB: [func return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')), 'Fuel on Board'],
293 300
             XTK: [func {
294 301
                 var xtk = nil;
295 302
                 var source = cdi.getValue('source');
296 303
                 if (source == 'NAV1')
297
-                    var xtk = abs(getprop('/instrumentation/nav[0]/crosstrack-error-m')) * M2NM;
304
+                    var xtk = abs(getprop('/instrumentation/nav[0]/crosstrack-error-m')) * units.distance.from_m;
298 305
                 elsif (source == 'NAV2')
299
-                    var xtk = abs(getprop('/instrumentation/nav[1]/crosstrack-error-m')) * M2NM;
306
+                    var xtk = abs(getprop('/instrumentation/nav[1]/crosstrack-error-m')) * units.distance.from_m;
300 307
                 elsif (source == 'GPS')
301
-                    var xtk = abs(getprop('/instrumentation/gps/wp/wp[1]/course-error-nm'));
308
+                    var xtk = abs(getprop('/instrumentation/gps/wp/wp[1]/course-error-nm')) * units.distance.from_nm;
302 309
 
310
+                var unit = units.distance.from_nm = 1 ? 'NM' : 'km';
303 311
                 if (xtk == nil)
304
-                    return ' ---NM';
312
+                    return ' ---' ~ unit;
305 313
                 elsif (xtk > 99.9)
306
-                    return ' ++.+NM';
314
+                    return ' ++.+' ~ unit;
307 315
                 else
308
-                    return sprintf('%2.1fNM', xtk);
316
+                    return sprintf('%2.1f%s', xtk, unit);
309 317
             }, 'Crosstrack Error'],
310 318
             MSA: [func {
311 319
                 data._msa_spd        = getprop('/velocities/groundspeed-kt');
... ...
@@ -323,7 +331,7 @@ var displayClass = {
323 331
                             if (data._msa_alt_intern < _geodinfo[0]) data._msa_alt_intern = _geodinfo[0];
324 332
                         data._msa_point += 1;
325 333
                         if (data._msa_point > 10) {
326
-                            data._msa_alt         = math.round((1000 + data._msa_alt_intern * M2FT) / 100) * 100;
334
+                            data._msa_alt         = math.round((1000 + data._msa_alt_intern * units.altitude.from_m) / 100) * 100;
327 335
                             data._msa_point       = 0;
328 336
                             data._msa_alt_intern  = 0;
329 337
                             data.timers.MSA_geodinfo.stop();
... ...
@@ -331,7 +339,7 @@ var displayClass = {
331 339
                     });
332 340
                 }
333 341
                 data.timers.MSA_geodinfo.start();
334
-                return data._msa_alt == -1 ? '-----ft' : sprintf('%5ift', data._msa_alt);
342
+                return data._msa_alt == -1 ? '-----ft' : sprintf('%5i%s', data._msa_alt, units.altitude.from_m == 1 ? 'm' : 'ft');
335 343
             }, 'Minimum Safe Altitude'],
336 344
 #            BRG: [func return '---°', 'Bearing'],
337 345
 #            ESA: [func return '-----', 'Enroute Safe Altitude'],
... ...
@@ -715,12 +723,13 @@ var displayClass = {
715 723
         var vsi = data.vsi;
716 724
         me.screenElements.VSIText
717 725
             .setText(num(math.round(vsi, 10)));
718
-        if (vsi > 4500)
719
-            vsi = 4500;
720
-        elsif (vsi < -4500)
721
-            vsi = -4500;
726
+        var scale = units.vspeed.from_fpm == 1 ? 1 : 10;
727
+        if (vsi > 4500 / scale)
728
+            vsi = 4500 / scale;
729
+        elsif (vsi < -4500 / scale)
730
+            vsi = -4500 / scale;
722 731
         me.screenElements.VSI
723
-            .setTranslation(0, vsi * -0.03465);
732
+            .setTranslation(0, vsi * -0.03465 * scale);
724 733
     },
725 734
 #}}}
726 735
 
... ...
@@ -748,7 +757,7 @@ var displayClass = {
748 757
                 .setColorFill(0,0,0);
749 758
         }
750 759
         foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
751
-            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) < 30)
760
+            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) * units.speed.from_kt < 30)
752 761
                 me.screenElements['IAS-' ~ v]
753 762
                     .setTranslation(0, (ias - data[v]) * 5.711)
754 763
                     .show();
... ...
@@ -782,10 +791,11 @@ var displayClass = {
782 791
 
783 792
     updateTAS: func {
784 793
 # updates the True Airspeed and GroundSpeed indicators {{{
794
+        var unit = units.speed.from_kt == 1 ? 'KT' : 'km/h';
785 795
         me.screenElements['TAS-text']
786
-            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
796
+            .setText(sprintf('%i%s', getprop('/instrumentation/airspeed-indicator/true-speed-kt') * units.speed.from_kt, unit));
787 797
         me.screenElements['GSPD-text']
788
-            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
798
+            .setText(sprintf('%i%s', getprop('/velocities/groundspeed-kt') * units.speed.from_kt, unit));
789 799
     },
790 800
 #}}}
791 801
 
... ...
@@ -953,14 +963,13 @@ var displayClass = {
953 963
 
954 964
     updateBARO : func () {
955 965
 # update BARO widget {{{
956
-        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
966
+        var fmt = data.settings.units.pressure == 'inhg' ? '%.2f%s' : '%i%s';
957 967
         me.screenElements['BARO-text']
958 968
             .setText(sprintf(fmt,
959
-                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
960
-                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
969
+                        getprop('/instrumentation/altimeter/setting-' ~ data.settings.units.pressure),
970
+                        data.settings.units.pressure == 'inhg' ? 'in' : 'hPa')
961 971
                 );
962 972
     },
963
-    _baro_unit : 'inhg',
964 973
 #}}}
965 974
 
966 975
     updateHSI : func () {
+23 -4
zkv1000.nas
... ...
@@ -26,6 +26,25 @@ var flightdeck = {};
26 26
 
27 27
 var autopilot = {};
28 28
 
29
+var units = {
30
+    speed : {
31
+        from_kt  : 1,
32
+        from_kmh : MPS2KT * 3.6,
33
+    },
34
+    altitude : {
35
+        from_ft : 1,
36
+        from_m  : M2FT,
37
+    },
38
+    vspeed : {
39
+        from_fpm : 1,
40
+        from_mpm : M2FT,
41
+    },
42
+    distance : {
43
+        from_m : M2NM / 1000,
44
+        from_nm : 1,
45
+    },
46
+};
47
+
29 48
 var data = { # set of data common to all devices
30 49
     roll : 0,
31 50
     pitch : 0,
... ...
@@ -60,9 +79,9 @@ var data = { # set of data common to all devices
60 79
             func {
61 80
                 data.roll = getprop('/orientation/roll-deg');
62 81
                 data.pitch = getprop('orientation/pitch-deg');
63
-                data.vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm');
64
-                data.ias = getprop('/velocities/airspeed-kt');
65
-                data.alt = getprop('/instrumentation/altimeter/indicated-altitude-ft');
82
+                data.vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm') * units.vspeed.from_fpm;
83
+                data.ias = getprop('/velocities/airspeed-kt') * units.speed.from_kt;
84
+                data.alt = getprop('/instrumentation/altimeter/indicated-altitude-ft') * units.altitude.from_ft;
66 85
                 data.hdg = getprop('/orientation/heading-deg');
67 86
                 data.aoa = getprop('/orientation/alpha-deg');
68 87
             }
... ...
@@ -130,7 +149,7 @@ var init_props = func {
130 149
     alerts.getNode('alert', 1).setBoolValue(0);
131 150
     alerts.getNode('message', 1).setValue('');
132 151
     foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide', 'Vne']) {
133
-        var speed = alerts.getValue(v);
152
+        var speed = alerts.getValue(v) * units.speed.from_kt;
134 153
         data[v] = speed != nil ? speed : 9999;
135 154
     }
136 155
     var aoa = alerts.getValue('stall-aoa');