zkv1000 / Nasal / display.nas /
Newer Older
1473 lines | 57.938kb
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 ILS glideslope
Sébastien MARQUE authored on 2020-06-09
74
                'VDI', 'GS-ILS', 'VDI-scale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
75
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
76
            );
77
            append(groups.hide,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
78
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
79
                'EIS',
80
                'CDI',
81
                'OMI', 'MarkerBG', 'MarkerText',
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 ILS glideslope
Sébastien MARQUE authored on 2020-06-09
110
                'VDI-type-bg',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
111
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
112
            );
113
            append(groups.clip,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
114
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
115
                'SpeedLint1',
116
                'SpeedTape',
117
                'LintAlt',
118
                'AltLint00011',
119
                'PitchScale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
120
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
121
            );
122
            append(groups.text,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
123
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
124
                'SelectedALT-text',
125
                'TAS-text',
126
                'GSPD-text',
127
                'TIME-text',
128
                'OAT-text',
129
                'VSIText',
130
                'Speed110',
131
                'Alt11100',
132
                'HDG-text',
133
                'BARO-text',
134
                'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
135
                'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
136
                'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
137
                'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
138
                'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
139
                'XPDR-MODE-text', 'XPDR-DIGIT-3-text', 'XPDR-DIGIT-2-text', 'XPDR-DIGIT-1-text', 'XPDR-DIGIT-0-text',
140
                'ETE', 'ETE-text', 'DIS', 'DIS-text', 'LEG-text',
141
                'LATMOD-Armed-text', 'LATMOD-Active-text',
142
                'AP-Status-text', 'YD-Status-text',
143
                'VERMOD-Active-text', 'VERMOD-Armed-text', 'VERMOD-Reference-text',
144
                'AltBigC', 'AltSmallC'
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
145
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
146
            );
147
            for (var place = 1; place <= 6; place +=1) {
148
                append(groups.text,
149
                    'AltBigU' ~ place,
150
                    'AltSmallU' ~ place,
151
                    'AltBigD' ~ place,
152
                    'AltSmallD' ~ place
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
153
                );
animation ALT
Sébastien MARQUE authored on 2017-03-11
154
            }
cosmetics
Sébastien MARQUE authored on 2020-05-12
155
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/PFD.svg');
156
        }
157
        else {
158
            var eis_file = eis.getValue('type');
159
            if (eis_file == nil)
160
                eis_file = eis.getValue('file');
161

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

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

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

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

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

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

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

            
217
        m.navbox = {
218
# {{{ the data to show info in navbox
219
            DTK: [func {
220
                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
221
                if (dtk == nil)
222
                    return '---°';
223
                else
224
                    return sprintf('%03i°', dtk);
225
            }, 'Desired Track'],
226
            ETE: [func {
227
                if (data.fpSize == 0) return '--:--';
228
                var eta = getprop('/autopilot/route-manager/wp/eta');
229
                return sprintf('%5s', eta != nil ? eta : '--:--');
230
            }, 'Estimated Time Enroute'],
231
            TDR: [func {
232
                if (data.fpSize == 0) return '---NM';
233
                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
234
                if (dist != nil)
235
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
236
                else
237
                    return '---NM';
238
            }, 'Total Distance Remaining'],
239
            DIS: [func {
240
                if (data.fpSize == 0) return '---NM';
241
                var dist = getprop('/autopilot/route-manager/wp/dist');
242
                if (dist != nil)
243
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
244
                else
245
                    return '---NM';
246
            }, 'Distance remaining'],
247
            LEG: [func {
248
                if (data.fpSize == 0) return '';
249
                var route = m.device.map.layers.route;
250
                var wp = route.flightPlan[route.currentLeg.index];
251
                return sprintf(' %s %s %s', wp[0].name, utf8.chstr(9658), wp[1].name);
252
            }, ''], # not listed in MFD menu, on PFD only the leg is shown not the item
253
            LDG: [func {
254
                var eteSeconds = getprop('/autopilot/route-manager/ete');
255
                var eteHours = math.floor(eteSeconds / 3600);
256
                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
257
                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
258
            }, 'ETA at Final Destination'],
259
            END: [func {
260
                var total_fuel = getprop('/consumables/fuel/total-fuel-gals');
261
                var gs = getprop('/velocities/groundspeed-kt');
262
                var consumption = 0;
263
                foreach(var engine; props.globals.getNode('/engines').getChildren('engine')) {
264
                    var ec = engine.getValue('fuel-flow-gph');
265
                    consumption += ec != nil ? ec : 0;
266
                }
267
                if (consumption > 0 and gs > 0)
268
                    return sprintf('%3iNM', (total_fuel * gs) / consumption);
269
                else
270
                    return '---NM';
271
            }, 'Endurance'],
272
            ETA: [func {
273
                var eteSeconds = getprop('/autopilot/route-manager/ete');
274
                var eta_hours = getprop('/sim/time/utc/hour');
275
                var eteHours = math.floor(eteSeconds / 3600);
276
                if (eteHours > 12)
277
                    return '--:--';
278
                var eta_minutes = int((eteSeconds - (eteHours * 3600)) / 60) + getprop('/sim/time/utc/minute');
279
                if (eta_minutes > 59) {
280
                    eta_minutes -= 60;
281
                    eta_hours += 1;
282
                }
283
                eta_hours += eteHours;
284
                if (eta_hours > 23)
285
                    eta_hours -= 24;
286
                return sprintf('%02i:%02i', eta_hours, eta_minutes);
287
            }, 'Estimated Time of Arrival'],
288
            GS:  [func return sprintf('%3iKT', getprop('/velocities/groundspeed-kt')), 'Ground Speed'],
289
            TRK: [func return sprintf('%03i°', getprop('/orientation/track-deg')), 'Track'],
290
            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
291
            FOB: [func return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')), 'Fuel on Board'],
292
            XTK: [func {
fix XTK display
Sébastien MARQUE authored on 2020-05-23
293
                var xtk = nil;
adds MSA and XTK navbox info...
Sébastien MARQUE authored on 2020-05-22
294
                var source = cdi.getValue('source');
295
                if (source == 'NAV1')
fix XTK display
Sébastien MARQUE authored on 2020-05-23
296
                    var xtk = abs(getprop('/instrumentation/nav[0]/crosstrack-error-m')) * M2NM;
297
                elsif (source == 'NAV2')
298
                    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
299
                elsif (source == 'GPS')
fix XTK display
Sébastien MARQUE authored on 2020-05-23
300
                    var xtk = abs(getprop('/instrumentation/gps/wp/wp[1]/course-error-nm'));
301

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

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

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

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

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

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

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

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

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

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

            
442
        foreach (var timer; keys(me.timers))
443
            me.timers[timer].start();
adds ILS glideslope
Sébastien MARQUE authored on 2020-06-09
444

            
445
        me.timers.updateGS = maketimer(0.2, me, me.updateGS);
commit initial
Sébastien MARQUE authored on 2017-03-07
446
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
447
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
448

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
829
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
830
                var Alt10000 += Alt20;
831

            
832
            if (alt> 100)
833
                var Offset10 = 100;
834

            
835
            if (alt> 1000)
836
                var Offset100 = 10;
837

            
838
            if (alt> 10000)
839
                var Offset1000 = 10;
840

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

            
862
                if (altUP == 0) {
863
                    var AltBigUP    = "";
864
                    var AltSmallUP  = "0";
865

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

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

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

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

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

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

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

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

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
1035
    updateCDI : func {
1036
# animation for CDI {{{
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1037
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
1038
        if (source == 'OFF') {
1039
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
1040
                foreach (var t; ['pointer', 'CDI'])
1041
                    me.screenElements[s ~ '-' ~ t].hide();
1042
            me.screenElements['CDI-GPS-ANN-text'].hide();
1043
            me.screenElements['CDI-GPS-XTK-text'].hide();
1044
            me.screenElements['CDI-SRC-text'].hide();
1045
            me.screenElements['CDI'].hide();
1046
        }
1047
        else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1048
            var course = cdi.getValue('course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1049
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
1050
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1051
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
1052
                .show();
1053
            me.screenElements['GPS-CTI']
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
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
1057
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
1058
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1059
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
1060
                me.screenElements[s ~ '-pointer']
1061
                    .setRotation(rot)
1062
                    .setVisible(source == s);
1063
                me.screenElements[s ~ '-CDI']
1064
                    .setVisible(source == s);
1065
                foreach (var f; ['FROM', 'TO'])
1066
                    me.screenElements[s ~ '-' ~ f]
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1067
                        .setVisible(s == source and cdi.getValue(f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
1068
                me.screenElements['CDI-SRC-text']
1069
                    .setText(source)
1070
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
1071
                    .show();
1072
            }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1073
            var deflection = cdi.getValue('course-deflection');
warning on CDI for NAV not i...
Sébastien MARQUE authored on 2020-05-30
1074
            if (left(source, 3) == 'NAV') {
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1075
                var scale = deflection / 4;
fix range warning on CDI
Sébastien MARQUE authored on 2020-06-03
1076
                if (cdi.getValue('in-range') == 0)
warning on CDI for NAV not i...
Sébastien MARQUE authored on 2020-05-30
1077
                    me.screenElements['CDI-GPS-XTK-text']
1078
                        .setColor(me.colors.green)
1079
                        .setText('RANGE')
1080
                        .setVisible(!me.screenElements['CDI-GPS-XTK-text'].getVisible());
1081
                else
1082
                    me.screenElements['CDI-GPS-XTK-text']
1083
                        .hide();
adds ILS glideslope
Sébastien MARQUE authored on 2020-06-09
1084
                if (source == 'NAV1' and getprop('/instrumentation/nav/nav-loc')) {
1085
                    me.screenElements['CDI-GPS-ANN-text']
1086
                        .setColor(me.colors.green)
1087
                        .setText('LOC')
1088
                        .show();
1089
                    cdi.setValue('course', int(getprop('/instrumentation/nav/radials/target-radial-deg')));
1090
                }
1091
                else
1092
                    me.screenElements['CDI-GPS-ANN-text'].hide();
warning on CDI for NAV not i...
Sébastien MARQUE authored on 2020-05-30
1093
            }
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1094
            else { # GPS
1095
                # TODO: deviation depending of the flight phase
1096
                # for now fixed 1 dot = 1 nm course error
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1097
                var abs_deflection_max = 2.4;
1098
                if (me.screenElements['LATMOD-Armed-text'].getText() == 'GPS')
1099
                    abs_deflection_max = 0.5;
adds GPS OBS mode
Sébastien MARQUE authored on 2020-05-30
1100
                if (getprop('/instrumentation/gps/mode') == 'obs') {
1101
                    abs_deflection_max = 0.1;
1102
                    me.screenElements['CDI-GPS-ANN-text']
adds ILS glideslope
Sébastien MARQUE authored on 2020-06-09
1103
                        .setColor(me.colors.magenta)
adds GPS OBS mode
Sébastien MARQUE authored on 2020-05-30
1104
                        .setText('OBS')
1105
                        .show();
1106
                }
1107
                else
1108
                    me.screenElements['CDI-GPS-ANN-text'].hide();
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1109
                var abs_deflection = abs(deflection);
1110
                me.screenElements['CDI-GPS-XTK-text']
fix issue with GPS/CDI
Sébastien MARQUE authored on 2020-05-28
1111
                    .setText(sprintf((abs_deflection < 1 ? 'XTK %.1fNM' : 'XTK %iNM'), abs_deflection))
warning on CDI for NAV not i...
Sébastien MARQUE authored on 2020-05-30
1112
                    .setColor(me.colors.magenta)
GFC700 GPS helper
Sébastien MARQUE authored on 2020-05-18
1113
                    .setVisible(abs_deflection > abs_deflection_max);
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1114
                var scale = deflection / 2;
1115
            }
fix bug with max cource devi...
Sébastien MARQUE authored on 2020-05-30
1116
            scale = (abs(scale) > 1.2) ? 1.2 * scale / abs(scale) : scale;
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1117
            me.screenElements[source ~ '-CDI']
1118
                .setTranslation(65 * scale, 0);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1119
            me.timers.updateCDI.start();
adds CDI
Sébastien MARQUE authored on 2017-03-18
1120
        }
1121
    },
1122
#}}}
1123

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1124
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1125
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1126
        # arg[0]._r = <comm|nav>
1127
        if (contains(arg[0], "active")) {
1128
            if (arg[0]['active'] == 'none') {
1129
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1130
                    .setColor(1,1,1);
1131
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1132
                    .setColor(1,1,1);
1133
            }
1134
            else {
1135
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1136
                    .setColor(0,1,0);
1137
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1138
                    .setColor(1,1,1);
1139
            }
1140
        }
1141
        if (contains(arg[0], 'tune')) {
1142
            # n = 0 -> NAV1/COMM1
1143
            # n = 1 -> NAV1/COMM2
1144
            me.screenElements[arg[0]._r ~ '-freq-switch']
1145
                .setTranslation(0, arg[0].tune * 25);
1146
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1147
                .setColor(0,1,1);
1148
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1149
                .setColor(1,1,1);
1150
        }
1151
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1152
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1153
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1154
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1155
                .setText(sprintf(fmt, getprop('/instrumentation/'
1156
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1157
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1158
                .setText(sprintf(fmt, getprop('/instrumentation/'
1159
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1160
        }
1161
        if (contains(arg[0], 'set')) {
1162
            # 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
1163
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1164
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1165
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1166
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1167
        }
1168
        if (contains(arg[0], 'auto')) {
1169
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1170
            var radio = arg[0].auto;
1171
            me._updateRadio({refresh: 1, _r: radio});
1172
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1173
            settimer(func me._updateRadio({auto: radio}), 2);
1174
        }
1175
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1176
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1177

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1178
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1179
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1180
        # made active via menu
1181
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1182
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1183
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1184
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1185
                me.screenElements['nav1-id']
1186
                    .setColor(1,1,1);
1187
                me.screenElements['nav2-id']
1188
                    .setColor(1,1,1);
1189
                me.screenElements['NAV1-pointer']
1190
                    .hide();
1191
                me.screenElements['NAV2-pointer']
1192
                    .hide();
1193
            }
1194
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1195
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1196
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1197
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1198
                    .setColor(0,1,0);
1199
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1200
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1201
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1202
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1203
#                me.screenElements['HDI']
1204
#                    .setRotation();
1205
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1206
#                    .hide();
1207
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1208
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1209
#                        .hide();
1210
            }
1211
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1212
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1213
            # 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
1214
            if (arg[0].val == nil)
1215
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1216
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1217
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1218
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1219
        else {
1220
            arg[0]._r = 'nav';
1221
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1222
        }
1223
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1224
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1225

            
1226
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1227
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1228
        arg[0]._r = 'comm';
1229
        me._updateRadio(arg[0]);
1230
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1231
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1232

            
1233
    updateTIME : func {
1234
# updates the displayed time botoom left {{{
1235
        me.screenElements['TIME-text']
1236
            .setText(getprop('/sim/time/gmt-string'));
1237
    },
1238
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1239

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1240
    updateXPDR : func {
1241
# updates transponder display {{{
1242
        for (var d = 0; d < 4; d+=1)
1243
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1244
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1245
        var tuning = radios.getValue('xpdr-tuning-digit');
1246
        var fms = radios.getValue('xpdr-tuning-fms-method');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1247
        for (var d = 0; d < 4; d+=1)
1248
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1249
                .setColor(1,1,1);
1250
        if (tuning != nil) {
1251
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1252
                .setColor(0,1,1);
1253
            if (fms)
1254
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1255
                    .setColor(0,1,1);
1256
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1257
        else {
1258
            if (getprop('/instrumentation/transponder/ident'))
1259
                var mode = 'IDENT';
1260
            else
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1261
                var mode = radios.getValue('xpdr-mode');
adds transponder
Sébastien MARQUE authored on 2017-03-17
1262
            var wow = getprop('/gear/gear/wow');
1263
            if (! wow and mode != 'STBY')
1264
                var color = [0, 1, 0];
1265
            else
1266
                var color = [1, 1, 1];
1267
            for (var d = 0; d < 4; d+=1)
1268
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1269
                    .setColor(color);
1270
            me.screenElements['XPDR-MODE-text']
1271
                .setColor(color)
1272
                .setText(mode);
1273
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1274
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1275
#}}}
1276

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1277
    updateOAT : func {
1278
# update OAT display on normal and reversionnary modes (every 3s) {{{
1279
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1280
        me.screenElements['OAT-text']
1281
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1282
    },
1283
    _oat_unit : 'c',
1284
#}}}
1285

            
1286
    updateWindData : func {
1287
# update the window text and arrows for OPTN1/2 {{{
1288
        if (me._winddata_optn == 0)
1289
            return;
make wind data available in ...
Sébastien MARQUE authored on 2020-05-28
1290
        if (data.ias > 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1291
            me.screenElements['WindData-NODATA']
1292
                .hide();
1293
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1294
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1295
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1296
            if (me._winddata_optn == 1) {
1297
                me.screenElements['WindData-OPTN1-HDG']
1298
                    .setRotation((alpha + 180) * D2R)
1299
                    .show();
1300
                me.screenElements['WindData-OPTN1-HDG-text']
1301
                    .setText(sprintf("%03i°", wind_hdg))
1302
                    .show();
1303
                me.screenElements['WindData-OPTN1-SPD-text']
1304
                    .setText(int(wind_spd) ~ 'KT')
1305
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1306
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1307
            else { # me._winddata_optn == 2
1308
                alpha *= D2R;
1309
                var Vt = wind_spd * math.sin(alpha);
1310
                var Ve = wind_spd * math.cos(alpha);
1311
                if (Vt != 0) {
1312
                    me.screenElements['WindData-OPTN2-crosswind-text']
1313
                        .setText(sprintf('%i', abs(Vt)))
1314
                        .show();
1315
                    me.screenElements['WindData-OPTN2-crosswind']
1316
                        .setScale(-abs(Vt)/Vt, 1)
1317
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1318
                        .show();
1319
                }
1320
                if (Ve != 0) {
1321
                    me.screenElements['WindData-OPTN2-headwind-text']
1322
                        .setText(sprintf('%i', abs(Ve)))
1323
                        .show();
1324
                    me.screenElements['WindData-OPTN2-headwind']
1325
                        .setScale(1, abs(Ve)/Ve)
1326
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1327
                        .show();
1328
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1329
            }
1330
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1331
        else {
1332
            foreach (var e; [
1333
                    'WindData-OPTN1-HDG',
1334
                    'WindData-OPTN1-HDG-text',
1335
                    'WindData-OPTN1-SPD-text',
1336
                    'WindData-OPTN2-crosswind-text',
1337
                    'WindData-OPTN2-crosswind',
1338
                    'WindData-OPTN2-headwind-text',
1339
                    'WindData-OPTN2-headwind'
1340
            ])
1341
                me.screenElements[e].hide();
1342
            me.screenElements['WindData-NODATA'].show();
1343
        }
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1344
        me.timers.updateWindData.start();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1345
    },
1346
    _winddata_optn : 0,
1347
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1348

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1349
    updateAOA : func {
1350
# update Angle Of Attack {{{
fix AOA not shown
Sébastien MARQUE authored on 2020-05-30
1351
        if (me.device.data.aoa + me.device.data['aoa-auto'] == 0)
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1352
            return;
1353
        var color = [1,1,1];
1354
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1355
        me.screenElements['AOA-text']
1356
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1357
        if (norm > 1) norm = 1;
1358
        if (norm > 0.9)
1359
            color = [1,0,0];
1360
        elsif (norm > 0.7)
1361
            color = [1,1,0];
1362
        elsif (norm < 0) {
1363
            norm = 0;
1364
            color = [1,0,0];
1365
        }
1366
        me.screenElements['AOA-needle']
1367
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1368
            .setColorFill(color);
1369
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1370
            .setColor(color);
settimers to maketimer conti...
Sébastien MARQUE authored on 2020-05-13
1371
        me.timers.updateAOA.start();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1372
    },
1373
# }}}
1374

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

            
1380
            var dev = radios.getNode(source).getValue();
1381
            var el  = 'BRG' ~ brg;
1382
            if (dev != 'OFF') {
1383
                var info = {
1384
                    pointer : nil,
1385
                    id : 'NO DATA',
1386
                    hdg : nil,
1387
                    dst : '--.-NM'
1388
                };
1389
                if (left(dev, 3) == 'NAV') {
1390
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1391
                    if (info.pointer) {
1392
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1393
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1394
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1395
                    }
1396
                }
1397
                elsif (dev == 'GPS') {
1398
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1399
                    if (info.pointer) {
1400
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1401
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1402
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1403
                    }
1404
                }
1405
                else { # there are 2 available ADF in FG, but instrument manage only 1
1406
                    info.pointer = getprop('/instrumentation/adf/in-range');
1407
                    if (info.pointer) {
1408
                        info.id  = getprop('/instrumentation/adf/ident');
1409
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1410
                    }
1411
                }
1412

            
1413
                if (info.pointer)
1414
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1415
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1416
                        .show();
1417
                else
1418
                    me.screenElements[el ~ '-pointer']
1419
                        .hide();
1420
                me.screenElements[el ~ '-SRC-text']
1421
                    .setText(dev);
1422
                me.screenElements[el ~ '-DST-text']
1423
                    .setText(info.dst);
1424
                me.screenElements[el ~ '-WPID-text']
1425
                    .setText(info.id);
1426
                me.screenElements['BRG' ~ brg]
1427
                    .show();
1428
            }
1429
            else {
1430
                me.screenElements['BRG' ~ brg]
1431
                    .hide();
1432
            }
1433
        }
1434
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1435
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1436

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1437
    updateOMI : func {
1438
# display marker baecon Outer, Middle, Inner {{{
1439
        var marker = nil;
1440
        foreach (var m; ['outer', 'middle', 'inner'])
1441
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1442
                marker = m;
1443
                me.screenElements['OMI']
1444
                    .show();
1445
                break;
1446
            }
1447
        if (marker != nil) {
1448
            me.screenElements['MarkerText']
1449
                .setText(me._omi_data[marker].t)
1450
                .show();
1451
            me.screenElements['MarkerBG']
1452
                .setColorFill(me._omi_data[marker].bg)
1453
                .show();
1454
        }
1455
        else
1456
            me.screenElements['OMI']
1457
                .hide();
1458
    },
1459
    _omi_data : {
1460
        'outer':  {t: 'O', bg: [0,1,1]},
1461
        'middle': {t: 'M', bg: [1,1,1]},
1462
        'inner':  {t: 'I', bg: [1,1,0]},
1463
    },
1464
#}}}
adds ILS glideslope
Sébastien MARQUE authored on 2020-06-09
1465

            
1466
    updateGS : func {
1467
# display glide-slope on ILS approach {{{
1468
        var deflection = getprop('/instrumentation/nav/gs-needle-deflection-norm');
1469
        me.screenElements['GS-ILS']
1470
            .setTranslation(0, deflection * 100);
1471
    },
1472
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1473
};