zkv1000 / Nasal / display.nas /
Newer Older
1432 lines | 56.061kb
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
827
            if (alt> 100)
828
                var Offset10 = 100;
829

            
830
            if (alt> 1000)
831
                var Offset100 = 10;
832

            
833
            if (alt> 10000)
834
                var Offset1000 = 10;
835

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

            
857
                if (altUP == 0) {
858
                    var AltBigUP    = "";
859
                    var AltSmallUP  = "0";
860

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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