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

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
25
        m.timers2 = {}; # tho old timer implementation use already a named timer hash
26
        # Softkeys revert to the previous level after 45 seconds of inactivity.
27
        m.softkeys_inactivity_delay = 45;
28

            
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
29
            var groups = {
animation VSI
Sébastien MARQUE authored on 2017-03-10
30
                show : [
makes header visible on MFD ...
Sébastien MARQUE authored on 2017-03-18
31
                    'Header',
commit initial
Sébastien MARQUE authored on 2017-03-07
32
                    'SoftKeysTexts', 
33
                    'COMM', 
34
                    'NAV', 
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
35
                    'nav-freq-switch',
36
                    'comm-freq-switch',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
37
                ],
38
                text: [
39
                    'nav1-standby-freq', 'nav1-selected-freq', 'nav1-id',
40
                    'nav2-standby-freq', 'nav2-selected-freq', 'nav2-id',
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
41
                    'comm1-standby-freq', 'comm1-selected-freq',
42
                    'comm2-standby-freq', 'comm2-selected-freq',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
43
                ],
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
44
                hide : [ 'Failures', 'NAV-COMM-Failures' ],
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
45
                clip: [ ],
46
            };
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
47

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

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
53
            if (m.device.role == 'PFD') {
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
54
                append(groups.show,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
55
# {{{
commit initial
Sébastien MARQUE authored on 2017-03-07
56
                    'XPDR-TIME', 
AI disponible
Sébastien MARQUE authored on 2017-03-10
57
                    'FlightInstruments',
58
                    'Horizon',
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
59
                    'bankPointer',
animation VSI
Sébastien MARQUE authored on 2017-03-10
60
                    'VSI',
animation HSI
Sébastien MARQUE authored on 2017-03-11
61
                    'Rose',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
62
                    'Heading-bug',
63
                    'PFD-Widgets',
trends animation
Sébastien MARQUE authored on 2017-03-13
64
                    'Trends',
65
                    'Airspeed-Trend-Indicator',
66
                    'Altitude-Trend-Indicator',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
67
                    'OAT',
68
                    'IAS-bg',
69
                    'TAS',
70
                    'GSPD',
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
71
                    'BARO-bg',
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
72
                    'SlipSkid',
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
73
                    'IAS-Vx', 'IAS-Vy', 'IAS-Vr', 'IAS-Vglide',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
74
# }}}
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
75
                );
76
                append(groups.hide,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
77
# {{{
adds EIS
Sébastien MARQUE authored on 2017-03-18
78
                    'EIS',
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
79
                    'CDI',
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
80
                    'OMI', 'MarkerBG', 'MarkerText',
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
81
                    'VDI',
adds CDI
Sébastien MARQUE authored on 2017-03-18
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',
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
85
                    'BRG1-pointer',
86
                    'BRG2-pointer',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
87
                    'SelectedHDG-bg',
88
                    'SelectedHDG-bgtext',
89
                    'SelectedHDG-text',
90
                    'SelectedCRS-bg',
91
                    'SelectedCRS-bgtext',
92
                    'SelectedCRS-text',
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
93
                    'SelectedALT', 'SelectedALT-bug', 'SelectedALT-bg', 'SelectedALT-symbol',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
94
                    'TAS',
95
                    'GSPD',
96
                    'WindData',
97
                    'Reversionnary',
98
                    'Annunciation',
99
                    'Comparator',
100
                    'BRG1',
101
                    'BRG2',
102
                    'DME1',
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
103
                    'PFD-Map-bg',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
104
                    'PFD-Multilines',
hide orientation on Inset ma...
Sébastien MARQUE authored on 2017-05-24
105
                    'MapOrientation',
improves WindData display
Sébastien MARQUE authored on 2017-03-16
106
                    'WindData', 'WindData-OPTN1', 'WindData-OPTN2', 'WindData-OPTN1-HDG', 'WindData-OPTN2-symbol', 'WindData-OPTN2-headwind', 'WindData-OPTN2-crosswind', 'WindData-NODATA',
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
107
                    'AOA', 'AOA-needle', 'AOA-text', 'AOA-approach',
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
108
                    'MFD-navbox',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
109
# }}}
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
110
                );
111
                append(groups.clip,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
112
# {{{
animation IAS
Sébastien MARQUE authored on 2017-03-10
113
                    'SpeedLint1',
animation ALT
Sébastien MARQUE authored on 2017-03-11
114
                    'SpeedTape',
115
                    'LintAlt',
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
116
                    'AltLint00011',
117
                    'PitchScale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
118
# }}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
119
                );
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
120
                append(groups.text,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
121
# {{{
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
122
                    'SelectedALT-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
123
                    'TAS-text',
124
                    'GSPD-text',
anime time display
Sébastien MARQUE authored on 2017-03-13
125
                    'TIME-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
126
                    'OAT-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
127
                    'VSIText',
128
                    'Speed110',
129
                    'Alt11100',
130
                    'HDG-text',
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
131
                    'BARO-text',
adds CDI
Sébastien MARQUE authored on 2017-03-18
132
                    'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
133
                    'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
134
                    'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
135
                    'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
136
                    'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
adds transponder
Sébastien MARQUE authored on 2017-03-17
137
                    'XPDR-MODE-text', 'XPDR-DIGIT-3-text', 'XPDR-DIGIT-2-text', 'XPDR-DIGIT-1-text', 'XPDR-DIGIT-0-text',
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
138
                    'ETE', 'ETE-text', 'DIS', 'DIS-text', 'LEG-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
139
                    'AltBigC', 'AltSmallC'
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
140
# }}}
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
141
                );
142
                for (var place = 1; place <= 6; place +=1) {
143
                    append(groups.text,
144
                        'AltBigU' ~ place,
145
                        'AltSmallU' ~ place,
146
                        'AltBigD' ~ place,
147
                        'AltSmallD' ~ place
148
                    );
149
                }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
150
                canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Systems/PFD.svg');
animation ALT
Sébastien MARQUE authored on 2017-03-11
151
            }
adds EIS
Sébastien MARQUE authored on 2017-03-18
152
            else {
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
153
                var eis_file = getprop('/instrumentation/zkv1000/eis/type');
154
                if (eis_file == nil)
155
                    eis_file = getprop('/instrumentation/zkv1000/eis/file');
156

            
157
                if (eis_file != nil) {
158
                    if (find('/', eis_file) == -1)
159
                        eis_file = data.zkv1000_dir ~ 'Nasal/EIS/' ~ eis_file ~ '.nas';
160
                    elsif (split('/', eis_file)[0] == 'Aircraft') {
161
                        var path = split('/', eis_file);
162
                        if (getprop('/sim/fg-aircraft') != nil) {
163
                            eis_file = getprop('/sim/fg-aircraft');
164
                            for (var i = 1; i < size(path); i += 1)
165
                                eis_file ~= '/' ~ path[i];
166
                        }
167
                        else
168
                            eis_file = getprop('/sim/fg-root') ~ '/' ~ eis_file;
169
                    }
170
                }
171
                else
172
                    eis_file = data.zkv1000_dir ~ 'Nasal/EIS/none.nas';
173

            
174
                if (io.stat(eis_file) == nil
175
                and print(eis_file ~ ' not found'))
176
                    eis_file = data.zkv1000_dir ~ 'Nasal/EIS/none.nas';
177
                io.load_nasal(eis_file, 'zkv1000');
178

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
179
                if (contains(m.parents[0], 'showEIS'))
180
                    m.showEIS(groups);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
181

            
182
                append(groups.hide, 'PFD-navbox');
183
                for (var i=1; i <= 4; i+=1)
184
                    foreach (var t; ['ID', 'VAL'])
185
                        append(groups.text, 'DATA-FIELD' ~ i ~ '-' ~ t ~ '-text');
adds EIS
Sébastien MARQUE authored on 2017-03-18
186
            }
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
187

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
188
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Systems/softkeys.svg');
189
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Systems/header-nav-comm.svg');
animation ALT
Sébastien MARQUE authored on 2017-03-11
190

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
191
            m.loadGroup(groups);
192

            
193
            if (m.device.role == 'PFD') {
194
                m.device.data.aoa = 0;
195
                m.device.data['aoa-auto'] = 0;
196
                m.device.data.mapclip = {
197
                    top: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[1]) - 1,
198
                    right: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[2]) - 1,
199
                    bottom: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[3]) - 1,
200
                    left: math.ceil(m.screenElements['PFD-Map-bg'].getTransformedBounds()[0]) - 1,
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
201
                };
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
202
            }
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
203
            else {
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
204
                m.device.data.mapclip = {
205
                    top: math.ceil(m.screenElements['Header'].getTransformedBounds()[3]),
206
                    right: m.display.get('view[0]'),
207
                    bottom: math.ceil(m.screenElements['SoftKeysTexts'].getTransformedBounds()[1]),
208
                    left: contains(m.screenElements, 'EIS') ? math.ceil(m.screenElements['EIS'].getTransformedBounds()[2]) : 0,
set MFD map size relative to...
Sébastien MARQUE authored on 2017-04-18
209
                };
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
210
            }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
211
        return m;
212
    },
213
#}}}
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
214

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
215
# timers stuff {{{
216
    timers : {},
217

            
218
    timerTrigger : func {
219
        var now = systime();
220
        foreach (var id; keys(me.timers)) {
221
            if (me.timers[id] < now) {
222
                me.screenElements[id].hide();
223
                delete(me.timers, id);
224
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
225
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
226
        settimer(func me.timerTrigger(), 1);
227
    },
228

            
229
    addTimer : func (duration, element) {
230
        if (typeof(element) == 'scalar')
231
            element = [ element ];
232
        var end = systime() + duration;
233
        foreach (var e; element)
234
            me.timers[e] = end;
commit initial
Sébastien MARQUE authored on 2017-03-07
235
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
236
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
237

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
238
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
239
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
240
        if (me.device.role == 'PFD') {
241
            me.updateAI();
242
            me.updateVSI();
243
            me.updateIAS();
244
            me.updateALT();
245
            me.updateHSI();
246
            me.updateTIME();
247
            me.updateOAT();
248
            me.updateTAS();
249
            me.updateBRG();
250
            me.updateXPDR();
251
            me.updateBARO();
252
            me.updateOMI();
253
            me.timerTrigger();
254
            me.screen.show();
255
        }
256
        else {
257
            me.updateEIS();
258
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
259
            me['page selected'] = 0;
260
            me.device.data['page selection'] = [
261
# {{{
262
                {
263
                    name: 'MAP',
264
                    objects: [
265
                        {text: 'NAVIGATION MAP'},
266
                        {text: 'TRAFFIC MAP'},
267
                        {text: 'STORMSCOPE'},
268
                        {text: 'WEATHER DATA LINK'},
269
                        {text: 'TAWS-B'},
270
                    ],
271
                },
272
                {
273
                    name: 'WPT',
274
                    objects: [
275
                        {text: 'AIRPORT INFORMATION'},
276
                        {text: 'AIRPORT DIRECTORY'},
277
                        {text: 'DEPARTURE INFORMATION'},
278
                        {text: 'ARRIVAL INFORMATION'},
279
                        {text: 'APPROACH INFORMATION'},
280
                        {text: 'WEATHER INFORMATION'},
281
                        {text: 'INTERSECTION INFORMATION'},
282
                        {text: 'NDB INFORMATION'},
283
                        {text: 'VOR INFORMATION'},
284
                        {text: 'USER WAYPOINT INFORMATION'},
285
                    ],
286
                },
287
                {
288
                    name: 'AUX',
289
                    objects: [
290
                        {text: 'TRIP PLANNING'},
291
                        {text: 'UTILITY'},
292
                        {text: 'GPS STATUS'},
293
                        {text: 'SYSTEM SETUP'},
294
                    ],
295
                },
296
                {
297
                    name: 'FPL',
298
                    objects: [
299
                        {text: 'ACTIVE FLIGHT PLAN'},
300
                        {text: 'WIDE VIEW, NARROW VIEW'},
301
                        {text: 'FLIGHT PLAN CATALOG'},
302
                    ],
303
                },
304
                {
305
                    name: 'PROC',
306
                    objects: [
307
                        {text: 'DEPARTURE LOADING'},
308
                        {text: 'ARRIVAL LOADING'},
309
                        {text: 'APPROACH LOADING'},
310
                    ],
311
                },
312
                {
313
                    name: 'NRST',
314
                    objects: [
315
                        {text: 'NEAREST AIRPORTS'},
316
                        {text: 'NEAREST INTERSECTIONS'},
317
                        {text: 'NEAREST NDB'},
318
                        {text: 'NEAREST VOR'},
319
                        {text: 'NEAREST USER WAYPOINTS'},
320
                        {text: 'NEAREST FREQUENCIES'},
321
                        {text: 'NEAREST AIRSPACES'},
322
                    ],
323
                },
324
# }}}
325
            ];
326
            me.setMFDPages();
327
            me.device.buttons.MENU = me.device.buttons.MapMenu;
328
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
329

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
330
        me.updateNAV({auto:'nav', tune: radios.getNode('nav-tune').getValue()});
331
        me.updateCOMM({auto:'comm', tune: radios.getNode('comm-tune').getValue()});
332
        me.softkeys_inactivity();
333
        me.updateSoftKeys();
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
334
        me.updateNavigationBox();
commit initial
Sébastien MARQUE authored on 2017-03-07
335
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
336
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
337

            
some added comments
Sébastien MARQUE authored on 2017-03-18
338
    colors : {
339
# set of predefined colors {{{
340
        green : [0, 1, 0],
341
        white : [1, 1, 1],
342
        black : [0, 0, 0],
343
        lightblue : [0, 1, 1],
344
        darkblue : [0, 0, 1],
345
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
346
        magenta : [1, 0, 1],
some added comments
Sébastien MARQUE authored on 2017-03-18
347
    },
348
#}}}
349

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
350
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
351
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
352
        if (typeof(h) != 'hash') {
353
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
354
                    caller(0)[0],
355
                    typeof(h),
356
                    caller(1)[0]));
357
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
358
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
359
        var setMethod = func (e, t) {
360
            if (t == 'hide')
361
                me.screenElements[e].hide();
362
            elsif (t == 'show')
363
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
364
            elsif (t == 'rot' or t == 'trans') {
365
                if (! contains(me.screenElements[e], t))
366
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
367
            }
368
            elsif (t == 'clip') {
369
                if (contains(me.clips, e))
370
                    me.screenElements[e].set("clip", me.clips[e]);
371
                else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
372
                    printlog('warn', 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
373
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
374
            elsif (t == 'text') {
375
                if (contains(me.texts, e)) {
376
                    if (contains(me.texts[e], 'alignment'))
377
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
378
                    if (contains(me.texts[e], 'default'))
379
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
380
                    if (contains(me.texts[e], 'color'))
381
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
382
                    if (contains(me.texts[e], 'visible'))
383
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
384
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
385
                else
386
                    printlog('debug', 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
387
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
388
            else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
389
                printlog('warn', 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
390
        };
391
        foreach (var todo; keys(h)) {
392
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
393
            foreach (var id; h[todo]) {
394
                if (! contains(me.screenElements, id)) {
395
                    me.screenElements[id] = me.screen.getElementById(id);
396
                    if (me.screenElements[id] != nil)
397
                        setMethod(id, todo);
398
                    else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
399
                        printlog('warn', 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
400
                }
401
                else
402
                    setMethod(id, todo);
403
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
404
        }
405
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
406
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
407

            
408
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
409
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
410
        PitchScale   : "rect(70,664,370,256)",
411
        SpeedLint1   : "rect(252,226,318,204)",
412
        SpeedTape    : "rect(115,239,455,156)",
413
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
414
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
415
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
416
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
417

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
418
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
419
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
420
        VSIText : {
421
            alignment: "right-bottom", default : num('0'),
422
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
423
        Speed110 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
424
            alignment : 'left-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
425
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
426
        Alt11100 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
427
            alignment:'left-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
428
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
429
        "HDG-text" : {
430
            default: '---°'
431
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
432
        'nav1-standby-freq' : {
433
            color: [0, 1, 1],
434
        },
435
        'nav1-id' : {
436
            default: ''
437
        },
438
        'nav2-id' : {
439
            default: ''
440
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
441
        'CDI-GPS-ANN-text' : {
442
            visible : 0
443
        },
444
        'CDI-GPS-XTK-text' : {
445
            visible : 0
446
        },
447
        'CDI-SRC-text' : {
448
            visible : 0
449
        },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
450
        'BARO-text' : {
451
            alignment : 'left-bottom',
452
        }
some added comments
Sébastien MARQUE authored on 2017-03-18
453
#        'TAS-text' : {
454
#            alignment : 'right-bottom',
455
#        },
456
#        'GSPD-text' : {
457
#            alignment : 'right-bottom',
458
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
459
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
460
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
461

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
462
    softkeys_inactivity : func {
463
# automagically back to previous level after some delay {{{
464
        me.timers2.softkeys_inactivity = maketimer (
465
            me.softkeys_inactivity_delay,
466
            func {
467
                pop(me.device.softkeys.path);
468
                me.updateSoftKeys();
469
            }, me);
470
        me.timers2.softkeys_inactivity.singleShot = 1;
471
    },
472
#}}}
473

            
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
474
    setSoftKeyColor : func (n, active, alert = 0) {
475
# set colors for active softkeys {{{
476
        var sftk = sprintf('SoftKey%02i-', n);
477
        if (active) {
478
            var bg = alert ? 1 : 0.5;
479
            me.screenElements[sftk ~ 'bg']
480
                .setColorFill(bg,bg,bg);
481
            me.screenElements[sftk ~ 'text']
482
                .setColor(0,0,0);
483
        }
484
        else {
485
            me.screenElements[sftk ~ 'bg']
486
                .setColorFill(0,0,0);
487
            me.screenElements[sftk ~ 'text']
488
                .setColor(1,1,1);
489
        }
490
    },
491
#}}}
492

            
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
493
    updateNavigationBox : func {
494
# update Navigation Box on MFD and PFD header {{{
495
        var route = me.device.map.layers.route;
496
        var fpSize = size(route.flightPlan);
497
        var navbox = {
498
            DTK: func {
499
                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
500
                if (dtk == nil)
501
                    return '---°';
502
                else
503
                    return sprintf('%03i°', dtk);
504
            },
505
            ETE: func {
506
                if (fpSize == 0) return '--:--';
507
                var eteSeconds = getprop('/autopilot/route-manager/ete');
508
                var eteHours = math.floor(eteSeconds / 3600);
509
                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
510
                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
511
            },
512
            DIS: func {
513
                if (fpSize == 0) return '---NM';
514
                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
515
                return sprintf(dist >= 100 ? '%i' : '%.1f', dist);
516
            },
517
            LEG: func {
518
                if (fpSize == 0) return '';
519
                var wp = route.flightPlan[route.currentLeg.index];
520
                return wp[0].name ~ ' > ' ~ wp[1].name;
521
            },
522
            GS : func return sprintf('%iKT', getprop('/velocities/groundspeed-kt')),
523
            TRK: func return sprintf('%03i°', getprop('/orientation/track-deg')),
524
            TAS: func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')),
525
            BRG: func return '---°',
526
            END: func return '---NM',
527
            ESA: func return '-----',
528
            ETA: func return '--:--',
529
            FOB: func return '---lbs',
530
            ISA: func return '-----',
531
            LDG: func return '--:--',
532
            MSA: func return '----ft',
533
            TKE: func return '---°',
534
            VSR: func return '----',
535
            XTK: func return '---NM',
536
        };
537
        if (me.device.role == 'MFD') {
538
            for (var i=1; i<=4; i+=1)
539
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
540
                    .setText(
541
                        navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].get('text')]()
542
                    );
543
            settimer(func me.updateNavigationBox(), 0.6);
544
        }
545
        else { # PFD
546
            me.screenElements['ETE-text'].setText(navbox.ETE());
547
            me.screenElements['DIS-text'].setText(navbox.DIS());
548
            me.screenElements['LEG-text'].setText(navbox.LEG());
549
            settimer(func me.updateNavigationBox(), 0.3);
550
        }
551
    },
552
#}}}
553

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
554
    updateSoftKeys : func {
555
# update SoftKeys boxes {{{
556
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
557
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
558
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
559
                .setText('ALERTS');
560
            if (size(me.device.softkeys.path) != 0)
561
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
562
                    .setText('BACK');
563
        }
564

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
565
        var path = keyMap[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
566
        var pathid = '';
567
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
568
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
569
            pathid ~= p;
570
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
571

            
572
        # feeding with empty menus the first boxes
573
        var start = (contains(path, 'first')) ? path.first : 0;
574
        for (var k = 0; k < start; k+=1) {
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
575
            var sftk = sprintf("SoftKey%02i-", k);
576
            me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
577
                .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
578
            me.screenElements[sftk ~ 'bg']
579
                .setColorFill(0,0,0);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
580
        }
581
        # filling with the content the next boxes
582
        forindex (var k; path.texts) {
583
            var i = k + start;
584
            me.screenElements[sprintf("SoftKey%02i-text", i)]
585
                .setText(path.texts[k]);
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
586
            me.setSoftKeyColor(i,
587
                    contains(me.device.softkeys.colored, pathid ~ path.texts[k]));
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
588
        }
589
        # feeding the last boxes with empty string
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
590
        var end = (me.device.role == 'PFD') ? 10 : 12;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
591
        if (size(path.texts) + start < end) {
592
            start = size(path.texts) + start;
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
593
            for (var k = start; k < end; k += 1) {
594
                var sftk = sprintf("SoftKey%02i-", k);
595
                me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
596
                    .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
597
                me.screenElements[sftk ~ 'bg']
598
                    .setColorFill(0,0,0);
599
            }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
600
        }
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
601

            
602
        if (size(me.device.softkeys.path))
603
            me.timers2.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
604
        else
605
            me.timers2.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
606
    },
607
#}}}
608

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
609
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
610
#{{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
611
        var pitch = data.pitch;
612
        var roll = data.roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
613
        if (pitch > 80)
614
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
615
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
616
            pitch = -80;
617
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
618
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
619
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
620
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
621
        me.screenElements.bankPointer
622
            .setRotation(-roll * D2R);
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
623
        me.screenElements['SlipSkid']
624
            .setTranslation(getprop("/instrumentation/slip-skid-ball/indicated-slip-skid") * 10, 0);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
625
        settimer(func me.updateAI(), 0.1);
AI disponible
Sébastien MARQUE authored on 2017-03-10
626
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
627
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
628

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
629
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
630
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
631
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
632
        me.screenElements.VSIText
633
            .setText(num(math.round(vsi, 10)));
634
        if (vsi > 4500)
635
            vsi = 4500;
636
        elsif (vsi < -4500)
637
            vsi = -4500;
638
        me.screenElements.VSI
639
            .setTranslation(0, vsi * -0.03465);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
640
        settimer(func me.updateVSI(), 0.1);
animation VSI
Sébastien MARQUE authored on 2017-03-10
641
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
642
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
643

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
644
    updateIAS: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
645
# animates the IAS lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
646
        var ias = data.ias;
animation IAS
Sébastien MARQUE authored on 2017-03-10
647
        if (ias >= 10)
648
            me.screenElements.Speed110
649
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
650
        else
651
            me.screenElements.Speed110
652
                .setText('');
653
        me.screenElements.SpeedLint1
654
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
655
        me.screenElements.SpeedTape
656
            .setTranslation(0,ias * 5.711);
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
657
        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
658
            me._ias_already_exceeded = 1;
659
            me.screenElements['IAS-bg']
660
                .setColorFill(1,0,0);
661
        }
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
662
        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
663
            me._ias_already_exceeded = 0;
664
            me.screenElements['IAS-bg']
665
                .setColorFill(0,0,0);
666
        }
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
667
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
668
            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) < 30)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
669
                me.screenElements['IAS-' ~ v]
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
670
                    .setTranslation(0, (ias - data[v]) * 5.711)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
671
                    .show();
672
            else
673
                me.screenElements['IAS-' ~ v]
674
                    .hide();
675
        }
676

            
trends animation
Sébastien MARQUE authored on 2017-03-13
677
        var now = systime();
678
        # estimated speed in 6s
679
        var Sy = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
680
        if (abs(Sy) > 30)
681
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
682
        me.screenElements['Airspeed-Trend-Indicator']
683
            .setScale(1,Sy)
684
            .setTranslation(0, -284.5 * (Sy - 1));
685
        me._last_ias_kt = ias;
686
        me._last_ias_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
687
        settimer(func me.updateIAS(), 0.1);
animation IAS
Sébastien MARQUE authored on 2017-03-10
688
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
689
    _last_ias_kt : 0,
690
    _last_ias_s : systime(),
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
691
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
692
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
693

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
694
    updateTAS: func {
695
# updates the True Airspeed and GroundSpeed indicators {{{
696
        me.screenElements['TAS-text']
697
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
698
        me.screenElements['GSPD-text']
699
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
700
        settimer(func me.updateTAS(), 0.5);
701
    },
702
#}}}
703

            
704
    updateALT: func () {
705
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
706
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
707
        if (alt < 0)
708
            me.screenElements.Alt11100
709
                .setText(sprintf("% 3i",math.ceil(alt/100)));
710
        elsif (alt < 100)
711
            me.screenElements.Alt11100
712
                .setText('');
713
        else
714
            me.screenElements.Alt11100
715
                .setText(sprintf("% 3i",math.floor(alt/100)));
716
        me.screenElements.AltLint00011
717
            .setTranslation(0,math.fmod(alt,100) * 1.24);
718

            
719
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
720
        if (alt> -1000 and alt< 1000000) {
721
            var Offset10 = 0;
722
            var Offset100 = 0;
723
            var Offset1000 = 0;
724
            if (alt< 0) {
725
                var Ne = 1;
726
                var alt= -alt;
727
            }
728
            else
729
                var Ne = 0;
730

            
731
            var Alt10       = math.mod(alt,100);
732
            var Alt100      = int(math.mod(alt/100,10));
733
            var Alt1000     = int(math.mod(alt/1000,10));
734
            var Alt10000    = int(math.mod(alt/10000,10));
735
            var Alt20       = math.mod(Alt10,20)/20;
736
            if (Alt10 >= 80)
737
                var Alt100 += Alt20;
738

            
739
            if (Alt10 >= 80 and Alt100 >= 9)
740
                var Alt1000 += Alt20;
741

            
742
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
743
                var Alt10000 += Alt20;
744

            
745
            if (alt> 100)
746
                var Offset10 = 100;
747

            
748
            if (alt> 1000)
749
                var Offset100 = 10;
750

            
751
            if (alt> 10000)
752
                var Offset1000 = 10;
753

            
754
            if (!Ne) {
755
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
756
                var altCentral = (int(alt/100)*100);
757
            }
758
            elsif (Ne) {
759
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
760
                var altCentral = -(int(alt/100)*100);
761
            }
762
            me.screenElements["AltBigC"].setText("");
763
            me.screenElements["AltSmallC"].setText("");
764
            for (var place = 1; place <= 6; place += 1) {
765
                var altUP = altCentral + (place*100);
766
                var offset = -30.078;
767
                if (altUP < 0) {
768
                    var altUP = -altUP;
769
                    var prefix = "-";
770
                    var offset += 15.039;
771
                }
772
                else
773
                    var prefix = "";
774

            
775
                if (altUP == 0) {
776
                    var AltBigUP    = "";
777
                    var AltSmallUP  = "0";
778

            
779
                }
780
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
781
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
782
                    var AltSmallUP  = "";
783
                }
784
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
785
                    var AltBigUP    = "";
786
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
787
                    var offset = -30.078;
788
                }
789
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
790
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
791
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
792
                    var offset += 15.039;
793
                }
794
                else {
795
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
796
                    var mod = int(math.mod(altUP,1000));
797
                    var AltSmallUP  = sprintf("%1d", mod);
798
                    var offset += 30.078;
799
                }
800

            
801
                me.screenElements["AltBigU"~place].setText(AltBigUP);
802
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
803
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
804
                var altDOWN = altCentral - (place*100);
805
                var offset = -30.078;
806
                if (altDOWN < 0) {
807
                    var altDOWN = -altDOWN;
808
                    var prefix = "-";
809
                    var offset += 15.039;
810
                }
811
                else
812
                    var prefix = "";
813

            
814
                if (altDOWN == 0) {
815
                    var AltBigDOWN  = "";
816
                    var AltSmallDOWN    = "0";
817
                }
818
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
819
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
820
                    var AltSmallDOWN    = "";
821
                }
822
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
823
                    var AltBigDOWN  = "";
824
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
825
                    var offset = -30.078;
826
                }
827
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
828
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
829
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
830
                    var offset += 15.039;
831
                }
832
                else {
833
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
834
                    var mod = int(math.mod(altDOWN,1000));
835
                    var AltSmallDOWN    = sprintf("%1d", mod);
836
                    var offset += 30.078;
837
                }
838
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
839
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
840
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
841
            }
842
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
843
        me.updateSelectedALT();
trends animation
Sébastien MARQUE authored on 2017-03-13
844
        var now = systime();
845
        # altitude in 6s
846
        var Sy = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
847
        if (abs(Sy) > 15)
848
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
849
        me.screenElements['Altitude-Trend-Indicator']
850
            .setScale(1,Sy)
851
            .setTranslation(0, -284.5 * (Sy - 1));
852
        me._last_alt_ft = alt;
853
        me._last_alt_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
854
        settimer(func me.updateALT(), 0.2);
animation ALT
Sébastien MARQUE authored on 2017-03-11
855
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
856
    _last_alt_ft : 0,
857
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
858
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
859

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
860
    updateBARO : func () {
861
# update BARO widget {{{
862
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
863
        me.screenElements['BARO-text']
864
            .setText(sprintf(fmt,
865
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
866
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
867
                );
868
    },
869
    _baro_unit : 'inhg',
870
#}}}
871

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
872
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
873
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
874
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
875
        me.screenElements.Rose
876
            .setRotation(-hdg * D2R);
877
        me.screenElements['HDG-text']
878
            .setText(sprintf("%03u°", hdg));
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
879
        settimer(func me.updateHSI(), 0.1);
animation HSI
Sébastien MARQUE authored on 2017-03-11
880
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
881
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
882

            
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
883
    updateHDG : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
884
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
885
        if (me.device.role == 'MFD')
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
886
            return;
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
887
        var hdg = getprop('/instrumentation/zkv1000/afcs/heading-bug-deg');
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
888
        me.screenElements['Heading-bug']
889
            .setRotation(hdg * D2R);
890
        me.screenElements['SelectedHDG-bg']
891
            .show();
892
        me.screenElements['SelectedHDG-bgtext']
893
            .show();
894
        me.screenElements['SelectedHDG-text']
895
            .setText(sprintf('%03d°%s', hdg, ''))
896
            .show();
897
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
898
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
899
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
900

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
901
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
902
# TODO: update display for NAV/GPS/BRG courses {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
903
        if (me.device.role == 'MFD')
anime CRS
Sébastien MARQUE authored on 2017-03-13
904
            return;
adds CDI
Sébastien MARQUE authored on 2017-03-18
905
        var source = getprop('/instrumentation/zkv1000/cdi/source');
906
        if (source == 'OFF')
907
            return;
908
        var crs = getprop('/instrumentation/zkv1000/cdi/course');
909
        if (crs == nil)
910
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
911
        me.screenElements['SelectedCRS-bg']
912
            .show();
913
        me.screenElements['SelectedCRS-bgtext']
914
            .show();
915
        me.screenElements['SelectedCRS-text']
916
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
917
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
918
            .show();
919
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
920
    },
921
#}}}
922

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
923
    updateSelectedALT : func {
924
# animation for altitude section, called via updatedALT {{{
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
925
        if (! me.screenElements['SelectedALT'].getVisible())
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
926
            return;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
927
        var selected_alt = getprop('/instrumentation/zkv1000/afcs/selected-alt-ft');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
928
        var delta_alt = data.alt - selected_alt;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
929
        if (abs(delta_alt) > 300)
930
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
931
        me.screenElements['SelectedALT-symbol']
932
            .setVisible(abs(delta_alt) > 100);
933
        me.screenElements['SelectedALT-bg']
934
            .setVisible(abs(delta_alt) > 100);
935
        me.screenElements['SelectedALT-text']
936
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
937
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
938
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
939
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
940
    },
941
#}}}
942

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
943
    updateCDI : func {
944
# animation for CDI {{{
945
        var source = getprop('/instrumentation/zkv1000/cdi/source');
946
        if (source == 'OFF') {
947
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
948
                foreach (var t; ['pointer', 'CDI'])
949
                    me.screenElements[s ~ '-' ~ t].hide();
950
            me.screenElements['CDI-GPS-ANN-text'].hide();
951
            me.screenElements['CDI-GPS-XTK-text'].hide();
952
            me.screenElements['CDI-SRC-text'].hide();
953
            me.screenElements['CDI'].hide();
954
        }
955
        else {
956
            var course = getprop('/instrumentation/zkv1000/cdi/course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
957
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
958
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
959
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
960
                .show();
961
            me.screenElements['GPS-CTI']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
962
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
963
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
964
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
965
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
966
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
967
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
968
                me.screenElements[s ~ '-pointer']
969
                    .setRotation(rot)
970
                    .setVisible(source == s);
971
                me.screenElements[s ~ '-CDI']
972
                    .setVisible(source == s);
973
                foreach (var f; ['FROM', 'TO'])
974
                    me.screenElements[s ~ '-' ~ f]
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
975
                        .setVisible(s == source and getprop('/instrumentation/zkv1000/cdi/' ~ f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
976
                me.screenElements['CDI-SRC-text']
977
                    .setText(source)
978
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
979
                    .show();
980
            }
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
981
            var deflection = getprop('/instrumentation/zkv1000/cdi/course-deflection');
982
            if (left(source, 3) == 'NAV')
983
                var scale = deflection / 4;
984
            else { # GPS
985
                # TODO: deviation depending of the flight phase
986
                # for now fixed 1 dot = 1 nm course error
987
                var abs_deflection = abs(deflection);
988
                me.screenElements['CDI-GPS-XTK-text']
989
                    .setText(sprintf('XTK %iNM', abs_deflection))
990
                    .setVisible(abs_deflection > 2.4);
991
                var scale = deflection / 2;
992
            }
993
            scale = (abs(scale) > 1.2) ? 1.2 : scale;
994
            me.screenElements[source ~ '-CDI']
995
                .setTranslation(65 * scale, 0);
996
            settimer(func me.updateCDI(), 0.3);
adds CDI
Sébastien MARQUE authored on 2017-03-18
997
        }
998
    },
999
#}}}
1000

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1001
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1002
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1003
        # arg[0]._r = <comm|nav>
1004
        if (contains(arg[0], "active")) {
1005
            if (arg[0]['active'] == 'none') {
1006
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1007
                    .setColor(1,1,1);
1008
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1009
                    .setColor(1,1,1);
1010
            }
1011
            else {
1012
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1013
                    .setColor(0,1,0);
1014
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1015
                    .setColor(1,1,1);
1016
            }
1017
        }
1018
        if (contains(arg[0], 'tune')) {
1019
            # n = 0 -> NAV1/COMM1
1020
            # n = 1 -> NAV1/COMM2
1021
            me.screenElements[arg[0]._r ~ '-freq-switch']
1022
                .setTranslation(0, arg[0].tune * 25);
1023
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1024
                .setColor(0,1,1);
1025
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1026
                .setColor(1,1,1);
1027
        }
1028
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1029
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1030
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1031
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1032
                .setText(sprintf(fmt, getprop('/instrumentation/'
1033
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1034
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1035
                .setText(sprintf(fmt, getprop('/instrumentation/'
1036
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1037
        }
1038
        if (contains(arg[0], 'set')) {
1039
            # positionne la valeur modifiée, les listeners "trigguent" en permanence ces propriétés, donc exit
1040
            var n = getprop('/instrumentation/zkv1000/radios/' ~ arg[0]._r ~ '-tune');
1041
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1042
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1043
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1044
        }
1045
        if (contains(arg[0], 'auto')) {
1046
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1047
            var radio = arg[0].auto;
1048
            me._updateRadio({refresh: 1, _r: radio});
1049
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1050
            settimer(func me._updateRadio({auto: radio}), 2);
1051
        }
1052
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1053
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1054

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1055
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1056
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1057
        # made active via menu
1058
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1059
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1060
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1061
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1062
                me.screenElements['nav1-id']
1063
                    .setColor(1,1,1);
1064
                me.screenElements['nav2-id']
1065
                    .setColor(1,1,1);
1066
                me.screenElements['NAV1-pointer']
1067
                    .hide();
1068
                me.screenElements['NAV2-pointer']
1069
                    .hide();
1070
            }
1071
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1072
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1073
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1074
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1075
                    .setColor(0,1,0);
1076
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1077
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1078
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1079
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1080
#                me.screenElements['HDI']
1081
#                    .setRotation();
1082
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1083
#                    .hide();
1084
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1085
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1086
#                        .hide();
1087
            }
1088
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1089
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1090
            # 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
1091
            if (arg[0].val == nil)
1092
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1093
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1094
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1095
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1096
        else {
1097
            arg[0]._r = 'nav';
1098
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1099
        }
1100
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1101
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1102

            
1103
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1104
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1105
        arg[0]._r = 'comm';
1106
        me._updateRadio(arg[0]);
1107
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1108
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1109

            
1110
    updateTIME : func {
1111
# updates the displayed time botoom left {{{
1112
        me.screenElements['TIME-text']
1113
            .setText(getprop('/sim/time/gmt-string'));
1114
        settimer(func me.updateTIME(), 1);
1115
    },
1116
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1117

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1118
    updateXPDR : func {
1119
# updates transponder display {{{
1120
        for (var d = 0; d < 4; d+=1)
1121
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1122
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
1123
        var tuning = getprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1124
        var fms = getprop('/instrumentation/zkv1000/radios/xpdr-tuning-fms-method');
1125
        for (var d = 0; d < 4; d+=1)
1126
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1127
                .setColor(1,1,1);
1128
        if (tuning != nil) {
1129
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1130
                .setColor(0,1,1);
1131
            if (fms)
1132
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1133
                    .setColor(0,1,1);
1134
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1135
        else {
1136
            if (getprop('/instrumentation/transponder/ident'))
1137
                var mode = 'IDENT';
1138
            else
1139
                var mode = getprop('/instrumentation/zkv1000/radio/xpdr-mode');
1140
            var wow = getprop('/gear/gear/wow');
1141
            if (! wow and mode != 'STBY')
1142
                var color = [0, 1, 0];
1143
            else
1144
                var color = [1, 1, 1];
1145
            for (var d = 0; d < 4; d+=1)
1146
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1147
                    .setColor(color);
1148
            me.screenElements['XPDR-MODE-text']
1149
                .setColor(color)
1150
                .setText(mode);
1151
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1152
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1153
#}}}
1154

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1155
    updateOAT : func {
1156
# update OAT display on normal and reversionnary modes (every 3s) {{{
1157
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1158
        me.screenElements['OAT-text']
1159
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1160
        settimer(func me.updateOAT(), 3);
1161
    },
1162
    _oat_unit : 'c',
1163
#}}}
1164

            
1165
    updateWindData : func {
1166
# update the window text and arrows for OPTN1/2 {{{
1167
        if (me._winddata_optn == 0)
1168
            return;
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1169
        if (data.ias < 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1170
            me.screenElements['WindData-NODATA']
1171
                .hide();
1172
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1173
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1174
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1175
            if (me._winddata_optn == 1) {
1176
                me.screenElements['WindData-OPTN1-HDG']
1177
                    .setRotation((alpha + 180) * D2R)
1178
                    .show();
1179
                me.screenElements['WindData-OPTN1-HDG-text']
1180
                    .setText(sprintf("%03i°", wind_hdg))
1181
                    .show();
1182
                me.screenElements['WindData-OPTN1-SPD-text']
1183
                    .setText(int(wind_spd) ~ 'KT')
1184
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1185
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1186
            else { # me._winddata_optn == 2
1187
                alpha *= D2R;
1188
                var Vt = wind_spd * math.sin(alpha);
1189
                var Ve = wind_spd * math.cos(alpha);
1190
                if (Vt != 0) {
1191
                    me.screenElements['WindData-OPTN2-crosswind-text']
1192
                        .setText(sprintf('%i', abs(Vt)))
1193
                        .show();
1194
                    me.screenElements['WindData-OPTN2-crosswind']
1195
                        .setScale(-abs(Vt)/Vt, 1)
1196
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1197
                        .show();
1198
                }
1199
                if (Ve != 0) {
1200
                    me.screenElements['WindData-OPTN2-headwind-text']
1201
                        .setText(sprintf('%i', abs(Ve)))
1202
                        .show();
1203
                    me.screenElements['WindData-OPTN2-headwind']
1204
                        .setScale(1, abs(Ve)/Ve)
1205
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1206
                        .show();
1207
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1208
            }
1209
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1210
        else {
1211
            foreach (var e; [
1212
                    'WindData-OPTN1-HDG',
1213
                    'WindData-OPTN1-HDG-text',
1214
                    'WindData-OPTN1-SPD-text',
1215
                    'WindData-OPTN2-crosswind-text',
1216
                    'WindData-OPTN2-crosswind',
1217
                    'WindData-OPTN2-headwind-text',
1218
                    'WindData-OPTN2-headwind'
1219
            ])
1220
                me.screenElements[e].hide();
1221
            me.screenElements['WindData-NODATA'].show();
1222
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1223
        settimer(func me.updateWindData(), 0.5);
1224
    },
1225
    _winddata_optn : 0,
1226
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1227

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1228
    updateAOA : func {
1229
# update Angle Of Attack {{{
1230
        if (me.device.data.aoa == 0)
1231
            return;
1232
        var color = [1,1,1];
1233
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1234
        me.screenElements['AOA-text']
1235
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1236
        if (norm > 1) norm = 1;
1237
        if (norm > 0.9)
1238
            color = [1,0,0];
1239
        elsif (norm > 0.7)
1240
            color = [1,1,0];
1241
        elsif (norm < 0) {
1242
            norm = 0;
1243
            color = [1,0,0];
1244
        }
1245
        me.screenElements['AOA-needle']
1246
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1247
            .setColorFill(color);
1248
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1249
            .setColor(color);
1250
        settimer(func me.updateAOA(), 0.1);
1251
    },
1252
# }}}
1253

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

            
1259
            var dev = radios.getNode(source).getValue();
1260
            var el  = 'BRG' ~ brg;
1261
            if (dev != 'OFF') {
1262
                var info = {
1263
                    pointer : nil,
1264
                    id : 'NO DATA',
1265
                    hdg : nil,
1266
                    dst : '--.-NM'
1267
                };
1268
                if (left(dev, 3) == 'NAV') {
1269
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1270
                    if (info.pointer) {
1271
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1272
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1273
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1274
                    }
1275
                }
1276
                elsif (dev == 'GPS') {
1277
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1278
                    if (info.pointer) {
1279
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1280
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1281
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1282
                    }
1283
                }
1284
                else { # there are 2 available ADF in FG, but instrument manage only 1
1285
                    info.pointer = getprop('/instrumentation/adf/in-range');
1286
                    if (info.pointer) {
1287
                        info.id  = getprop('/instrumentation/adf/ident');
1288
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1289
                    }
1290
                }
1291

            
1292
                if (info.pointer)
1293
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1294
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1295
                        .show();
1296
                else
1297
                    me.screenElements[el ~ '-pointer']
1298
                        .hide();
1299
                me.screenElements[el ~ '-SRC-text']
1300
                    .setText(dev);
1301
                me.screenElements[el ~ '-DST-text']
1302
                    .setText(info.dst);
1303
                me.screenElements[el ~ '-WPID-text']
1304
                    .setText(info.id);
1305
                me.screenElements['BRG' ~ brg]
1306
                    .show();
1307
            }
1308
            else {
1309
                me.screenElements['BRG' ~ brg]
1310
                    .hide();
1311
            }
1312
        }
colorize BRG1/2 when needed,...
Sébastien MARQUE authored on 2017-03-21
1313
        settimer(func me.updateBRG(), 0.5);
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1314
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1315
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1316

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1317
    updateOMI : func {
1318
# display marker baecon Outer, Middle, Inner {{{
1319
        var marker = nil;
1320
        foreach (var m; ['outer', 'middle', 'inner'])
1321
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1322
                marker = m;
1323
                me.screenElements['OMI']
1324
                    .show();
1325
                break;
1326
            }
1327
        if (marker != nil) {
1328
            me.screenElements['MarkerText']
1329
                .setText(me._omi_data[marker].t)
1330
                .show();
1331
            me.screenElements['MarkerBG']
1332
                .setColorFill(me._omi_data[marker].bg)
1333
                .show();
1334
        }
1335
        else
1336
            me.screenElements['OMI']
1337
                .hide();
1338
        settimer(func me.updateOMI(), 1);
1339
    },
1340
    _omi_data : {
1341
        'outer':  {t: 'O', bg: [0,1,1]},
1342
        'middle': {t: 'M', bg: [1,1,1]},
1343
        'inner':  {t: 'I', bg: [1,1,0]},
1344
    },
1345
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1346
};