zkv1000 / Nasal / display.nas /
Newer Older
1391 lines | 53.942kb
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'],
290
            FOB: [func { return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')); }, 'Fuel on Board'],
291
#            BRG: [func return '---°', 'Bearing'],
292
#            ESA: [func return '-----', 'Enroute Safe Altitude'],
293
#            ISA: [func return '-----', 'ISA Relative Temperature'],
294
#            MSA: [func return '----ft', 'Minimum Safe Altitude'],
295
#            TKE: [func return ' ---°', 'Track Angle Error'],
296
#            VSR: [func return ' ----', 'Vertical Speed Required'],
297
#            XTK: [func return ' ---NM', 'Crosstrack Error'],
298
# }}}
299
        };
300
        if (m.device.role == 'PFD')
301
            foreach (var item; keys(m.navbox))
302
                if (item != 'LEG' and item != 'DIS' and item != 'ETE')
303
                    delete(m.navbox, item);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
304
        return m;
305
    },
306
#}}}
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
307

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
308
    off: func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
309
        me.parents[0]._updateRadio = func; # because of the settimers...
310
        me.parents[0].updateEIS = func;
311
        foreach(var timer; keys(me.timers)) {
312
            me.timers[timer].stop();
313
            delete(me.timers, timer);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
314
        }
poweroff improved
Sébastien MARQUE authored on 2020-05-16
315
        foreach (var e; keys(me.screenElements)) {
316
            if (typeof(me.screenElements[e]) != 'nil')
317
                me.screenElements[e].hide();
318
            delete(me.screenElements, e);
319
        }
320
        foreach (var e; keys(me.screenElements)) {
321
            if (typeof(me.screenElements[e]) != 'nil')
322
                me.screenElements[e].hide();
323
            delete(me.screenElements, e);
324
        }
325
        foreach (var e; keys(me.screenElements)) {
326
            if (typeof(me.screenElements[e]) != 'nil')
327
                me.screenElements[e].hide();
328
            delete(me.screenElements, e);
329
        }
330
        me.screen.setVisible(0);
331
        settimer(func {
332
                me.screen.removeAllChildren();
333
                me.screen.del();
334
                me.display.del();
335
        }, 0.1);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
336
    },
337

            
338
# temporary Widget Display for HDG and CRS modification {{{
339

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

            
342
    timerTrigger : func {
343
        var now = systime();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
344
        foreach (var id; keys(me.temporaryWidgetDisplay)) {
345
            if (me.temporaryWidgetDisplay[id] < now) {
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
346
                me.screenElements[id].hide();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
347
                delete(me.temporaryWidgetDisplay, id);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
348
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
349
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
350
    },
351

            
352
    addTimer : func (duration, element) {
353
        if (typeof(element) == 'scalar')
354
            element = [ element ];
355
        var end = systime() + duration;
356
        foreach (var e; element)
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
357
            me.temporaryWidgetDisplay[e] = end;
commit initial
Sébastien MARQUE authored on 2017-03-07
358
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
359
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
360

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
361
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
362
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
363
        if (me.device.role == 'PFD') {
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
364
            me.timers.updateAI     = maketimer(0.1, me, me.updateAI     );
365
            me.timers.updateVSI    = maketimer(0.1, me, me.updateVSI    );
366
            me.timers.updateIAS    = maketimer(0.1, me, me.updateIAS    );
367
            me.timers.updateALT    = maketimer(0.2, me, me.updateALT    );
368
            me.timers.updateHSI    = maketimer(0.2, me, me.updateHSI    );
369
            me.timers.updateTIME   = maketimer(1.0, me, me.updateTIME   );
370
            me.timers.updateOAT    = maketimer(3.0, me, me.updateOAT    );
371
            me.timers.updateTAS    = maketimer(0.5, me, me.updateTAS    );
372
            me.timers.updateBRG    = maketimer(0.5, me, me.updateBRG    );
373
            me.timers.updateXPDR   = maketimer(0,   me, me.updateXPDR   ); me.timers.updateXPDR.singleShot=1;
374
            me.timers.updateBARO   = maketimer(0,   me, me.updateBARO   ); me.timers.updateBARO.singleShot=1;
375
            me.timers.updateOMI    = maketimer(1.0, me, me.updateOMI    );
376
            me.timers.timerTrigger = maketimer(1.0, me, me.timerTrigger );
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
377
            me.timers.updateAOA    = maketimer(0.1, me, me.updateAOA    );    me.timers.updateAOA.singleShot=1;
378
            me.timers.updateCDI    = maketimer(0.3, me, me.updateCDI    );    me.timers.updateCDI.singleShot=1;
379
            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
380

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
381
            me.screen.show();
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
382
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
383
        }
384
        else {
385
            me.updateEIS();
386
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
387
            me['page selected'] = 0;
388
            me.setMFDPages();
389
            me.device.buttons.MENU = me.device.buttons.MapMenu;
390
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
391

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

            
398
        foreach (var timer; keys(me.timers))
399
            me.timers[timer].start();
commit initial
Sébastien MARQUE authored on 2017-03-07
400
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
401
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
402

            
some added comments
Sébastien MARQUE authored on 2017-03-18
403
    colors : {
404
# set of predefined colors {{{
405
        green : [0, 1, 0],
406
        white : [1, 1, 1],
407
        black : [0, 0, 0],
408
        lightblue : [0, 1, 1],
409
        darkblue : [0, 0, 1],
410
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
411
        magenta : [1, 0, 1],
add yellow predefined color
Sébastien MARQUE authored on 2020-05-11
412
        yellow : [1, 1, 0],
some added comments
Sébastien MARQUE authored on 2017-03-18
413
    },
414
#}}}
415

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
416
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
417
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
418
        if (typeof(h) != 'hash') {
419
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
420
                    caller(0)[0],
421
                    typeof(h),
422
                    caller(1)[0]));
423
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
424
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
425
        var setMethod = func (e, t) {
426
            if (t == 'hide')
427
                me.screenElements[e].hide();
428
            elsif (t == 'show')
429
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
430
            elsif (t == 'rot' or t == 'trans') {
431
                if (! contains(me.screenElements[e], t))
432
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
433
            }
434
            elsif (t == 'clip') {
435
                if (contains(me.clips, e))
436
                    me.screenElements[e].set("clip", me.clips[e]);
437
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
438
                    logprint(LOG_WARN, 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
439
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
440
            elsif (t == 'text') {
441
                if (contains(me.texts, e)) {
442
                    if (contains(me.texts[e], 'alignment'))
443
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
444
                    if (contains(me.texts[e], 'default'))
445
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
446
                    if (contains(me.texts[e], 'color'))
447
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
448
                    if (contains(me.texts[e], 'visible'))
449
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
450
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
451
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
452
                    logprint(LOG_DEBUG, 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
453
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
454
            else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
455
                logprint(LOG_WARN, 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
456
        };
457
        foreach (var todo; keys(h)) {
458
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
459
            foreach (var id; h[todo]) {
460
                if (! contains(me.screenElements, id)) {
461
                    me.screenElements[id] = me.screen.getElementById(id);
462
                    if (me.screenElements[id] != nil)
463
                        setMethod(id, todo);
464
                    else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
465
                        logprint(LOG_WARN, 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
466
                }
467
                else
468
                    setMethod(id, todo);
469
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
470
        }
471
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
472
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
473

            
474
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
475
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
476
        PitchScale   : "rect(70,664,370,256)",
477
        SpeedLint1   : "rect(252,226,318,204)",
478
        SpeedTape    : "rect(115,239,455,156)",
479
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
480
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
481
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
482
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
483

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
484
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
485
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
486
        VSIText : {
487
            alignment: "right-bottom", default : num('0'),
488
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
489
        Speed110 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
490
            alignment : 'right-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
491
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
492
        Alt11100 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
493
            alignment:'right-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
494
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
495
        "HDG-text" : {
496
            default: '---°'
497
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
498
        'nav1-standby-freq' : {
499
            color: [0, 1, 1],
500
        },
501
        'nav1-id' : {
502
            default: ''
503
        },
504
        'nav2-id' : {
505
            default: ''
506
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
507
        'CDI-GPS-ANN-text' : {
508
            visible : 0
509
        },
510
        'CDI-GPS-XTK-text' : {
511
            visible : 0
512
        },
513
        'CDI-SRC-text' : {
514
            visible : 0
515
        },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
516
        'BARO-text' : {
517
            alignment : 'left-bottom',
improve route info display
Sébastien MARQUE authored on 2020-05-03
518
        },
519
        'LEG-text' : {
520
            alignment : 'center-center',
521
        },
some added comments
Sébastien MARQUE authored on 2017-03-18
522
#        'TAS-text' : {
523
#            alignment : 'right-bottom',
524
#        },
525
#        'GSPD-text' : {
526
#            alignment : 'right-bottom',
527
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
528
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
529
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
530

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
531
    softkeys_inactivity : func {
532
# automagically back to previous level after some delay {{{
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
533
        me.timers.softkeys_inactivity = maketimer (
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
534
            me.softkeys_inactivity_delay,
535
            func {
536
                pop(me.device.softkeys.path);
537
                me.updateSoftKeys();
538
            }, me);
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
539
        me.timers.softkeys_inactivity.singleShot = 1;
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
540
    },
541
#}}}
542

            
softkey is implemented by de...
Sébastien MARQUE authored on 2017-12-21
543
    setSoftKeyColor : func (n, active, implemented = 1, alert = 0) {
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
544
# set colors for active softkeys {{{
545
        var sftk = sprintf('SoftKey%02i-', n);
546
        if (active) {
547
            var bg = alert ? 1 : 0.5;
548
            me.screenElements[sftk ~ 'bg']
549
                .setColorFill(bg,bg,bg);
550
            me.screenElements[sftk ~ 'text']
551
                .setColor(0,0,0);
552
        }
553
        else {
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
554
            var tc = implemented ? 1 : 0.5;
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
555
            me.screenElements[sftk ~ 'bg']
556
                .setColorFill(0,0,0);
557
            me.screenElements[sftk ~ 'text']
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
558
                .setColor(tc,tc,tc);
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
559
        }
560
    },
561
#}}}
562

            
navigation box content
Sébastien MARQUE authored on 2020-05-12
563
    updateNavigationBox : func {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
564
# update Navigation Box on MFD and PFD header {{{
565
        var route = me.device.map.layers.route;
navigation box content
Sébastien MARQUE authored on 2020-05-12
566
        data.fpSize = size(route.flightPlan);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
567
        if (me.device.role == 'MFD') {
568
            for (var i=1; i<=4; i+=1)
569
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
570
                    .setText(
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
571
                        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
572
                    );
573
        }
574
        else { # PFD
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
575
            var enroute = getprop('/autopilot/route-manager/current-wp') > -1;
improve route info display
Sébastien MARQUE authored on 2020-05-03
576
            me.screenElements['ETE'].setVisible(enroute);
577
            me.screenElements['DIS'].setVisible(enroute);
navigation box content
Sébastien MARQUE authored on 2020-05-12
578
            me.screenElements['ETE-text'].setVisible(enroute).setText(me.navbox.ETE[0]());
579
            me.screenElements['DIS-text'].setVisible(enroute).setText(me.navbox.DIS[0]());
580
            me.screenElements['LEG-text'].setVisible(enroute).setText(me.navbox.LEG[0]());
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
581
        }
582
    },
583
#}}}
584

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
585
    updateSoftKeys : func {
586
# update SoftKeys boxes {{{
587
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
588
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
589
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
590
                .setText('ALERTS');
591
            if (size(me.device.softkeys.path) != 0)
592
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
593
                    .setText('BACK')
594
                    .setColor(1,1,1);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
595
        }
596

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
597
        var path = keyMap[me.device.role];
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
598
        var bindings = me.device.softkeys.bindings[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
599
        var pathid = '';
600
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
601
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
602
            pathid ~= p;
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
603
            if (contains(bindings, p))
604
                bindings = bindings[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
605
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
606

            
607
        # feeding with empty menus the first boxes
608
        var start = (contains(path, 'first')) ? path.first : 0;
609
        for (var k = 0; k < start; k+=1) {
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
610
            var sftk = sprintf("SoftKey%02i-", k);
611
            me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
612
                .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
613
            me.screenElements[sftk ~ 'bg']
614
                .setColorFill(0,0,0);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
615
        }
616
        # filling with the content the next boxes
617
        forindex (var k; path.texts) {
618
            var i = k + start;
619
            me.screenElements[sprintf("SoftKey%02i-text", i)]
620
                .setText(path.texts[k]);
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
621
            me.setSoftKeyColor(i,
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
622
                    contains(me.device.softkeys.colored, pathid ~ path.texts[k]),
623
                    contains(bindings, path.texts[k]));
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
624
        }
625
        # feeding the last boxes with empty string
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
626
        var end = (me.device.role == 'PFD') ? 10 : 12;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
627
        if (size(path.texts) + start < end) {
628
            start = size(path.texts) + start;
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
629
            for (var k = start; k < end; k += 1) {
630
                var sftk = sprintf("SoftKey%02i-", k);
631
                me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
632
                    .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
633
                me.screenElements[sftk ~ 'bg']
634
                    .setColorFill(0,0,0);
635
            }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
636
        }
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
637

            
638
        if (size(me.device.softkeys.path))
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
639
            me.timers.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
640
        else
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
641
            me.timers.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
642
    },
643
#}}}
644

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
645
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
646
#{{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
647
        var pitch = data.pitch;
648
        var roll = data.roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
649
        if (pitch > 80)
650
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
651
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
652
            pitch = -80;
653
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
654
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
655
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
656
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
657
        me.screenElements.bankPointer
658
            .setRotation(-roll * D2R);
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
659
        me.screenElements['SlipSkid']
660
            .setTranslation(getprop("/instrumentation/slip-skid-ball/indicated-slip-skid") * 10, 0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
661
        me.screenElements['Traffic']
662
            .setVisible(size(data.tcas));
AI disponible
Sébastien MARQUE authored on 2017-03-10
663
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
664
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
665

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
666
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
667
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
668
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
669
        me.screenElements.VSIText
670
            .setText(num(math.round(vsi, 10)));
671
        if (vsi > 4500)
672
            vsi = 4500;
673
        elsif (vsi < -4500)
674
            vsi = -4500;
675
        me.screenElements.VSI
676
            .setTranslation(0, vsi * -0.03465);
677
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
678
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
679

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
680
    updateIAS: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
681
# animates the IAS lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
682
        var ias = data.ias;
animation IAS
Sébastien MARQUE authored on 2017-03-10
683
        if (ias >= 10)
684
            me.screenElements.Speed110
685
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
686
        else
687
            me.screenElements.Speed110
688
                .setText('');
689
        me.screenElements.SpeedLint1
690
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
691
        me.screenElements.SpeedTape
692
            .setTranslation(0,ias * 5.711);
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
693
        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
694
            me._ias_already_exceeded = 1;
695
            me.screenElements['IAS-bg']
696
                .setColorFill(1,0,0);
697
        }
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
698
        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
699
            me._ias_already_exceeded = 0;
700
            me.screenElements['IAS-bg']
701
                .setColorFill(0,0,0);
702
        }
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
703
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
704
            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) < 30)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
705
                me.screenElements['IAS-' ~ v]
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
706
                    .setTranslation(0, (ias - data[v]) * 5.711)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
707
                    .show();
708
            else
709
                me.screenElements['IAS-' ~ v]
710
                    .hide();
711
        }
712

            
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
713
        var Sy = 0;
714
        for (var i = 8; i >= 0; i -= 1)
715
            me._last_ias_Sy[i+1] = me._last_ias_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
716
        var now = systime();
717
        # estimated speed in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
718
        me._last_ias_Sy[0] = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
719
        foreach (var _Sy; me._last_ias_Sy)
720
            Sy += _Sy;
721
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
722
        if (abs(Sy) > 30)
723
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
724
        me.screenElements['Airspeed-Trend-Indicator']
725
            .setScale(1,Sy)
726
            .setTranslation(0, -284.5 * (Sy - 1));
727
        me._last_ias_kt = ias;
728
        me._last_ias_s = now;
animation IAS
Sébastien MARQUE authored on 2017-03-10
729
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
730
    _last_ias_kt : 0,
731
    _last_ias_s : systime(),
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
732
    _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
733
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
734
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
735

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
736
    updateTAS: func {
737
# updates the True Airspeed and GroundSpeed indicators {{{
738
        me.screenElements['TAS-text']
739
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
740
        me.screenElements['GSPD-text']
741
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
742
    },
743
#}}}
744

            
745
    updateALT: func () {
746
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
747
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
748
        if (alt < 0)
749
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
750
                .setText(sprintf("%3d",math.ceil(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
751
        elsif (alt < 100)
752
            me.screenElements.Alt11100
753
                .setText('');
754
        else
755
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
756
                .setText(sprintf("%3i",math.floor(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
757
        me.screenElements.AltLint00011
758
            .setTranslation(0,math.fmod(alt,100) * 1.24);
759

            
760
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
761
        if (alt> -1000 and alt< 1000000) {
762
            var Offset10 = 0;
763
            var Offset100 = 0;
764
            var Offset1000 = 0;
765
            if (alt< 0) {
766
                var Ne = 1;
767
                var alt= -alt;
768
            }
769
            else
770
                var Ne = 0;
771

            
772
            var Alt10       = math.mod(alt,100);
773
            var Alt100      = int(math.mod(alt/100,10));
774
            var Alt1000     = int(math.mod(alt/1000,10));
775
            var Alt10000    = int(math.mod(alt/10000,10));
776
            var Alt20       = math.mod(Alt10,20)/20;
777
            if (Alt10 >= 80)
778
                var Alt100 += Alt20;
779

            
780
            if (Alt10 >= 80 and Alt100 >= 9)
781
                var Alt1000 += Alt20;
782

            
783
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
784
                var Alt10000 += Alt20;
785

            
786
            if (alt> 100)
787
                var Offset10 = 100;
788

            
789
            if (alt> 1000)
790
                var Offset100 = 10;
791

            
792
            if (alt> 10000)
793
                var Offset1000 = 10;
794

            
795
            if (!Ne) {
796
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
797
                var altCentral = (int(alt/100)*100);
798
            }
799
            elsif (Ne) {
800
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
801
                var altCentral = -(int(alt/100)*100);
802
            }
803
            me.screenElements["AltBigC"].setText("");
804
            me.screenElements["AltSmallC"].setText("");
805
            for (var place = 1; place <= 6; place += 1) {
806
                var altUP = altCentral + (place*100);
807
                var offset = -30.078;
808
                if (altUP < 0) {
809
                    var altUP = -altUP;
810
                    var prefix = "-";
811
                    var offset += 15.039;
812
                }
813
                else
814
                    var prefix = "";
815

            
816
                if (altUP == 0) {
817
                    var AltBigUP    = "";
818
                    var AltSmallUP  = "0";
819

            
820
                }
821
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
822
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
823
                    var AltSmallUP  = "";
824
                }
825
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
826
                    var AltBigUP    = "";
827
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
828
                    var offset = -30.078;
829
                }
830
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
831
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
832
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
833
                    var offset += 15.039;
834
                }
835
                else {
836
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
837
                    var mod = int(math.mod(altUP,1000));
838
                    var AltSmallUP  = sprintf("%1d", mod);
839
                    var offset += 30.078;
840
                }
841

            
842
                me.screenElements["AltBigU"~place].setText(AltBigUP);
843
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
844
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
845
                var altDOWN = altCentral - (place*100);
846
                var offset = -30.078;
847
                if (altDOWN < 0) {
848
                    var altDOWN = -altDOWN;
849
                    var prefix = "-";
850
                    var offset += 15.039;
851
                }
852
                else
853
                    var prefix = "";
854

            
855
                if (altDOWN == 0) {
856
                    var AltBigDOWN  = "";
857
                    var AltSmallDOWN    = "0";
858
                }
859
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
860
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
861
                    var AltSmallDOWN    = "";
862
                }
863
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
864
                    var AltBigDOWN  = "";
865
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
866
                    var offset = -30.078;
867
                }
868
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
869
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
870
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
871
                    var offset += 15.039;
872
                }
873
                else {
874
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
875
                    var mod = int(math.mod(altDOWN,1000));
876
                    var AltSmallDOWN    = sprintf("%1d", mod);
877
                    var offset += 30.078;
878
                }
879
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
880
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
881
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
882
            }
883
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
884
        me.updateSelectedALT();
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
885
        var Sy = 0;
886
        for (var i = 8; i >= 0; i -= 1)
887
            me._last_alt_Sy[i+1] = me._last_alt_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
888
        var now = systime();
889
        # altitude in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
890
        me._last_alt_Sy[0] = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
891
        foreach (var _Sy; me._last_alt_Sy)
892
            Sy += _Sy;
893
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
894
        if (abs(Sy) > 15)
895
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
896
        me.screenElements['Altitude-Trend-Indicator']
897
            .setScale(1,Sy)
898
            .setTranslation(0, -284.5 * (Sy - 1));
899
        me._last_alt_ft = alt;
900
        me._last_alt_s = now;
animation ALT
Sébastien MARQUE authored on 2017-03-11
901
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
902
    _last_alt_ft : 0,
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
903
    _last_alt_Sy : [0,0,0,0,0,0,0,0,0,0],
trends animation
Sébastien MARQUE authored on 2017-03-13
904
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
905
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
906

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
907
    updateBARO : func () {
908
# update BARO widget {{{
909
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
910
        me.screenElements['BARO-text']
911
            .setText(sprintf(fmt,
912
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
913
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
914
                );
915
    },
916
    _baro_unit : 'inhg',
917
#}}}
918

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
919
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
920
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
921
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
922
        me.screenElements.Rose
923
            .setRotation(-hdg * D2R);
924
        me.screenElements['HDG-text']
925
            .setText(sprintf("%03u°", hdg));
926
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
927
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
928

            
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
929
    updateHDG : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
930
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
931
        if (me.device.role == 'MFD')
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
932
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
933
        var hdg = afcs.getValue('heading-bug-deg');
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
934
        me.screenElements['Heading-bug']
935
            .setRotation(hdg * D2R);
936
        me.screenElements['SelectedHDG-bg']
937
            .show();
938
        me.screenElements['SelectedHDG-bgtext']
939
            .show();
940
        me.screenElements['SelectedHDG-text']
941
            .setText(sprintf('%03d°%s', hdg, ''))
942
            .show();
943
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
944
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
945
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
946

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
947
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
948
# TODO: update display for NAV/GPS/BRG courses {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
949
        if (me.device.role == 'MFD')
anime CRS
Sébastien MARQUE authored on 2017-03-13
950
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
951
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
952
        if (source == 'OFF')
953
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
954
        var crs = cdi.getValue('course');
adds CDI
Sébastien MARQUE authored on 2017-03-18
955
        if (crs == nil)
956
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
957
        me.screenElements['SelectedCRS-bg']
958
            .show();
959
        me.screenElements['SelectedCRS-bgtext']
960
            .show();
961
        me.screenElements['SelectedCRS-text']
962
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
963
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
964
            .show();
965
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
966
    },
967
#}}}
968

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
969
    updateSelectedALT : func {
970
# animation for altitude section, called via updatedALT {{{
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
971
        if (! me.screenElements['SelectedALT'].getVisible())
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
972
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
973
        var selected_alt = afcs.getValue('selected-alt-ft');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
974
        var delta_alt = data.alt - selected_alt;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
975
        if (abs(delta_alt) > 300)
976
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
977
        me.screenElements['SelectedALT-symbol']
978
            .setVisible(abs(delta_alt) > 100);
979
        me.screenElements['SelectedALT-bg']
980
            .setVisible(abs(delta_alt) > 100);
981
        me.screenElements['SelectedALT-text']
982
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
983
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
984
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
985
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
986
    },
987
#}}}
988

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
989
    updateCDI : func {
990
# animation for CDI {{{
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
991
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
992
        if (source == 'OFF') {
993
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
994
                foreach (var t; ['pointer', 'CDI'])
995
                    me.screenElements[s ~ '-' ~ t].hide();
996
            me.screenElements['CDI-GPS-ANN-text'].hide();
997
            me.screenElements['CDI-GPS-XTK-text'].hide();
998
            me.screenElements['CDI-SRC-text'].hide();
999
            me.screenElements['CDI'].hide();
1000
        }
1001
        else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1002
            var course = cdi.getValue('course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1003
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
1004
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1005
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
1006
                .show();
1007
            me.screenElements['GPS-CTI']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
1008
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
1009
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1010
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
1011
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
1012
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1013
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
1014
                me.screenElements[s ~ '-pointer']
1015
                    .setRotation(rot)
1016
                    .setVisible(source == s);
1017
                me.screenElements[s ~ '-CDI']
1018
                    .setVisible(source == s);
1019
                foreach (var f; ['FROM', 'TO'])
1020
                    me.screenElements[s ~ '-' ~ f]
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1021
                        .setVisible(s == source and cdi.getValue(f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
1022
                me.screenElements['CDI-SRC-text']
1023
                    .setText(source)
1024
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
1025
                    .show();
1026
            }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1027
            var deflection = cdi.getValue('course-deflection');
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1028
            if (left(source, 3) == 'NAV')
1029
                var scale = deflection / 4;
1030
            else { # GPS
1031
                # TODO: deviation depending of the flight phase
1032
                # for now fixed 1 dot = 1 nm course error
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1033
                var abs_deflection_max = 2.4;
1034
                if (me.screenElements['LATMOD-Armed-text'].getText() == 'GPS')
1035
                    abs_deflection_max = 0.5;
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1036
                var abs_deflection = abs(deflection);
1037
                me.screenElements['CDI-GPS-XTK-text']
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1038
                    .setText(sprintf(abs_deflection < 1 ? 'XTK %.1NM' : 'XTK %iNM', abs_deflection))
1039
                    .setVisible(abs_deflection > abs_deflection_max);
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1040
                var scale = deflection / 2;
1041
            }
1042
            scale = (abs(scale) > 1.2) ? 1.2 : scale;
1043
            me.screenElements[source ~ '-CDI']
1044
                .setTranslation(65 * scale, 0);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1045
            me.timers.updateCDI.start();
adds CDI
Sébastien MARQUE authored on 2017-03-18
1046
        }
1047
    },
1048
#}}}
1049

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1050
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1051
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1052
        # arg[0]._r = <comm|nav>
1053
        if (contains(arg[0], "active")) {
1054
            if (arg[0]['active'] == 'none') {
1055
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1056
                    .setColor(1,1,1);
1057
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1058
                    .setColor(1,1,1);
1059
            }
1060
            else {
1061
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1062
                    .setColor(0,1,0);
1063
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1064
                    .setColor(1,1,1);
1065
            }
1066
        }
1067
        if (contains(arg[0], 'tune')) {
1068
            # n = 0 -> NAV1/COMM1
1069
            # n = 1 -> NAV1/COMM2
1070
            me.screenElements[arg[0]._r ~ '-freq-switch']
1071
                .setTranslation(0, arg[0].tune * 25);
1072
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1073
                .setColor(0,1,1);
1074
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1075
                .setColor(1,1,1);
1076
        }
1077
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1078
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1079
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1080
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1081
                .setText(sprintf(fmt, getprop('/instrumentation/'
1082
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1083
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1084
                .setText(sprintf(fmt, getprop('/instrumentation/'
1085
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1086
        }
1087
        if (contains(arg[0], 'set')) {
1088
            # 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
1089
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1090
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1091
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1092
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1093
        }
1094
        if (contains(arg[0], 'auto')) {
1095
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1096
            var radio = arg[0].auto;
1097
            me._updateRadio({refresh: 1, _r: radio});
1098
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1099
            settimer(func me._updateRadio({auto: radio}), 2);
1100
        }
1101
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1102
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1103

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1104
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1105
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1106
        # made active via menu
1107
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1108
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1109
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1110
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1111
                me.screenElements['nav1-id']
1112
                    .setColor(1,1,1);
1113
                me.screenElements['nav2-id']
1114
                    .setColor(1,1,1);
1115
                me.screenElements['NAV1-pointer']
1116
                    .hide();
1117
                me.screenElements['NAV2-pointer']
1118
                    .hide();
1119
            }
1120
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1121
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1122
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1123
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1124
                    .setColor(0,1,0);
1125
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1126
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1127
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1128
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1129
#                me.screenElements['HDI']
1130
#                    .setRotation();
1131
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1132
#                    .hide();
1133
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1134
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1135
#                        .hide();
1136
            }
1137
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1138
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1139
            # 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
1140
            if (arg[0].val == nil)
1141
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1142
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1143
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1144
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1145
        else {
1146
            arg[0]._r = 'nav';
1147
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1148
        }
1149
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1150
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1151

            
1152
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1153
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1154
        arg[0]._r = 'comm';
1155
        me._updateRadio(arg[0]);
1156
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1157
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1158

            
1159
    updateTIME : func {
1160
# updates the displayed time botoom left {{{
1161
        me.screenElements['TIME-text']
1162
            .setText(getprop('/sim/time/gmt-string'));
1163
    },
1164
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1165

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1166
    updateXPDR : func {
1167
# updates transponder display {{{
1168
        for (var d = 0; d < 4; d+=1)
1169
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1170
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1171
        var tuning = radios.getValue('xpdr-tuning-digit');
1172
        var fms = radios.getValue('xpdr-tuning-fms-method');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1173
        for (var d = 0; d < 4; d+=1)
1174
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1175
                .setColor(1,1,1);
1176
        if (tuning != nil) {
1177
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1178
                .setColor(0,1,1);
1179
            if (fms)
1180
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1181
                    .setColor(0,1,1);
1182
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1183
        else {
1184
            if (getprop('/instrumentation/transponder/ident'))
1185
                var mode = 'IDENT';
1186
            else
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1187
                var mode = radios.getValue('xpdr-mode');
adds transponder
Sébastien MARQUE authored on 2017-03-17
1188
            var wow = getprop('/gear/gear/wow');
1189
            if (! wow and mode != 'STBY')
1190
                var color = [0, 1, 0];
1191
            else
1192
                var color = [1, 1, 1];
1193
            for (var d = 0; d < 4; d+=1)
1194
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1195
                    .setColor(color);
1196
            me.screenElements['XPDR-MODE-text']
1197
                .setColor(color)
1198
                .setText(mode);
1199
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1200
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1201
#}}}
1202

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1203
    updateOAT : func {
1204
# update OAT display on normal and reversionnary modes (every 3s) {{{
1205
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1206
        me.screenElements['OAT-text']
1207
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1208
    },
1209
    _oat_unit : 'c',
1210
#}}}
1211

            
1212
    updateWindData : func {
1213
# update the window text and arrows for OPTN1/2 {{{
1214
        if (me._winddata_optn == 0)
1215
            return;
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1216
        if (data.ias < 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1217
            me.screenElements['WindData-NODATA']
1218
                .hide();
1219
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1220
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1221
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1222
            if (me._winddata_optn == 1) {
1223
                me.screenElements['WindData-OPTN1-HDG']
1224
                    .setRotation((alpha + 180) * D2R)
1225
                    .show();
1226
                me.screenElements['WindData-OPTN1-HDG-text']
1227
                    .setText(sprintf("%03i°", wind_hdg))
1228
                    .show();
1229
                me.screenElements['WindData-OPTN1-SPD-text']
1230
                    .setText(int(wind_spd) ~ 'KT')
1231
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1232
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1233
            else { # me._winddata_optn == 2
1234
                alpha *= D2R;
1235
                var Vt = wind_spd * math.sin(alpha);
1236
                var Ve = wind_spd * math.cos(alpha);
1237
                if (Vt != 0) {
1238
                    me.screenElements['WindData-OPTN2-crosswind-text']
1239
                        .setText(sprintf('%i', abs(Vt)))
1240
                        .show();
1241
                    me.screenElements['WindData-OPTN2-crosswind']
1242
                        .setScale(-abs(Vt)/Vt, 1)
1243
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1244
                        .show();
1245
                }
1246
                if (Ve != 0) {
1247
                    me.screenElements['WindData-OPTN2-headwind-text']
1248
                        .setText(sprintf('%i', abs(Ve)))
1249
                        .show();
1250
                    me.screenElements['WindData-OPTN2-headwind']
1251
                        .setScale(1, abs(Ve)/Ve)
1252
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1253
                        .show();
1254
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1255
            }
1256
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1257
        else {
1258
            foreach (var e; [
1259
                    'WindData-OPTN1-HDG',
1260
                    'WindData-OPTN1-HDG-text',
1261
                    'WindData-OPTN1-SPD-text',
1262
                    'WindData-OPTN2-crosswind-text',
1263
                    'WindData-OPTN2-crosswind',
1264
                    'WindData-OPTN2-headwind-text',
1265
                    'WindData-OPTN2-headwind'
1266
            ])
1267
                me.screenElements[e].hide();
1268
            me.screenElements['WindData-NODATA'].show();
1269
        }
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1270
        me.timers.updateWindData.start();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1271
    },
1272
    _winddata_optn : 0,
1273
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1274

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1275
    updateAOA : func {
1276
# update Angle Of Attack {{{
1277
        if (me.device.data.aoa == 0)
1278
            return;
1279
        var color = [1,1,1];
1280
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1281
        me.screenElements['AOA-text']
1282
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1283
        if (norm > 1) norm = 1;
1284
        if (norm > 0.9)
1285
            color = [1,0,0];
1286
        elsif (norm > 0.7)
1287
            color = [1,1,0];
1288
        elsif (norm < 0) {
1289
            norm = 0;
1290
            color = [1,0,0];
1291
        }
1292
        me.screenElements['AOA-needle']
1293
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1294
            .setColorFill(color);
1295
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1296
            .setColor(color);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1297
        me.timers.updateAOA.start();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1298
    },
1299
# }}}
1300

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

            
1306
            var dev = radios.getNode(source).getValue();
1307
            var el  = 'BRG' ~ brg;
1308
            if (dev != 'OFF') {
1309
                var info = {
1310
                    pointer : nil,
1311
                    id : 'NO DATA',
1312
                    hdg : nil,
1313
                    dst : '--.-NM'
1314
                };
1315
                if (left(dev, 3) == 'NAV') {
1316
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1317
                    if (info.pointer) {
1318
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1319
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1320
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1321
                    }
1322
                }
1323
                elsif (dev == 'GPS') {
1324
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1325
                    if (info.pointer) {
1326
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1327
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1328
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1329
                    }
1330
                }
1331
                else { # there are 2 available ADF in FG, but instrument manage only 1
1332
                    info.pointer = getprop('/instrumentation/adf/in-range');
1333
                    if (info.pointer) {
1334
                        info.id  = getprop('/instrumentation/adf/ident');
1335
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1336
                    }
1337
                }
1338

            
1339
                if (info.pointer)
1340
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1341
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1342
                        .show();
1343
                else
1344
                    me.screenElements[el ~ '-pointer']
1345
                        .hide();
1346
                me.screenElements[el ~ '-SRC-text']
1347
                    .setText(dev);
1348
                me.screenElements[el ~ '-DST-text']
1349
                    .setText(info.dst);
1350
                me.screenElements[el ~ '-WPID-text']
1351
                    .setText(info.id);
1352
                me.screenElements['BRG' ~ brg]
1353
                    .show();
1354
            }
1355
            else {
1356
                me.screenElements['BRG' ~ brg]
1357
                    .hide();
1358
            }
1359
        }
1360
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1361
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1362

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1363
    updateOMI : func {
1364
# display marker baecon Outer, Middle, Inner {{{
1365
        var marker = nil;
1366
        foreach (var m; ['outer', 'middle', 'inner'])
1367
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1368
                marker = m;
1369
                me.screenElements['OMI']
1370
                    .show();
1371
                break;
1372
            }
1373
        if (marker != nil) {
1374
            me.screenElements['MarkerText']
1375
                .setText(me._omi_data[marker].t)
1376
                .show();
1377
            me.screenElements['MarkerBG']
1378
                .setColorFill(me._omi_data[marker].bg)
1379
                .show();
1380
        }
1381
        else
1382
            me.screenElements['OMI']
1383
                .hide();
1384
    },
1385
    _omi_data : {
1386
        'outer':  {t: 'O', bg: [0,1,1]},
1387
        'middle': {t: 'M', bg: [1,1,1]},
1388
        'inner':  {t: 'I', bg: [1,1,0]},
1389
    },
1390
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1391
};