zkv1000 / Nasal / display.nas /
Newer Older
1424 lines | 55.716kb
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1
# vim: set foldmethod=marker foldmarker={{{,}}} :
commit initial
Sébastien MARQUE authored on 2017-03-07
2
var displayClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
3
    new: func(device) {
add new vim folds
Sébastien MARQUE authored on 2017-03-15
4
# the contructor {{{
commit initial
Sébastien MARQUE authored on 2017-03-07
5
        var m = { parents: [ displayClass ] };
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
6

            
commit initial
Sébastien MARQUE authored on 2017-03-07
7
        m.display = canvas.new({
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
8
                "name"      : device.name,
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
9
                "size"      : [1280, 1280],
10
                "view"      : [1024, 768],
commit initial
Sébastien MARQUE authored on 2017-03-07
11
                "mipmapping": 1
12
        });
13
        m.display.addPlacement({
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
14
                "node": device.data['screen-object'] != nil ? device.data['screen-object'] : "Screen",
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
15
                "parent": device.name
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
16
            });
commit initial
Sébastien MARQUE authored on 2017-03-07
17
        m.display.setColorBackground(0,0,0);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
18
        m.role = device.role;
pass device pointer to displ...
Sébastien MARQUE authored on 2017-03-14
19
        m.device = device;
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
20
        m.screenElements = {};
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
21
        m.screen = m.display
22
            .createGroup()
23
            .show();
commit initial
Sébastien MARQUE authored on 2017-03-07
24

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
25
        m.timers = {};
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
26
        # Softkeys revert to the previous level after 45 seconds of inactivity.
27
        m.softkeys_inactivity_delay = 45;
28

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
29
        var groups = {
30
            show : [
31
                'Header',
32
                'SoftKeysTexts',
33
                'COMM',
34
                'NAV',
35
                'nav-freq-switch',
36
                'comm-freq-switch',
37
            ],
38
            text: [
39
                'nav1-standby-freq', 'nav1-selected-freq', 'nav1-id',
40
                'nav2-standby-freq', 'nav2-selected-freq', 'nav2-id',
41
                'comm1-standby-freq', 'comm1-selected-freq',
42
                'comm2-standby-freq', 'comm2-selected-freq',
43
            ],
44
            hide : [ 'Failures', 'NAV-COMM-Failures' ],
45
            clip: [ ],
46
        };
47

            
48
        for (var k = 0; k < 12; k += 1) {
49
            append(groups.text, sprintf("SoftKey%02i-text", k));
50
            append(groups.show, sprintf("SoftKey%02i-bg", k));
51
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
52

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
53
        if (m.device.role == 'PFD') {
54
            append(groups.show,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
55
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
56
                'XPDR-TIME',
57
                'FlightInstruments',
58
                'Horizon',
59
                'bankPointer',
60
                'VSI',
61
                'Rose',
62
                'Heading-bug',
63
                'PFD-Widgets',
64
                'Trends',
65
                'Airspeed-Trend-Indicator',
66
                'Altitude-Trend-Indicator',
67
                'OAT',
68
                'IAS-bg',
69
                'TAS',
70
                'GSPD',
71
                'BARO-bg',
72
                'SlipSkid',
73
                'IAS-Vx', 'IAS-Vy', 'IAS-Vr', 'IAS-Vglide',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
74
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
75
            );
76
            append(groups.hide,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
77
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
78
                'EIS',
79
                'CDI',
80
                'OMI', 'MarkerBG', 'MarkerText',
81
                'VDI',
82
                'NAV1-pointer', 'NAV1-CDI', 'NAV1-FROM', 'NAV1-TO',
83
                'NAV2-pointer', 'NAV2-CDI', 'NAV2-FROM', 'NAV2-TO',
84
                'GPS-pointer', 'GPS-CDI', 'GPS-CTI', 'GPS-CTI-diamond', 'GPS-FROM', 'GPS-TO',
85
                'BRG1-pointer',
86
                'BRG2-pointer',
87
                'SelectedHDG-bg',
88
                'SelectedHDG-bgtext',
89
                'SelectedHDG-text',
90
                'SelectedCRS-bg',
91
                'SelectedCRS-bgtext',
92
                'SelectedCRS-text',
93
                'SelectedALT', 'SelectedALT-bug', 'SelectedALT-bg', 'SelectedALT-symbol',
94
                'TAS',
95
                'GSPD',
96
                'WindData',
97
                'Reversionnary',
98
                'Annunciation',
99
                'Comparator',
100
                'BRG1',
101
                'BRG2',
102
                'DME1',
103
                'PFD-Map-bg',
104
                'PFD-Multilines',
105
                'MapOrientation',
106
                'WindData', 'WindData-OPTN1', 'WindData-OPTN2', 'WindData-OPTN1-HDG', 'WindData-OPTN2-symbol', 'WindData-OPTN2-headwind', 'WindData-OPTN2-crosswind', 'WindData-NODATA',
107
                'AOA', 'AOA-needle', 'AOA-text', 'AOA-approach',
108
                'MFD-navbox',
109
                'Traffic',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
110
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
111
            );
112
            append(groups.clip,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
113
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
114
                'SpeedLint1',
115
                'SpeedTape',
116
                'LintAlt',
117
                'AltLint00011',
118
                'PitchScale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
119
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
120
            );
121
            append(groups.text,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
122
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
123
                'SelectedALT-text',
124
                'TAS-text',
125
                'GSPD-text',
126
                'TIME-text',
127
                'OAT-text',
128
                'VSIText',
129
                'Speed110',
130
                'Alt11100',
131
                'HDG-text',
132
                'BARO-text',
133
                'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
134
                'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
135
                'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
136
                'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
137
                'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
138
                'XPDR-MODE-text', 'XPDR-DIGIT-3-text', 'XPDR-DIGIT-2-text', 'XPDR-DIGIT-1-text', 'XPDR-DIGIT-0-text',
139
                'ETE', 'ETE-text', 'DIS', 'DIS-text', 'LEG-text',
140
                'LATMOD-Armed-text', 'LATMOD-Active-text',
141
                'AP-Status-text', 'YD-Status-text',
142
                'VERMOD-Active-text', 'VERMOD-Armed-text', 'VERMOD-Reference-text',
143
                'AltBigC', 'AltSmallC'
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
144
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
145
            );
146
            for (var place = 1; place <= 6; place +=1) {
147
                append(groups.text,
148
                    'AltBigU' ~ place,
149
                    'AltSmallU' ~ place,
150
                    'AltBigD' ~ place,
151
                    'AltSmallD' ~ place
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
152
                );
animation ALT
Sébastien MARQUE authored on 2017-03-11
153
            }
cosmetics
Sébastien MARQUE authored on 2020-05-12
154
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/PFD.svg');
155
        }
156
        else {
157
            var eis_file = eis.getValue('type');
158
            if (eis_file == nil)
159
                eis_file = eis.getValue('file');
160

            
161
            if (eis_file != nil) {
162
                if (find('/', eis_file) == -1)
163
                    eis_file = data.zkv1000_dir ~ 'Nasal/EIS/' ~ eis_file ~ '.nas';
164
                elsif (split('/', eis_file)[0] == 'Aircraft') {
165
                    var path = split('/', eis_file);
166
                    if (getprop('/sim/fg-aircraft') != nil) {
167
                        eis_file = getprop('/sim/fg-aircraft');
168
                        for (var i = 1; i < size(path); i += 1)
169
                            eis_file ~= '/' ~ path[i];
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
170
                    }
cosmetics
Sébastien MARQUE authored on 2020-05-12
171
                    else
172
                        eis_file = getprop('/sim/fg-root') ~ '/' ~ eis_file;
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
173
                }
cosmetics
Sébastien MARQUE authored on 2020-05-12
174
            }
175
            else
176
                eis_file = data.zkv1000_dir ~ 'Nasal/EIS/none.nas';
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
177

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
178
            if (io.stat(eis_file) == nil
179
            and print(eis_file ~ ' not found'))
180
                eis_file = data.zkv1000_dir ~ 'Nasal/EIS/none.nas';
181
            io.load_nasal(eis_file, 'zkv1000');
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
182

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
183
            if (contains(m.parents[0], 'showEIS'))
184
                m.showEIS(groups);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
185

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
186
            append(groups.hide, 'PFD-navbox');
187
            for (var i=1; i <= 4; i+=1)
188
                foreach (var t; ['ID', 'VAL'])
189
                    append(groups.text, 'DATA-FIELD' ~ i ~ '-' ~ t ~ '-text');
190
        }
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
191

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
192
        canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/softkeys.svg');
193
        canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/header-nav-comm.svg');
animation ALT
Sébastien MARQUE authored on 2017-03-11
194

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
195
        m.loadGroup(groups);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
196

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
197
        if (m.device.role == 'PFD') {
198
            m.device.data.aoa = 0;
199
            m.device.data['aoa-auto'] = 0;
200
            m.device.data.mapclip = {
201
                top: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[1]) - 1,
202
                right: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[2]) - 1,
203
                bottom: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[3]) - 1,
204
                left: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[0]) - 1,
205
            };
206
        }
207
        else {
208
            m.device.data.mapclip = {
209
                top: math.ceil(m.screenElements['Header'].getTransformedBounds()[3]),
210
                right: m.display.get('view[0]'),
211
                bottom: math.ceil(m.screenElements['SoftKeysTexts'].getTransformedBounds()[1]),
212
                left: contains(m.screenElements, 'EIS') ? math.ceil(m.screenElements['EIS'].getTransformedBounds()[2]) : 0,
213
            };
214
        }
navigation box content
Sébastien MARQUE authored on 2020-05-12
215

            
216
        m.navbox = {
217
# {{{ the data to show info in navbox
218
            DTK: [func {
219
                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
220
                if (dtk == nil)
221
                    return '---°';
222
                else
223
                    return sprintf('%03i°', dtk);
224
            }, 'Desired Track'],
225
            ETE: [func {
226
                if (data.fpSize == 0) return '--:--';
227
                var eta = getprop('/autopilot/route-manager/wp/eta');
228
                return sprintf('%5s', eta != nil ? eta : '--:--');
229
            }, 'Estimated Time Enroute'],
230
            TDR: [func {
231
                if (data.fpSize == 0) return '---NM';
232
                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
233
                if (dist != nil)
234
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
235
                else
236
                    return '---NM';
237
            }, 'Total Distance Remaining'],
238
            DIS: [func {
239
                if (data.fpSize == 0) return '---NM';
240
                var dist = getprop('/autopilot/route-manager/wp/dist');
241
                if (dist != nil)
242
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
243
                else
244
                    return '---NM';
245
            }, 'Distance remaining'],
246
            LEG: [func {
247
                if (data.fpSize == 0) return '';
248
                var route = m.device.map.layers.route;
249
                var wp = route.flightPlan[route.currentLeg.index];
250
                return sprintf(' %s %s %s', wp[0].name, utf8.chstr(9658), wp[1].name);
251
            }, ''], # not listed in MFD menu, on PFD only the leg is shown not the item
252
            LDG: [func {
253
                var eteSeconds = getprop('/autopilot/route-manager/ete');
254
                var eteHours = math.floor(eteSeconds / 3600);
255
                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
256
                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
257
            }, 'ETA at Final Destination'],
258
            END: [func {
259
                var total_fuel = getprop('/consumables/fuel/total-fuel-gals');
260
                var gs = getprop('/velocities/groundspeed-kt');
261
                var consumption = 0;
262
                foreach(var engine; props.globals.getNode('/engines').getChildren('engine')) {
263
                    var ec = engine.getValue('fuel-flow-gph');
264
                    consumption += ec != nil ? ec : 0;
265
                }
266
                if (consumption > 0 and gs > 0)
267
                    return sprintf('%3iNM', (total_fuel * gs) / consumption);
268
                else
269
                    return '---NM';
270
            }, 'Endurance'],
271
            ETA: [func {
272
                var eteSeconds = getprop('/autopilot/route-manager/ete');
273
                var eta_hours = getprop('/sim/time/utc/hour');
274
                var eteHours = math.floor(eteSeconds / 3600);
275
                if (eteHours > 12)
276
                    return '--:--';
277
                var eta_minutes = int((eteSeconds - (eteHours * 3600)) / 60) + getprop('/sim/time/utc/minute');
278
                if (eta_minutes > 59) {
279
                    eta_minutes -= 60;
280
                    eta_hours += 1;
281
                }
282
                eta_hours += eteHours;
283
                if (eta_hours > 23)
284
                    eta_hours -= 24;
285
                return sprintf('%02i:%02i', eta_hours, eta_minutes);
286
            }, 'Estimated Time of Arrival'],
287
            GS:  [func return sprintf('%3iKT', getprop('/velocities/groundspeed-kt')), 'Ground Speed'],
288
            TRK: [func return sprintf('%03i°', getprop('/orientation/track-deg')), 'Track'],
289
            TAS: [func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')), 'True Air Speed'],
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
290
            FOB: [func return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')), 'Fuel on Board'],
291
            XTK: [func {
292
                var source = cdi.getValue('source');
293
                if (source == 'NAV1')
294
                    var xtk = sprintf('/instrumentation/nav[0]/crosstrack-error-m');
295
                elsif (source == 'GPS')
296
                    var xtk = sprintf('/instrumentation/gps/wp/wp[1]/course-error-nm');
297
                return ' ---NM'
298
            }, 'Crosstrack Error'],
299
            MSA: [func {
300
                data._msa_spd        = getprop('/velocities/groundspeed-kt');
301
                data._msa_track      = getprop('/orientation/track-deg');
302
                if (! contains(data.timers, 'MSA_geodinfo')) {
303
                    data._msa_alt         = -1;
304
                    data._msa_point       = 1;
305
                    data._msa_alt_intern  = 0;
306
                    data.timers.MSA_geodinfo = maketimer(0, func {
307
                        var geo = greatCircleMove(
308
                                data._msa_track,
309
                                (data._msa_spd / 12) / 10 * data._msa_point);
310
                        var (alt, _) = geodinfo(geo.lat, geo.lon, 10000);
311
                        if (data._msa_alt_intern < alt) data._msa_alt_intern = alt;
312
                        data._msa_point += 1;
313
                        if (data._msa_point > 10) {
314
                            data._msa_alt         = math.round((1000 + data._msa_alt_intern * M2FT) / 100) * 100;
315
                            data._msa_point       = 0;
316
                            data._msa_alt_intern  = 0;
317
                        }
318
                        else
319
                            data.timers.MSA_geodinfo.restart(0);
320
                    });
321
                    data.timers.MSA_geodinfo.singleShot = 1;
322
                }
323
                data.timers.MSA_geodinfo.start();
324
                return data._msa_alt == -1 ? '-----ft' : sprintf('%5ift', data._msa_alt);
325
            }, 'Minimum Safe Altitude'],
navigation box content
Sébastien MARQUE authored on 2020-05-12
326
#            BRG: [func return '---°', 'Bearing'],
327
#            ESA: [func return '-----', 'Enroute Safe Altitude'],
328
#            ISA: [func return '-----', 'ISA Relative Temperature'],
329
#            TKE: [func return ' ---°', 'Track Angle Error'],
330
#            VSR: [func return ' ----', 'Vertical Speed Required'],
331
# }}}
332
        };
333
        if (m.device.role == 'PFD')
334
            foreach (var item; keys(m.navbox))
335
                if (item != 'LEG' and item != 'DIS' and item != 'ETE')
336
                    delete(m.navbox, item);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
337
        return m;
338
    },
339
#}}}
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
340

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
341
    off: func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
342
        me.parents[0]._updateRadio = func; # because of the settimers...
343
        me.parents[0].updateEIS = func;
344
        foreach(var timer; keys(me.timers)) {
345
            me.timers[timer].stop();
346
            delete(me.timers, timer);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
347
        }
poweroff improved
Sébastien MARQUE authored on 2020-05-16
348
        foreach (var e; keys(me.screenElements)) {
349
            if (typeof(me.screenElements[e]) != 'nil')
350
                me.screenElements[e].hide();
351
            delete(me.screenElements, e);
352
        }
353
        foreach (var e; keys(me.screenElements)) {
354
            if (typeof(me.screenElements[e]) != 'nil')
355
                me.screenElements[e].hide();
356
            delete(me.screenElements, e);
357
        }
358
        foreach (var e; keys(me.screenElements)) {
359
            if (typeof(me.screenElements[e]) != 'nil')
360
                me.screenElements[e].hide();
361
            delete(me.screenElements, e);
362
        }
363
        me.screen.setVisible(0);
364
        settimer(func {
365
                me.screen.removeAllChildren();
366
                me.screen.del();
367
                me.display.del();
368
        }, 0.1);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
369
    },
370

            
371
# temporary Widget Display for HDG and CRS modification {{{
372

            
373
    temporaryWidgetDisplay : {},
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
374

            
375
    timerTrigger : func {
376
        var now = systime();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
377
        foreach (var id; keys(me.temporaryWidgetDisplay)) {
378
            if (me.temporaryWidgetDisplay[id] < now) {
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
379
                me.screenElements[id].hide();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
380
                delete(me.temporaryWidgetDisplay, id);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
381
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
382
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
383
    },
384

            
385
    addTimer : func (duration, element) {
386
        if (typeof(element) == 'scalar')
387
            element = [ element ];
388
        var end = systime() + duration;
389
        foreach (var e; element)
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
390
            me.temporaryWidgetDisplay[e] = end;
commit initial
Sébastien MARQUE authored on 2017-03-07
391
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
392
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
393

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
394
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
395
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
396
        if (me.device.role == 'PFD') {
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
397
            me.timers.updateAI     = maketimer(0.1, me, me.updateAI     );
398
            me.timers.updateVSI    = maketimer(0.1, me, me.updateVSI    );
399
            me.timers.updateIAS    = maketimer(0.1, me, me.updateIAS    );
400
            me.timers.updateALT    = maketimer(0.2, me, me.updateALT    );
401
            me.timers.updateHSI    = maketimer(0.2, me, me.updateHSI    );
402
            me.timers.updateTIME   = maketimer(1.0, me, me.updateTIME   );
403
            me.timers.updateOAT    = maketimer(3.0, me, me.updateOAT    );
404
            me.timers.updateTAS    = maketimer(0.5, me, me.updateTAS    );
405
            me.timers.updateBRG    = maketimer(0.5, me, me.updateBRG    );
406
            me.timers.updateXPDR   = maketimer(0,   me, me.updateXPDR   ); me.timers.updateXPDR.singleShot=1;
407
            me.timers.updateBARO   = maketimer(0,   me, me.updateBARO   ); me.timers.updateBARO.singleShot=1;
408
            me.timers.updateOMI    = maketimer(1.0, me, me.updateOMI    );
409
            me.timers.timerTrigger = maketimer(1.0, me, me.timerTrigger );
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
410
            me.timers.updateAOA    = maketimer(0.1, me, me.updateAOA    );    me.timers.updateAOA.singleShot=1;
411
            me.timers.updateCDI    = maketimer(0.3, me, me.updateCDI    );    me.timers.updateCDI.singleShot=1;
412
            me.timers.updateWindData = maketimer(0.5, me, me.updateWindData); me.timers.updateWindData.singleShot=1;
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
413

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
414
            me.screen.show();
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
415
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
416
        }
417
        else {
418
            me.updateEIS();
419
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
420
            me['page selected'] = 0;
421
            me.setMFDPages();
422
            me.device.buttons.MENU = me.device.buttons.MapMenu;
423
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
424

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
425
        me.updateNAV({auto:'nav', tune: radios.getNode('nav-tune').getValue()});
426
        me.updateCOMM({auto:'comm', tune: radios.getNode('comm-tune').getValue()});
427
        me.softkeys_inactivity();
428
        me.updateSoftKeys();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
429
        me.timers.updateNavigationBox = maketimer(me.device.role == 'MFD' ? 0.6 : 0.3, me, me.updateNavigationBox);
430

            
431
        foreach (var timer; keys(me.timers))
432
            me.timers[timer].start();
commit initial
Sébastien MARQUE authored on 2017-03-07
433
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
434
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
435

            
some added comments
Sébastien MARQUE authored on 2017-03-18
436
    colors : {
437
# set of predefined colors {{{
438
        green : [0, 1, 0],
439
        white : [1, 1, 1],
440
        black : [0, 0, 0],
441
        lightblue : [0, 1, 1],
442
        darkblue : [0, 0, 1],
443
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
444
        magenta : [1, 0, 1],
add yellow predefined color
Sébastien MARQUE authored on 2020-05-11
445
        yellow : [1, 1, 0],
some added comments
Sébastien MARQUE authored on 2017-03-18
446
    },
447
#}}}
448

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
449
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
450
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
451
        if (typeof(h) != 'hash') {
452
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
453
                    caller(0)[0],
454
                    typeof(h),
455
                    caller(1)[0]));
456
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
457
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
458
        var setMethod = func (e, t) {
459
            if (t == 'hide')
460
                me.screenElements[e].hide();
461
            elsif (t == 'show')
462
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
463
            elsif (t == 'rot' or t == 'trans') {
464
                if (! contains(me.screenElements[e], t))
465
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
466
            }
467
            elsif (t == 'clip') {
468
                if (contains(me.clips, e))
469
                    me.screenElements[e].set("clip", me.clips[e]);
470
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
471
                    logprint(LOG_WARN, 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
472
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
473
            elsif (t == 'text') {
474
                if (contains(me.texts, e)) {
475
                    if (contains(me.texts[e], 'alignment'))
476
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
477
                    if (contains(me.texts[e], 'default'))
478
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
479
                    if (contains(me.texts[e], 'color'))
480
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
481
                    if (contains(me.texts[e], 'visible'))
482
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
483
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
484
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
485
                    logprint(LOG_DEBUG, 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
486
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
487
            else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
488
                logprint(LOG_WARN, 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
489
        };
490
        foreach (var todo; keys(h)) {
491
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
492
            foreach (var id; h[todo]) {
493
                if (! contains(me.screenElements, id)) {
494
                    me.screenElements[id] = me.screen.getElementById(id);
495
                    if (me.screenElements[id] != nil)
496
                        setMethod(id, todo);
497
                    else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
498
                        logprint(LOG_WARN, 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
499
                }
500
                else
501
                    setMethod(id, todo);
502
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
503
        }
504
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
505
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
506

            
507
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
508
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
509
        PitchScale   : "rect(70,664,370,256)",
510
        SpeedLint1   : "rect(252,226,318,204)",
511
        SpeedTape    : "rect(115,239,455,156)",
512
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
513
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
514
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
515
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
516

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
517
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
518
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
519
        VSIText : {
520
            alignment: "right-bottom", default : num('0'),
521
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
522
        Speed110 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
523
            alignment : 'right-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
524
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
525
        Alt11100 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
526
            alignment:'right-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
527
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
528
        "HDG-text" : {
529
            default: '---°'
530
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
531
        'nav1-standby-freq' : {
532
            color: [0, 1, 1],
533
        },
534
        'nav1-id' : {
535
            default: ''
536
        },
537
        'nav2-id' : {
538
            default: ''
539
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
540
        'CDI-GPS-ANN-text' : {
541
            visible : 0
542
        },
543
        'CDI-GPS-XTK-text' : {
544
            visible : 0
545
        },
546
        'CDI-SRC-text' : {
547
            visible : 0
548
        },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
549
        'BARO-text' : {
550
            alignment : 'left-bottom',
improve route info display
Sébastien MARQUE authored on 2020-05-03
551
        },
552
        'LEG-text' : {
553
            alignment : 'center-center',
554
        },
some added comments
Sébastien MARQUE authored on 2017-03-18
555
#        'TAS-text' : {
556
#            alignment : 'right-bottom',
557
#        },
558
#        'GSPD-text' : {
559
#            alignment : 'right-bottom',
560
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
561
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
562
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
563

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
564
    softkeys_inactivity : func {
565
# automagically back to previous level after some delay {{{
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
566
        me.timers.softkeys_inactivity = maketimer (
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
567
            me.softkeys_inactivity_delay,
568
            func {
569
                pop(me.device.softkeys.path);
570
                me.updateSoftKeys();
571
            }, me);
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
572
        me.timers.softkeys_inactivity.singleShot = 1;
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
573
    },
574
#}}}
575

            
softkey is implemented by de...
Sébastien MARQUE authored on 2017-12-21
576
    setSoftKeyColor : func (n, active, implemented = 1, alert = 0) {
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
577
# set colors for active softkeys {{{
578
        var sftk = sprintf('SoftKey%02i-', n);
579
        if (active) {
580
            var bg = alert ? 1 : 0.5;
581
            me.screenElements[sftk ~ 'bg']
582
                .setColorFill(bg,bg,bg);
583
            me.screenElements[sftk ~ 'text']
584
                .setColor(0,0,0);
585
        }
586
        else {
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
587
            var tc = implemented ? 1 : 0.5;
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
588
            me.screenElements[sftk ~ 'bg']
589
                .setColorFill(0,0,0);
590
            me.screenElements[sftk ~ 'text']
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
591
                .setColor(tc,tc,tc);
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
592
        }
593
    },
594
#}}}
595

            
navigation box content
Sébastien MARQUE authored on 2020-05-12
596
    updateNavigationBox : func {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
597
# update Navigation Box on MFD and PFD header {{{
598
        var route = me.device.map.layers.route;
navigation box content
Sébastien MARQUE authored on 2020-05-12
599
        data.fpSize = size(route.flightPlan);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
600
        if (me.device.role == 'MFD') {
601
            for (var i=1; i<=4; i+=1)
602
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
603
                    .setText(
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
604
                        me.navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].get('text')][0]()
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
605
                    );
606
        }
607
        else { # PFD
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
608
            var enroute = getprop('/autopilot/route-manager/current-wp') > -1;
improve route info display
Sébastien MARQUE authored on 2020-05-03
609
            me.screenElements['ETE'].setVisible(enroute);
610
            me.screenElements['DIS'].setVisible(enroute);
navigation box content
Sébastien MARQUE authored on 2020-05-12
611
            me.screenElements['ETE-text'].setVisible(enroute).setText(me.navbox.ETE[0]());
612
            me.screenElements['DIS-text'].setVisible(enroute).setText(me.navbox.DIS[0]());
613
            me.screenElements['LEG-text'].setVisible(enroute).setText(me.navbox.LEG[0]());
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
614
        }
615
    },
616
#}}}
617

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
618
    updateSoftKeys : func {
619
# update SoftKeys boxes {{{
620
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
621
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
622
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
623
                .setText('ALERTS');
624
            if (size(me.device.softkeys.path) != 0)
625
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
626
                    .setText('BACK')
627
                    .setColor(1,1,1);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
628
        }
629

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
630
        var path = keyMap[me.device.role];
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
631
        var bindings = me.device.softkeys.bindings[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
632
        var pathid = '';
633
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
634
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
635
            pathid ~= p;
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
636
            if (contains(bindings, p))
637
                bindings = bindings[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
638
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
639

            
640
        # feeding with empty menus the first boxes
641
        var start = (contains(path, 'first')) ? path.first : 0;
642
        for (var k = 0; k < start; k+=1) {
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
643
            var sftk = sprintf("SoftKey%02i-", k);
644
            me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
645
                .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
646
            me.screenElements[sftk ~ 'bg']
647
                .setColorFill(0,0,0);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
648
        }
649
        # filling with the content the next boxes
650
        forindex (var k; path.texts) {
651
            var i = k + start;
652
            me.screenElements[sprintf("SoftKey%02i-text", i)]
653
                .setText(path.texts[k]);
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
654
            me.setSoftKeyColor(i,
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
655
                    contains(me.device.softkeys.colored, pathid ~ path.texts[k]),
656
                    contains(bindings, path.texts[k]));
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
657
        }
658
        # feeding the last boxes with empty string
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
659
        var end = (me.device.role == 'PFD') ? 10 : 12;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
660
        if (size(path.texts) + start < end) {
661
            start = size(path.texts) + start;
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
662
            for (var k = start; k < end; k += 1) {
663
                var sftk = sprintf("SoftKey%02i-", k);
664
                me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
665
                    .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
666
                me.screenElements[sftk ~ 'bg']
667
                    .setColorFill(0,0,0);
668
            }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
669
        }
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
670

            
671
        if (size(me.device.softkeys.path))
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
672
            me.timers.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
673
        else
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
674
            me.timers.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
675
    },
676
#}}}
677

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
678
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
679
#{{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
680
        var pitch = data.pitch;
681
        var roll = data.roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
682
        if (pitch > 80)
683
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
684
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
685
            pitch = -80;
686
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
687
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
688
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
689
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
690
        me.screenElements.bankPointer
691
            .setRotation(-roll * D2R);
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
692
        me.screenElements['SlipSkid']
693
            .setTranslation(getprop("/instrumentation/slip-skid-ball/indicated-slip-skid") * 10, 0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
694
        me.screenElements['Traffic']
695
            .setVisible(size(data.tcas));
AI disponible
Sébastien MARQUE authored on 2017-03-10
696
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
697
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
698

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
699
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
700
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
701
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
702
        me.screenElements.VSIText
703
            .setText(num(math.round(vsi, 10)));
704
        if (vsi > 4500)
705
            vsi = 4500;
706
        elsif (vsi < -4500)
707
            vsi = -4500;
708
        me.screenElements.VSI
709
            .setTranslation(0, vsi * -0.03465);
710
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
711
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
712

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
713
    updateIAS: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
714
# animates the IAS lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
715
        var ias = data.ias;
animation IAS
Sébastien MARQUE authored on 2017-03-10
716
        if (ias >= 10)
717
            me.screenElements.Speed110
718
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
719
        else
720
            me.screenElements.Speed110
721
                .setText('');
722
        me.screenElements.SpeedLint1
723
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
724
        me.screenElements.SpeedTape
725
            .setTranslation(0,ias * 5.711);
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
726
        if (ias > data.Vne and ! me._ias_already_exceeded) { # easier than .getColorFill
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
727
            me._ias_already_exceeded = 1;
728
            me.screenElements['IAS-bg']
729
                .setColorFill(1,0,0);
730
        }
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
731
        elsif (ias < data.Vne and me._ias_already_exceeded) { # easier than .getColorFill
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
732
            me._ias_already_exceeded = 0;
733
            me.screenElements['IAS-bg']
734
                .setColorFill(0,0,0);
735
        }
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
736
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
737
            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) < 30)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
738
                me.screenElements['IAS-' ~ v]
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
739
                    .setTranslation(0, (ias - data[v]) * 5.711)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
740
                    .show();
741
            else
742
                me.screenElements['IAS-' ~ v]
743
                    .hide();
744
        }
745

            
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
746
        var Sy = 0;
747
        for (var i = 8; i >= 0; i -= 1)
748
            me._last_ias_Sy[i+1] = me._last_ias_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
749
        var now = systime();
750
        # estimated speed in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
751
        me._last_ias_Sy[0] = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
752
        foreach (var _Sy; me._last_ias_Sy)
753
            Sy += _Sy;
754
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
755
        if (abs(Sy) > 30)
756
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
757
        me.screenElements['Airspeed-Trend-Indicator']
758
            .setScale(1,Sy)
759
            .setTranslation(0, -284.5 * (Sy - 1));
760
        me._last_ias_kt = ias;
761
        me._last_ias_s = now;
animation IAS
Sébastien MARQUE authored on 2017-03-10
762
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
763
    _last_ias_kt : 0,
764
    _last_ias_s : systime(),
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
765
    _last_ias_Sy : [0,0,0,0,0,0,0,0,0,0],
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
766
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
767
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
768

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
769
    updateTAS: func {
770
# updates the True Airspeed and GroundSpeed indicators {{{
771
        me.screenElements['TAS-text']
772
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
773
        me.screenElements['GSPD-text']
774
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
775
    },
776
#}}}
777

            
778
    updateALT: func () {
779
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
780
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
781
        if (alt < 0)
782
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
783
                .setText(sprintf("%3d",math.ceil(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
784
        elsif (alt < 100)
785
            me.screenElements.Alt11100
786
                .setText('');
787
        else
788
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
789
                .setText(sprintf("%3i",math.floor(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
790
        me.screenElements.AltLint00011
791
            .setTranslation(0,math.fmod(alt,100) * 1.24);
792

            
793
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
794
        if (alt> -1000 and alt< 1000000) {
795
            var Offset10 = 0;
796
            var Offset100 = 0;
797
            var Offset1000 = 0;
798
            if (alt< 0) {
799
                var Ne = 1;
800
                var alt= -alt;
801
            }
802
            else
803
                var Ne = 0;
804

            
805
            var Alt10       = math.mod(alt,100);
806
            var Alt100      = int(math.mod(alt/100,10));
807
            var Alt1000     = int(math.mod(alt/1000,10));
808
            var Alt10000    = int(math.mod(alt/10000,10));
809
            var Alt20       = math.mod(Alt10,20)/20;
810
            if (Alt10 >= 80)
811
                var Alt100 += Alt20;
812

            
813
            if (Alt10 >= 80 and Alt100 >= 9)
814
                var Alt1000 += Alt20;
815

            
816
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
817
                var Alt10000 += Alt20;
818

            
819
            if (alt> 100)
820
                var Offset10 = 100;
821

            
822
            if (alt> 1000)
823
                var Offset100 = 10;
824

            
825
            if (alt> 10000)
826
                var Offset1000 = 10;
827

            
828
            if (!Ne) {
829
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
830
                var altCentral = (int(alt/100)*100);
831
            }
832
            elsif (Ne) {
833
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
834
                var altCentral = -(int(alt/100)*100);
835
            }
836
            me.screenElements["AltBigC"].setText("");
837
            me.screenElements["AltSmallC"].setText("");
838
            for (var place = 1; place <= 6; place += 1) {
839
                var altUP = altCentral + (place*100);
840
                var offset = -30.078;
841
                if (altUP < 0) {
842
                    var altUP = -altUP;
843
                    var prefix = "-";
844
                    var offset += 15.039;
845
                }
846
                else
847
                    var prefix = "";
848

            
849
                if (altUP == 0) {
850
                    var AltBigUP    = "";
851
                    var AltSmallUP  = "0";
852

            
853
                }
854
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
855
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
856
                    var AltSmallUP  = "";
857
                }
858
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
859
                    var AltBigUP    = "";
860
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
861
                    var offset = -30.078;
862
                }
863
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
864
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
865
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
866
                    var offset += 15.039;
867
                }
868
                else {
869
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
870
                    var mod = int(math.mod(altUP,1000));
871
                    var AltSmallUP  = sprintf("%1d", mod);
872
                    var offset += 30.078;
873
                }
874

            
875
                me.screenElements["AltBigU"~place].setText(AltBigUP);
876
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
877
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
878
                var altDOWN = altCentral - (place*100);
879
                var offset = -30.078;
880
                if (altDOWN < 0) {
881
                    var altDOWN = -altDOWN;
882
                    var prefix = "-";
883
                    var offset += 15.039;
884
                }
885
                else
886
                    var prefix = "";
887

            
888
                if (altDOWN == 0) {
889
                    var AltBigDOWN  = "";
890
                    var AltSmallDOWN    = "0";
891
                }
892
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
893
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
894
                    var AltSmallDOWN    = "";
895
                }
896
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
897
                    var AltBigDOWN  = "";
898
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
899
                    var offset = -30.078;
900
                }
901
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
902
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
903
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
904
                    var offset += 15.039;
905
                }
906
                else {
907
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
908
                    var mod = int(math.mod(altDOWN,1000));
909
                    var AltSmallDOWN    = sprintf("%1d", mod);
910
                    var offset += 30.078;
911
                }
912
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
913
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
914
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
915
            }
916
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
917
        me.updateSelectedALT();
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
918
        var Sy = 0;
919
        for (var i = 8; i >= 0; i -= 1)
920
            me._last_alt_Sy[i+1] = me._last_alt_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
921
        var now = systime();
922
        # altitude in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
923
        me._last_alt_Sy[0] = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
924
        foreach (var _Sy; me._last_alt_Sy)
925
            Sy += _Sy;
926
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
927
        if (abs(Sy) > 15)
928
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
929
        me.screenElements['Altitude-Trend-Indicator']
930
            .setScale(1,Sy)
931
            .setTranslation(0, -284.5 * (Sy - 1));
932
        me._last_alt_ft = alt;
933
        me._last_alt_s = now;
animation ALT
Sébastien MARQUE authored on 2017-03-11
934
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
935
    _last_alt_ft : 0,
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
936
    _last_alt_Sy : [0,0,0,0,0,0,0,0,0,0],
trends animation
Sébastien MARQUE authored on 2017-03-13
937
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
938
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
939

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
940
    updateBARO : func () {
941
# update BARO widget {{{
942
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
943
        me.screenElements['BARO-text']
944
            .setText(sprintf(fmt,
945
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
946
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
947
                );
948
    },
949
    _baro_unit : 'inhg',
950
#}}}
951

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
952
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
953
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
954
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
955
        me.screenElements.Rose
956
            .setRotation(-hdg * D2R);
957
        me.screenElements['HDG-text']
958
            .setText(sprintf("%03u°", hdg));
959
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
960
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
961

            
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
962
    updateHDG : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
963
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
964
        if (me.device.role == 'MFD')
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
965
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
966
        var hdg = afcs.getValue('heading-bug-deg');
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
967
        me.screenElements['Heading-bug']
968
            .setRotation(hdg * D2R);
969
        me.screenElements['SelectedHDG-bg']
970
            .show();
971
        me.screenElements['SelectedHDG-bgtext']
972
            .show();
973
        me.screenElements['SelectedHDG-text']
974
            .setText(sprintf('%03d°%s', hdg, ''))
975
            .show();
976
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
977
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
978
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
979

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
980
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
981
# TODO: update display for NAV/GPS/BRG courses {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
982
        if (me.device.role == 'MFD')
anime CRS
Sébastien MARQUE authored on 2017-03-13
983
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
984
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
985
        if (source == 'OFF')
986
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
987
        var crs = cdi.getValue('course');
adds CDI
Sébastien MARQUE authored on 2017-03-18
988
        if (crs == nil)
989
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
990
        me.screenElements['SelectedCRS-bg']
991
            .show();
992
        me.screenElements['SelectedCRS-bgtext']
993
            .show();
994
        me.screenElements['SelectedCRS-text']
995
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
996
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
997
            .show();
998
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
999
    },
1000
#}}}
1001

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1002
    updateSelectedALT : func {
1003
# animation for altitude section, called via updatedALT {{{
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
1004
        if (! me.screenElements['SelectedALT'].getVisible())
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
1005
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1006
        var selected_alt = afcs.getValue('selected-alt-ft');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1007
        var delta_alt = data.alt - selected_alt;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1008
        if (abs(delta_alt) > 300)
1009
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
1010
        me.screenElements['SelectedALT-symbol']
1011
            .setVisible(abs(delta_alt) > 100);
1012
        me.screenElements['SelectedALT-bg']
1013
            .setVisible(abs(delta_alt) > 100);
1014
        me.screenElements['SelectedALT-text']
1015
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1016
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
1017
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1018
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
1019
    },
1020
#}}}
1021

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
1022
    updateCDI : func {
1023
# animation for CDI {{{
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1024
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
1025
        if (source == 'OFF') {
1026
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
1027
                foreach (var t; ['pointer', 'CDI'])
1028
                    me.screenElements[s ~ '-' ~ t].hide();
1029
            me.screenElements['CDI-GPS-ANN-text'].hide();
1030
            me.screenElements['CDI-GPS-XTK-text'].hide();
1031
            me.screenElements['CDI-SRC-text'].hide();
1032
            me.screenElements['CDI'].hide();
1033
        }
1034
        else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1035
            var course = cdi.getValue('course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1036
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
1037
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1038
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
1039
                .show();
1040
            me.screenElements['GPS-CTI']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
1041
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
1042
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1043
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
1044
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
1045
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1046
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
1047
                me.screenElements[s ~ '-pointer']
1048
                    .setRotation(rot)
1049
                    .setVisible(source == s);
1050
                me.screenElements[s ~ '-CDI']
1051
                    .setVisible(source == s);
1052
                foreach (var f; ['FROM', 'TO'])
1053
                    me.screenElements[s ~ '-' ~ f]
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1054
                        .setVisible(s == source and cdi.getValue(f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
1055
                me.screenElements['CDI-SRC-text']
1056
                    .setText(source)
1057
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
1058
                    .show();
1059
            }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1060
            var deflection = cdi.getValue('course-deflection');
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1061
            if (left(source, 3) == 'NAV')
1062
                var scale = deflection / 4;
1063
            else { # GPS
1064
                # TODO: deviation depending of the flight phase
1065
                # for now fixed 1 dot = 1 nm course error
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1066
                var abs_deflection_max = 2.4;
1067
                if (me.screenElements['LATMOD-Armed-text'].getText() == 'GPS')
1068
                    abs_deflection_max = 0.5;
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1069
                var abs_deflection = abs(deflection);
1070
                me.screenElements['CDI-GPS-XTK-text']
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1071
                    .setText(sprintf(abs_deflection < 1 ? 'XTK %.1NM' : 'XTK %iNM', abs_deflection))
1072
                    .setVisible(abs_deflection > abs_deflection_max);
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1073
                var scale = deflection / 2;
1074
            }
1075
            scale = (abs(scale) > 1.2) ? 1.2 : scale;
1076
            me.screenElements[source ~ '-CDI']
1077
                .setTranslation(65 * scale, 0);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1078
            me.timers.updateCDI.start();
adds CDI
Sébastien MARQUE authored on 2017-03-18
1079
        }
1080
    },
1081
#}}}
1082

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1083
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1084
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1085
        # arg[0]._r = <comm|nav>
1086
        if (contains(arg[0], "active")) {
1087
            if (arg[0]['active'] == 'none') {
1088
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1089
                    .setColor(1,1,1);
1090
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1091
                    .setColor(1,1,1);
1092
            }
1093
            else {
1094
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1095
                    .setColor(0,1,0);
1096
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1097
                    .setColor(1,1,1);
1098
            }
1099
        }
1100
        if (contains(arg[0], 'tune')) {
1101
            # n = 0 -> NAV1/COMM1
1102
            # n = 1 -> NAV1/COMM2
1103
            me.screenElements[arg[0]._r ~ '-freq-switch']
1104
                .setTranslation(0, arg[0].tune * 25);
1105
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1106
                .setColor(0,1,1);
1107
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1108
                .setColor(1,1,1);
1109
        }
1110
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1111
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1112
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1113
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1114
                .setText(sprintf(fmt, getprop('/instrumentation/'
1115
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1116
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1117
                .setText(sprintf(fmt, getprop('/instrumentation/'
1118
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1119
        }
1120
        if (contains(arg[0], 'set')) {
1121
            # positionne la valeur modifiée, les listeners "trigguent" en permanence ces propriétés, donc exit
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1122
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1123
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1124
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1125
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1126
        }
1127
        if (contains(arg[0], 'auto')) {
1128
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1129
            var radio = arg[0].auto;
1130
            me._updateRadio({refresh: 1, _r: radio});
1131
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1132
            settimer(func me._updateRadio({auto: radio}), 2);
1133
        }
1134
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1135
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1136

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1137
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1138
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1139
        # made active via menu
1140
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1141
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1142
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1143
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1144
                me.screenElements['nav1-id']
1145
                    .setColor(1,1,1);
1146
                me.screenElements['nav2-id']
1147
                    .setColor(1,1,1);
1148
                me.screenElements['NAV1-pointer']
1149
                    .hide();
1150
                me.screenElements['NAV2-pointer']
1151
                    .hide();
1152
            }
1153
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1154
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1155
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1156
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1157
                    .setColor(0,1,0);
1158
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1159
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1160
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1161
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1162
#                me.screenElements['HDI']
1163
#                    .setRotation();
1164
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1165
#                    .hide();
1166
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1167
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1168
#                        .hide();
1169
            }
1170
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1171
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1172
            # TODO: récupérer la valeur via les paramètres transmis du listener
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1173
            if (arg[0].val == nil)
1174
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1175
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1176
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1177
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1178
        else {
1179
            arg[0]._r = 'nav';
1180
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1181
        }
1182
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1183
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1184

            
1185
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1186
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1187
        arg[0]._r = 'comm';
1188
        me._updateRadio(arg[0]);
1189
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1190
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1191

            
1192
    updateTIME : func {
1193
# updates the displayed time botoom left {{{
1194
        me.screenElements['TIME-text']
1195
            .setText(getprop('/sim/time/gmt-string'));
1196
    },
1197
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1198

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1199
    updateXPDR : func {
1200
# updates transponder display {{{
1201
        for (var d = 0; d < 4; d+=1)
1202
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1203
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1204
        var tuning = radios.getValue('xpdr-tuning-digit');
1205
        var fms = radios.getValue('xpdr-tuning-fms-method');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1206
        for (var d = 0; d < 4; d+=1)
1207
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1208
                .setColor(1,1,1);
1209
        if (tuning != nil) {
1210
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1211
                .setColor(0,1,1);
1212
            if (fms)
1213
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1214
                    .setColor(0,1,1);
1215
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1216
        else {
1217
            if (getprop('/instrumentation/transponder/ident'))
1218
                var mode = 'IDENT';
1219
            else
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1220
                var mode = radios.getValue('xpdr-mode');
adds transponder
Sébastien MARQUE authored on 2017-03-17
1221
            var wow = getprop('/gear/gear/wow');
1222
            if (! wow and mode != 'STBY')
1223
                var color = [0, 1, 0];
1224
            else
1225
                var color = [1, 1, 1];
1226
            for (var d = 0; d < 4; d+=1)
1227
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1228
                    .setColor(color);
1229
            me.screenElements['XPDR-MODE-text']
1230
                .setColor(color)
1231
                .setText(mode);
1232
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1233
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1234
#}}}
1235

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1236
    updateOAT : func {
1237
# update OAT display on normal and reversionnary modes (every 3s) {{{
1238
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1239
        me.screenElements['OAT-text']
1240
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1241
    },
1242
    _oat_unit : 'c',
1243
#}}}
1244

            
1245
    updateWindData : func {
1246
# update the window text and arrows for OPTN1/2 {{{
1247
        if (me._winddata_optn == 0)
1248
            return;
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1249
        if (data.ias < 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1250
            me.screenElements['WindData-NODATA']
1251
                .hide();
1252
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1253
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1254
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1255
            if (me._winddata_optn == 1) {
1256
                me.screenElements['WindData-OPTN1-HDG']
1257
                    .setRotation((alpha + 180) * D2R)
1258
                    .show();
1259
                me.screenElements['WindData-OPTN1-HDG-text']
1260
                    .setText(sprintf("%03i°", wind_hdg))
1261
                    .show();
1262
                me.screenElements['WindData-OPTN1-SPD-text']
1263
                    .setText(int(wind_spd) ~ 'KT')
1264
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1265
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1266
            else { # me._winddata_optn == 2
1267
                alpha *= D2R;
1268
                var Vt = wind_spd * math.sin(alpha);
1269
                var Ve = wind_spd * math.cos(alpha);
1270
                if (Vt != 0) {
1271
                    me.screenElements['WindData-OPTN2-crosswind-text']
1272
                        .setText(sprintf('%i', abs(Vt)))
1273
                        .show();
1274
                    me.screenElements['WindData-OPTN2-crosswind']
1275
                        .setScale(-abs(Vt)/Vt, 1)
1276
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1277
                        .show();
1278
                }
1279
                if (Ve != 0) {
1280
                    me.screenElements['WindData-OPTN2-headwind-text']
1281
                        .setText(sprintf('%i', abs(Ve)))
1282
                        .show();
1283
                    me.screenElements['WindData-OPTN2-headwind']
1284
                        .setScale(1, abs(Ve)/Ve)
1285
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1286
                        .show();
1287
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1288
            }
1289
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1290
        else {
1291
            foreach (var e; [
1292
                    'WindData-OPTN1-HDG',
1293
                    'WindData-OPTN1-HDG-text',
1294
                    'WindData-OPTN1-SPD-text',
1295
                    'WindData-OPTN2-crosswind-text',
1296
                    'WindData-OPTN2-crosswind',
1297
                    'WindData-OPTN2-headwind-text',
1298
                    'WindData-OPTN2-headwind'
1299
            ])
1300
                me.screenElements[e].hide();
1301
            me.screenElements['WindData-NODATA'].show();
1302
        }
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1303
        me.timers.updateWindData.start();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1304
    },
1305
    _winddata_optn : 0,
1306
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1307

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1308
    updateAOA : func {
1309
# update Angle Of Attack {{{
1310
        if (me.device.data.aoa == 0)
1311
            return;
1312
        var color = [1,1,1];
1313
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1314
        me.screenElements['AOA-text']
1315
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1316
        if (norm > 1) norm = 1;
1317
        if (norm > 0.9)
1318
            color = [1,0,0];
1319
        elsif (norm > 0.7)
1320
            color = [1,1,0];
1321
        elsif (norm < 0) {
1322
            norm = 0;
1323
            color = [1,0,0];
1324
        }
1325
        me.screenElements['AOA-needle']
1326
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1327
            .setColorFill(color);
1328
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1329
            .setColor(color);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1330
        me.timers.updateAOA.start();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1331
    },
1332
# }}}
1333

            
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1334
    updateBRG : func {
some added comments
Sébastien MARQUE authored on 2017-03-18
1335
# displays and update BRG1/2 {{{
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1336
        foreach (var brg; [1, 2]) {
1337
            var source = 'brg' ~ brg ~ '-source';
1338

            
1339
            var dev = radios.getNode(source).getValue();
1340
            var el  = 'BRG' ~ brg;
1341
            if (dev != 'OFF') {
1342
                var info = {
1343
                    pointer : nil,
1344
                    id : 'NO DATA',
1345
                    hdg : nil,
1346
                    dst : '--.-NM'
1347
                };
1348
                if (left(dev, 3) == 'NAV') {
1349
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1350
                    if (info.pointer) {
1351
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1352
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1353
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1354
                    }
1355
                }
1356
                elsif (dev == 'GPS') {
1357
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1358
                    if (info.pointer) {
1359
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1360
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1361
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1362
                    }
1363
                }
1364
                else { # there are 2 available ADF in FG, but instrument manage only 1
1365
                    info.pointer = getprop('/instrumentation/adf/in-range');
1366
                    if (info.pointer) {
1367
                        info.id  = getprop('/instrumentation/adf/ident');
1368
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1369
                    }
1370
                }
1371

            
1372
                if (info.pointer)
1373
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1374
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1375
                        .show();
1376
                else
1377
                    me.screenElements[el ~ '-pointer']
1378
                        .hide();
1379
                me.screenElements[el ~ '-SRC-text']
1380
                    .setText(dev);
1381
                me.screenElements[el ~ '-DST-text']
1382
                    .setText(info.dst);
1383
                me.screenElements[el ~ '-WPID-text']
1384
                    .setText(info.id);
1385
                me.screenElements['BRG' ~ brg]
1386
                    .show();
1387
            }
1388
            else {
1389
                me.screenElements['BRG' ~ brg]
1390
                    .hide();
1391
            }
1392
        }
1393
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1394
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1395

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1396
    updateOMI : func {
1397
# display marker baecon Outer, Middle, Inner {{{
1398
        var marker = nil;
1399
        foreach (var m; ['outer', 'middle', 'inner'])
1400
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1401
                marker = m;
1402
                me.screenElements['OMI']
1403
                    .show();
1404
                break;
1405
            }
1406
        if (marker != nil) {
1407
            me.screenElements['MarkerText']
1408
                .setText(me._omi_data[marker].t)
1409
                .show();
1410
            me.screenElements['MarkerBG']
1411
                .setColorFill(me._omi_data[marker].bg)
1412
                .show();
1413
        }
1414
        else
1415
            me.screenElements['OMI']
1416
                .hide();
1417
    },
1418
    _omi_data : {
1419
        'outer':  {t: 'O', bg: [0,1,1]},
1420
        'middle': {t: 'M', bg: [1,1,1]},
1421
        'inner':  {t: 'I', bg: [1,1,0]},
1422
    },
1423
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1424
};