zkv1000 / Nasal / display.nas /
Newer Older
1434 lines | 56.168kb
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 {
fix XTK display
Sébastien MARQUE authored on 2020-05-23
292
                var xtk = nil;
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
293
                var source = cdi.getValue('source');
294
                if (source == 'NAV1')
fix XTK display
Sébastien MARQUE authored on 2020-05-23
295
                    var xtk = abs(getprop('/instrumentation/nav[0]/crosstrack-error-m')) * M2NM;
296
                elsif (source == 'NAV2')
297
                    var xtk = abs(getprop('/instrumentation/nav[1]/crosstrack-error-m')) * M2NM;
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
298
                elsif (source == 'GPS')
fix XTK display
Sébastien MARQUE authored on 2020-05-23
299
                    var xtk = abs(getprop('/instrumentation/gps/wp/wp[1]/course-error-nm'));
300

            
301
                if (xtk == nil)
302
                    return ' ---NM';
303
                elsif (xtk > 99.9)
304
                    return ' ++.+NM';
305
                else
306
                    return sprintf('%2.1fNM', xtk);
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
307
            }, 'Crosstrack Error'],
308
            MSA: [func {
309
                data._msa_spd        = getprop('/velocities/groundspeed-kt');
310
                data._msa_track      = getprop('/orientation/track-deg');
311
                if (! contains(data.timers, 'MSA_geodinfo')) {
312
                    data._msa_alt         = -1;
313
                    data._msa_point       = 1;
314
                    data._msa_alt_intern  = 0;
315
                    data.timers.MSA_geodinfo = maketimer(0, func {
316
                        var geo = greatCircleMove(
317
                                data._msa_track,
318
                                (data._msa_spd / 12) / 10 * data._msa_point);
fix MSA display
Sébastien MARQUE authored on 2020-05-23
319
                        var _geodinfo = geodinfo(geo.lat, geo.lon, 10000);
320
                        if (_geodinfo != nil)
321
                            if (data._msa_alt_intern < _geodinfo[0]) data._msa_alt_intern = _geodinfo[0];
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
322
                        data._msa_point += 1;
323
                        if (data._msa_point > 10) {
324
                            data._msa_alt         = math.round((1000 + data._msa_alt_intern * M2FT) / 100) * 100;
325
                            data._msa_point       = 0;
326
                            data._msa_alt_intern  = 0;
fix MSA display
Sébastien MARQUE authored on 2020-05-23
327
                            data.timers.MSA_geodinfo.stop();
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
328
                        }
329
                    });
330
                }
331
                data.timers.MSA_geodinfo.start();
332
                return data._msa_alt == -1 ? '-----ft' : sprintf('%5ift', data._msa_alt);
333
            }, 'Minimum Safe Altitude'],
navigation box content
Sébastien MARQUE authored on 2020-05-12
334
#            BRG: [func return '---°', 'Bearing'],
335
#            ESA: [func return '-----', 'Enroute Safe Altitude'],
336
#            ISA: [func return '-----', 'ISA Relative Temperature'],
337
#            TKE: [func return ' ---°', 'Track Angle Error'],
338
#            VSR: [func return ' ----', 'Vertical Speed Required'],
339
# }}}
340
        };
341
        if (m.device.role == 'PFD')
342
            foreach (var item; keys(m.navbox))
343
                if (item != 'LEG' and item != 'DIS' and item != 'ETE')
344
                    delete(m.navbox, item);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
345
        return m;
346
    },
347
#}}}
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
348

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

            
379
# temporary Widget Display for HDG and CRS modification {{{
380

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

            
383
    timerTrigger : func {
384
        var now = systime();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
385
        foreach (var id; keys(me.temporaryWidgetDisplay)) {
386
            if (me.temporaryWidgetDisplay[id] < now) {
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
387
                me.screenElements[id].hide();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
388
                delete(me.temporaryWidgetDisplay, id);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
389
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
390
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
391
    },
392

            
393
    addTimer : func (duration, element) {
394
        if (typeof(element) == 'scalar')
395
            element = [ element ];
396
        var end = systime() + duration;
397
        foreach (var e; element)
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
398
            me.temporaryWidgetDisplay[e] = end;
commit initial
Sébastien MARQUE authored on 2017-03-07
399
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
400
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
401

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
402
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
403
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
404
        if (me.device.role == 'PFD') {
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
405
            me.timers.updateAI     = maketimer(0.1, me, me.updateAI     );
406
            me.timers.updateVSI    = maketimer(0.1, me, me.updateVSI    );
407
            me.timers.updateIAS    = maketimer(0.1, me, me.updateIAS    );
408
            me.timers.updateALT    = maketimer(0.2, me, me.updateALT    );
409
            me.timers.updateHSI    = maketimer(0.2, me, me.updateHSI    );
410
            me.timers.updateTIME   = maketimer(1.0, me, me.updateTIME   );
411
            me.timers.updateOAT    = maketimer(3.0, me, me.updateOAT    );
412
            me.timers.updateTAS    = maketimer(0.5, me, me.updateTAS    );
413
            me.timers.updateBRG    = maketimer(0.5, me, me.updateBRG    );
414
            me.timers.updateXPDR   = maketimer(0,   me, me.updateXPDR   ); me.timers.updateXPDR.singleShot=1;
415
            me.timers.updateBARO   = maketimer(0,   me, me.updateBARO   ); me.timers.updateBARO.singleShot=1;
416
            me.timers.updateOMI    = maketimer(1.0, me, me.updateOMI    );
417
            me.timers.timerTrigger = maketimer(1.0, me, me.timerTrigger );
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
418
            me.timers.updateAOA    = maketimer(0.1, me, me.updateAOA    );    me.timers.updateAOA.singleShot=1;
419
            me.timers.updateCDI    = maketimer(0.3, me, me.updateCDI    );    me.timers.updateCDI.singleShot=1;
420
            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
421

            
heading bug set at power on
Sébastien MARQUE authored on 2020-05-30
422
            me.screenElements['Heading-bug'].setRotation(int(afcs.getValue('heading-bug-deg')) * D2R);
423

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
424
            me.screen.show();
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
425
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
426
        }
427
        else {
428
            me.updateEIS();
429
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
430
            me['page selected'] = 0;
431
            me.setMFDPages();
432
            me.device.buttons.MENU = me.device.buttons.MapMenu;
433
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
434

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

            
441
        foreach (var timer; keys(me.timers))
442
            me.timers[timer].start();
commit initial
Sébastien MARQUE authored on 2017-03-07
443
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
444
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
445

            
some added comments
Sébastien MARQUE authored on 2017-03-18
446
    colors : {
447
# set of predefined colors {{{
448
        green : [0, 1, 0],
449
        white : [1, 1, 1],
450
        black : [0, 0, 0],
451
        lightblue : [0, 1, 1],
452
        darkblue : [0, 0, 1],
453
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
454
        magenta : [1, 0, 1],
add yellow predefined color
Sébastien MARQUE authored on 2020-05-11
455
        yellow : [1, 1, 0],
some added comments
Sébastien MARQUE authored on 2017-03-18
456
    },
457
#}}}
458

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

            
517
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
518
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
519
        PitchScale   : "rect(70,664,370,256)",
520
        SpeedLint1   : "rect(252,226,318,204)",
521
        SpeedTape    : "rect(115,239,455,156)",
522
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
523
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
524
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
525
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
526

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

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
574
    softkeys_inactivity : func {
575
# automagically back to previous level after some delay {{{
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
576
        me.timers.softkeys_inactivity = maketimer (
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
577
            me.softkeys_inactivity_delay,
578
            func {
579
                pop(me.device.softkeys.path);
580
                me.updateSoftKeys();
581
            }, me);
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
582
        me.timers.softkeys_inactivity.singleShot = 1;
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
583
    },
584
#}}}
585

            
softkey is implemented by de...
Sébastien MARQUE authored on 2017-12-21
586
    setSoftKeyColor : func (n, active, implemented = 1, alert = 0) {
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
587
# set colors for active softkeys {{{
588
        var sftk = sprintf('SoftKey%02i-', n);
589
        if (active) {
590
            var bg = alert ? 1 : 0.5;
591
            me.screenElements[sftk ~ 'bg']
592
                .setColorFill(bg,bg,bg);
593
            me.screenElements[sftk ~ 'text']
594
                .setColor(0,0,0);
595
        }
596
        else {
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
597
            var tc = implemented ? 1 : 0.5;
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
598
            me.screenElements[sftk ~ 'bg']
599
                .setColorFill(0,0,0);
600
            me.screenElements[sftk ~ 'text']
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
601
                .setColor(tc,tc,tc);
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
602
        }
603
    },
604
#}}}
605

            
navigation box content
Sébastien MARQUE authored on 2020-05-12
606
    updateNavigationBox : func {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
607
# update Navigation Box on MFD and PFD header {{{
608
        var route = me.device.map.layers.route;
navigation box content
Sébastien MARQUE authored on 2020-05-12
609
        data.fpSize = size(route.flightPlan);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
610
        if (me.device.role == 'MFD') {
611
            for (var i=1; i<=4; i+=1)
612
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
613
                    .setText(
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
614
                        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
615
                    );
616
        }
617
        else { # PFD
MFD navbox always available
Sébastien MARQUE authored on 2020-05-20
618
            var enroute = getprop('/autopilot/route-manager/current-wp') > -1;
improve route info display
Sébastien MARQUE authored on 2020-05-03
619
            me.screenElements['ETE'].setVisible(enroute);
620
            me.screenElements['DIS'].setVisible(enroute);
navigation box content
Sébastien MARQUE authored on 2020-05-12
621
            me.screenElements['ETE-text'].setVisible(enroute).setText(me.navbox.ETE[0]());
622
            me.screenElements['DIS-text'].setVisible(enroute).setText(me.navbox.DIS[0]());
623
            me.screenElements['LEG-text'].setVisible(enroute).setText(me.navbox.LEG[0]());
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
624
        }
625
    },
626
#}}}
627

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
628
    updateSoftKeys : func {
629
# update SoftKeys boxes {{{
630
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
631
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
632
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
633
                .setText('ALERTS');
634
            if (size(me.device.softkeys.path) != 0)
635
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
636
                    .setText('BACK')
637
                    .setColor(1,1,1);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
638
        }
639

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
640
        var path = keyMap[me.device.role];
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
641
        var bindings = me.device.softkeys.bindings[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
642
        var pathid = '';
643
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
644
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
645
            pathid ~= p;
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
646
            if (contains(bindings, p))
647
                bindings = bindings[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
648
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
649

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

            
681
        if (size(me.device.softkeys.path))
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
682
            me.timers.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
683
        else
old timers2 removed
Sébastien MARQUE authored on 2020-05-15
684
            me.timers.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
685
    },
686
#}}}
687

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

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
709
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
710
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
711
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
712
        me.screenElements.VSIText
713
            .setText(num(math.round(vsi, 10)));
714
        if (vsi > 4500)
715
            vsi = 4500;
716
        elsif (vsi < -4500)
717
            vsi = -4500;
718
        me.screenElements.VSI
719
            .setTranslation(0, vsi * -0.03465);
720
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
721
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
722

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

            
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
756
        var Sy = 0;
757
        for (var i = 8; i >= 0; i -= 1)
758
            me._last_ias_Sy[i+1] = me._last_ias_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
759
        var now = systime();
760
        # estimated speed in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
761
        me._last_ias_Sy[0] = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
762
        foreach (var _Sy; me._last_ias_Sy)
763
            Sy += _Sy;
764
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
765
        if (abs(Sy) > 30)
766
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
767
        me.screenElements['Airspeed-Trend-Indicator']
768
            .setScale(1,Sy)
769
            .setTranslation(0, -284.5 * (Sy - 1));
770
        me._last_ias_kt = ias;
771
        me._last_ias_s = now;
animation IAS
Sébastien MARQUE authored on 2017-03-10
772
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
773
    _last_ias_kt : 0,
774
    _last_ias_s : systime(),
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
775
    _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
776
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
777
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
778

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
779
    updateTAS: func {
780
# updates the True Airspeed and GroundSpeed indicators {{{
781
        me.screenElements['TAS-text']
782
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
783
        me.screenElements['GSPD-text']
784
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
785
    },
786
#}}}
787

            
788
    updateALT: func () {
789
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
790
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
791
        if (alt < 0)
792
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
793
                .setText(sprintf("%3d",math.ceil(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
794
        elsif (alt < 100)
795
            me.screenElements.Alt11100
796
                .setText('');
797
        else
798
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
799
                .setText(sprintf("%3i",math.floor(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
800
        me.screenElements.AltLint00011
801
            .setTranslation(0,math.fmod(alt,100) * 1.24);
802

            
803
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
804
        if (alt> -1000 and alt< 1000000) {
805
            var Offset10 = 0;
806
            var Offset100 = 0;
807
            var Offset1000 = 0;
808
            if (alt< 0) {
809
                var Ne = 1;
810
                var alt= -alt;
811
            }
812
            else
813
                var Ne = 0;
814

            
815
            var Alt10       = math.mod(alt,100);
816
            var Alt100      = int(math.mod(alt/100,10));
817
            var Alt1000     = int(math.mod(alt/1000,10));
818
            var Alt10000    = int(math.mod(alt/10000,10));
819
            var Alt20       = math.mod(Alt10,20)/20;
820
            if (Alt10 >= 80)
821
                var Alt100 += Alt20;
822

            
823
            if (Alt10 >= 80 and Alt100 >= 9)
824
                var Alt1000 += Alt20;
825

            
826
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
827
                var Alt10000 += Alt20;
828

            
829
            if (alt> 100)
830
                var Offset10 = 100;
831

            
832
            if (alt> 1000)
833
                var Offset100 = 10;
834

            
835
            if (alt> 10000)
836
                var Offset1000 = 10;
837

            
838
            if (!Ne) {
839
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
840
                var altCentral = (int(alt/100)*100);
841
            }
842
            elsif (Ne) {
843
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
844
                var altCentral = -(int(alt/100)*100);
845
            }
846
            me.screenElements["AltBigC"].setText("");
847
            me.screenElements["AltSmallC"].setText("");
848
            for (var place = 1; place <= 6; place += 1) {
849
                var altUP = altCentral + (place*100);
850
                var offset = -30.078;
851
                if (altUP < 0) {
852
                    var altUP = -altUP;
853
                    var prefix = "-";
854
                    var offset += 15.039;
855
                }
856
                else
857
                    var prefix = "";
858

            
859
                if (altUP == 0) {
860
                    var AltBigUP    = "";
861
                    var AltSmallUP  = "0";
862

            
863
                }
864
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
865
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
866
                    var AltSmallUP  = "";
867
                }
868
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
869
                    var AltBigUP    = "";
870
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
871
                    var offset = -30.078;
872
                }
873
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
874
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
875
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
876
                    var offset += 15.039;
877
                }
878
                else {
879
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
880
                    var mod = int(math.mod(altUP,1000));
881
                    var AltSmallUP  = sprintf("%1d", mod);
882
                    var offset += 30.078;
883
                }
884

            
885
                me.screenElements["AltBigU"~place].setText(AltBigUP);
886
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
887
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
888
                var altDOWN = altCentral - (place*100);
889
                var offset = -30.078;
890
                if (altDOWN < 0) {
891
                    var altDOWN = -altDOWN;
892
                    var prefix = "-";
893
                    var offset += 15.039;
894
                }
895
                else
896
                    var prefix = "";
897

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

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
950
    updateBARO : func () {
951
# update BARO widget {{{
952
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
953
        me.screenElements['BARO-text']
954
            .setText(sprintf(fmt,
955
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
956
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
957
                );
958
    },
959
    _baro_unit : 'inhg',
960
#}}}
961

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
962
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
963
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
964
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
965
        me.screenElements.Rose
966
            .setRotation(-hdg * D2R);
967
        me.screenElements['HDG-text']
968
            .setText(sprintf("%03u°", hdg));
969
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
970
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
971

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

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

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

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

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1093
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1094
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1095
        # arg[0]._r = <comm|nav>
1096
        if (contains(arg[0], "active")) {
1097
            if (arg[0]['active'] == 'none') {
1098
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1099
                    .setColor(1,1,1);
1100
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1101
                    .setColor(1,1,1);
1102
            }
1103
            else {
1104
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1105
                    .setColor(0,1,0);
1106
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1107
                    .setColor(1,1,1);
1108
            }
1109
        }
1110
        if (contains(arg[0], 'tune')) {
1111
            # n = 0 -> NAV1/COMM1
1112
            # n = 1 -> NAV1/COMM2
1113
            me.screenElements[arg[0]._r ~ '-freq-switch']
1114
                .setTranslation(0, arg[0].tune * 25);
1115
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1116
                .setColor(0,1,1);
1117
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1118
                .setColor(1,1,1);
1119
        }
1120
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1121
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1122
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1123
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1124
                .setText(sprintf(fmt, getprop('/instrumentation/'
1125
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1126
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1127
                .setText(sprintf(fmt, getprop('/instrumentation/'
1128
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1129
        }
1130
        if (contains(arg[0], 'set')) {
1131
            # 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
1132
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1133
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1134
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1135
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1136
        }
1137
        if (contains(arg[0], 'auto')) {
1138
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1139
            var radio = arg[0].auto;
1140
            me._updateRadio({refresh: 1, _r: radio});
1141
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1142
            settimer(func me._updateRadio({auto: radio}), 2);
1143
        }
1144
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1145
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1146

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1147
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1148
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1149
        # made active via menu
1150
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1151
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1152
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1153
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1154
                me.screenElements['nav1-id']
1155
                    .setColor(1,1,1);
1156
                me.screenElements['nav2-id']
1157
                    .setColor(1,1,1);
1158
                me.screenElements['NAV1-pointer']
1159
                    .hide();
1160
                me.screenElements['NAV2-pointer']
1161
                    .hide();
1162
            }
1163
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1164
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1165
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1166
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1167
                    .setColor(0,1,0);
1168
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1169
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1170
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1171
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1172
#                me.screenElements['HDI']
1173
#                    .setRotation();
1174
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1175
#                    .hide();
1176
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1177
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1178
#                        .hide();
1179
            }
1180
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1181
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1182
            # 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
1183
            if (arg[0].val == nil)
1184
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1185
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1186
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1187
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1188
        else {
1189
            arg[0]._r = 'nav';
1190
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1191
        }
1192
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1193
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1194

            
1195
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1196
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1197
        arg[0]._r = 'comm';
1198
        me._updateRadio(arg[0]);
1199
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1200
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1201

            
1202
    updateTIME : func {
1203
# updates the displayed time botoom left {{{
1204
        me.screenElements['TIME-text']
1205
            .setText(getprop('/sim/time/gmt-string'));
1206
    },
1207
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1208

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

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1246
    updateOAT : func {
1247
# update OAT display on normal and reversionnary modes (every 3s) {{{
1248
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1249
        me.screenElements['OAT-text']
1250
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1251
    },
1252
    _oat_unit : 'c',
1253
#}}}
1254

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

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

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

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

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

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