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

            
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
493
    updateNavigationBox : func (getDataFields = 0) {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
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
        };
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
537
        if (getDataFields)
538
            return keys(navbox);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
539
        if (me.device.role == 'MFD') {
540
            for (var i=1; i<=4; i+=1)
541
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
542
                    .setText(
543
                        navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].get('text')]()
544
                    );
545
            settimer(func me.updateNavigationBox(), 0.6);
546
        }
547
        else { # PFD
548
            me.screenElements['ETE-text'].setText(navbox.ETE());
549
            me.screenElements['DIS-text'].setText(navbox.DIS());
550
            me.screenElements['LEG-text'].setText(navbox.LEG());
551
            settimer(func me.updateNavigationBox(), 0.3);
552
        }
553
    },
554
#}}}
555

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
747
            if (alt> 100)
748
                var Offset10 = 100;
749

            
750
            if (alt> 1000)
751
                var Offset100 = 10;
752

            
753
            if (alt> 10000)
754
                var Offset1000 = 10;
755

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

            
777
                if (altUP == 0) {
778
                    var AltBigUP    = "";
779
                    var AltSmallUP  = "0";
780

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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