zkv1000 / Nasal / display.nas /
Newer Older
1292 lines | 48.934kb
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',
add TCAS
Sébastien MARQUE authored on 2017-12-21
109
                    'Traffic',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
110
# }}}
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
111
                );
112
                append(groups.clip,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
113
# {{{
animation IAS
Sébastien MARQUE authored on 2017-03-10
114
                    'SpeedLint1',
animation ALT
Sébastien MARQUE authored on 2017-03-11
115
                    'SpeedTape',
116
                    'LintAlt',
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
117
                    'AltLint00011',
118
                    'PitchScale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
119
# }}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
120
                );
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
121
                append(groups.text,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
122
# {{{
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
123
                    'SelectedALT-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
124
                    'TAS-text',
125
                    'GSPD-text',
anime time display
Sébastien MARQUE authored on 2017-03-13
126
                    'TIME-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
127
                    'OAT-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
128
                    'VSIText',
129
                    'Speed110',
130
                    'Alt11100',
131
                    'HDG-text',
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
132
                    'BARO-text',
adds CDI
Sébastien MARQUE authored on 2017-03-18
133
                    'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
134
                    'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
135
                    'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
136
                    'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
137
                    'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
adds transponder
Sébastien MARQUE authored on 2017-03-17
138
                    '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
139
                    'ETE', 'ETE-text', 'DIS', 'DIS-text', 'LEG-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
140
                    'AltBigC', 'AltSmallC'
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
141
# }}}
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
142
                );
143
                for (var place = 1; place <= 6; place +=1) {
144
                    append(groups.text,
145
                        'AltBigU' ~ place,
146
                        'AltSmallU' ~ place,
147
                        'AltBigD' ~ place,
148
                        'AltSmallD' ~ place
149
                    );
150
                }
relocate SVG files in Models...
Sébastien MARQUE authored on 2017-12-31
151
                canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/PFD.svg');
animation ALT
Sébastien MARQUE authored on 2017-03-11
152
            }
adds EIS
Sébastien MARQUE authored on 2017-03-18
153
            else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
154
                var eis_file = eis.getValue('type');
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
155
                if (eis_file == nil)
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
156
                    eis_file = eis.getValue('file');
EIS now really specific to a...
Sébastien MARQUE authored on 2017-04-20
157

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

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

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

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

            
relocate SVG files in Models...
Sébastien MARQUE authored on 2017-12-31
189
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/softkeys.svg');
190
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/header-nav-comm.svg');
animation ALT
Sébastien MARQUE authored on 2017-03-11
191

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

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

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

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

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

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
239
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
240
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
241
        if (me.device.role == 'PFD') {
242
            me.updateAI();
243
            me.updateVSI();
244
            me.updateIAS();
245
            me.updateALT();
246
            me.updateHSI();
247
            me.updateTIME();
248
            me.updateOAT();
249
            me.updateTAS();
250
            me.updateBRG();
251
            me.updateXPDR();
252
            me.updateBARO();
253
            me.updateOMI();
254
            me.timerTrigger();
255
            me.screen.show();
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
256
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
257
        }
258
        else {
259
            me.updateEIS();
260
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
261
            me['page selected'] = 0;
262
            me.setMFDPages();
263
            me.device.buttons.MENU = me.device.buttons.MapMenu;
264
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
265

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
266
        me.updateNAV({auto:'nav', tune: radios.getNode('nav-tune').getValue()});
267
        me.updateCOMM({auto:'comm', tune: radios.getNode('comm-tune').getValue()});
268
        me.softkeys_inactivity();
269
        me.updateSoftKeys();
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
270
        me.updateNavigationBox();
commit initial
Sébastien MARQUE authored on 2017-03-07
271
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
272
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
273

            
some added comments
Sébastien MARQUE authored on 2017-03-18
274
    colors : {
275
# set of predefined colors {{{
276
        green : [0, 1, 0],
277
        white : [1, 1, 1],
278
        black : [0, 0, 0],
279
        lightblue : [0, 1, 1],
280
        darkblue : [0, 0, 1],
281
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
282
        magenta : [1, 0, 1],
some added comments
Sébastien MARQUE authored on 2017-03-18
283
    },
284
#}}}
285

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
286
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
287
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
288
        if (typeof(h) != 'hash') {
289
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
290
                    caller(0)[0],
291
                    typeof(h),
292
                    caller(1)[0]));
293
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
294
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
295
        var setMethod = func (e, t) {
296
            if (t == 'hide')
297
                me.screenElements[e].hide();
298
            elsif (t == 'show')
299
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
300
            elsif (t == 'rot' or t == 'trans') {
301
                if (! contains(me.screenElements[e], t))
302
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
303
            }
304
            elsif (t == 'clip') {
305
                if (contains(me.clips, e))
306
                    me.screenElements[e].set("clip", me.clips[e]);
307
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
308
                    logprint(LOG_WARN, 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
309
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
310
            elsif (t == 'text') {
311
                if (contains(me.texts, e)) {
312
                    if (contains(me.texts[e], 'alignment'))
313
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
314
                    if (contains(me.texts[e], 'default'))
315
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
316
                    if (contains(me.texts[e], 'color'))
317
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
318
                    if (contains(me.texts[e], 'visible'))
319
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
320
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
321
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
322
                    logprint(LOG_DEBUG, 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
323
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
324
            else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
325
                logprint(LOG_WARN, 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
326
        };
327
        foreach (var todo; keys(h)) {
328
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
329
            foreach (var id; h[todo]) {
330
                if (! contains(me.screenElements, id)) {
331
                    me.screenElements[id] = me.screen.getElementById(id);
332
                    if (me.screenElements[id] != nil)
333
                        setMethod(id, todo);
334
                    else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
335
                        logprint(LOG_WARN, 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
336
                }
337
                else
338
                    setMethod(id, todo);
339
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
340
        }
341
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
342
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
343

            
344
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
345
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
346
        PitchScale   : "rect(70,664,370,256)",
347
        SpeedLint1   : "rect(252,226,318,204)",
348
        SpeedTape    : "rect(115,239,455,156)",
349
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
350
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
351
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
352
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
353

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
354
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
355
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
356
        VSIText : {
357
            alignment: "right-bottom", default : num('0'),
358
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
359
        Speed110 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
360
            alignment : 'left-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
361
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
362
        Alt11100 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
363
            alignment:'left-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
364
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
365
        "HDG-text" : {
366
            default: '---°'
367
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
368
        'nav1-standby-freq' : {
369
            color: [0, 1, 1],
370
        },
371
        'nav1-id' : {
372
            default: ''
373
        },
374
        'nav2-id' : {
375
            default: ''
376
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
377
        'CDI-GPS-ANN-text' : {
378
            visible : 0
379
        },
380
        'CDI-GPS-XTK-text' : {
381
            visible : 0
382
        },
383
        'CDI-SRC-text' : {
384
            visible : 0
385
        },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
386
        'BARO-text' : {
387
            alignment : 'left-bottom',
388
        }
some added comments
Sébastien MARQUE authored on 2017-03-18
389
#        'TAS-text' : {
390
#            alignment : 'right-bottom',
391
#        },
392
#        'GSPD-text' : {
393
#            alignment : 'right-bottom',
394
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
395
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
396
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
397

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
398
    softkeys_inactivity : func {
399
# automagically back to previous level after some delay {{{
400
        me.timers2.softkeys_inactivity = maketimer (
401
            me.softkeys_inactivity_delay,
402
            func {
403
                pop(me.device.softkeys.path);
404
                me.updateSoftKeys();
405
            }, me);
406
        me.timers2.softkeys_inactivity.singleShot = 1;
407
    },
408
#}}}
409

            
softkey is implemented by de...
Sébastien MARQUE authored on 2017-12-21
410
    setSoftKeyColor : func (n, active, implemented = 1, alert = 0) {
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
411
# set colors for active softkeys {{{
412
        var sftk = sprintf('SoftKey%02i-', n);
413
        if (active) {
414
            var bg = alert ? 1 : 0.5;
415
            me.screenElements[sftk ~ 'bg']
416
                .setColorFill(bg,bg,bg);
417
            me.screenElements[sftk ~ 'text']
418
                .setColor(0,0,0);
419
        }
420
        else {
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
421
            var tc = implemented ? 1 : 0.5;
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
422
            me.screenElements[sftk ~ 'bg']
423
                .setColorFill(0,0,0);
424
            me.screenElements[sftk ~ 'text']
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
425
                .setColor(tc,tc,tc);
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
426
        }
427
    },
428
#}}}
429

            
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
430
    updateNavigationBox : func (getDataFields = 0) {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
431
# update Navigation Box on MFD and PFD header {{{
432
        var route = me.device.map.layers.route;
433
        var fpSize = size(route.flightPlan);
434
        var navbox = {
435
            DTK: func {
436
                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
437
                if (dtk == nil)
438
                    return '---°';
439
                else
440
                    return sprintf('%03i°', dtk);
441
            },
442
            ETE: func {
443
                if (fpSize == 0) return '--:--';
444
                var eteSeconds = getprop('/autopilot/route-manager/ete');
445
                var eteHours = math.floor(eteSeconds / 3600);
446
                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
447
                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
448
            },
449
            DIS: func {
450
                if (fpSize == 0) return '---NM';
451
                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
452
                return sprintf(dist >= 100 ? '%i' : '%.1f', dist);
453
            },
454
            LEG: func {
455
                if (fpSize == 0) return '';
456
                var wp = route.flightPlan[route.currentLeg.index];
457
                return wp[0].name ~ ' > ' ~ wp[1].name;
458
            },
459
            GS : func return sprintf('%iKT', getprop('/velocities/groundspeed-kt')),
460
            TRK: func return sprintf('%03i°', getprop('/orientation/track-deg')),
461
            TAS: func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')),
462
            BRG: func return '---°',
463
            END: func return '---NM',
464
            ESA: func return '-----',
465
            ETA: func return '--:--',
466
            FOB: func return '---lbs',
467
            ISA: func return '-----',
468
            LDG: func return '--:--',
469
            MSA: func return '----ft',
470
            TKE: func return '---°',
471
            VSR: func return '----',
472
            XTK: func return '---NM',
473
        };
adds MFD menu for Aux/System...
Sébastien MARQUE authored on 2017-06-02
474
        if (getDataFields)
475
            return keys(navbox);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
476
        if (me.device.role == 'MFD') {
477
            for (var i=1; i<=4; i+=1)
478
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
479
                    .setText(
480
                        navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].get('text')]()
481
                    );
482
            settimer(func me.updateNavigationBox(), 0.6);
483
        }
484
        else { # PFD
485
            me.screenElements['ETE-text'].setText(navbox.ETE());
486
            me.screenElements['DIS-text'].setText(navbox.DIS());
487
            me.screenElements['LEG-text'].setText(navbox.LEG());
488
            settimer(func me.updateNavigationBox(), 0.3);
489
        }
490
    },
491
#}}}
492

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
493
    updateSoftKeys : func {
494
# update SoftKeys boxes {{{
495
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
496
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
497
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
498
                .setText('ALERTS');
499
            if (size(me.device.softkeys.path) != 0)
500
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
501
                    .setText('BACK')
502
                    .setColor(1,1,1);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
503
        }
504

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
505
        var path = keyMap[me.device.role];
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
506
        var bindings = me.device.softkeys.bindings[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
507
        var pathid = '';
508
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
509
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
510
            pathid ~= p;
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
511
            if (contains(bindings, p))
512
                bindings = bindings[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
513
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
514

            
515
        # feeding with empty menus the first boxes
516
        var start = (contains(path, 'first')) ? path.first : 0;
517
        for (var k = 0; k < start; k+=1) {
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
518
            var sftk = sprintf("SoftKey%02i-", k);
519
            me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
520
                .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
521
            me.screenElements[sftk ~ 'bg']
522
                .setColorFill(0,0,0);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
523
        }
524
        # filling with the content the next boxes
525
        forindex (var k; path.texts) {
526
            var i = k + start;
527
            me.screenElements[sprintf("SoftKey%02i-text", i)]
528
                .setText(path.texts[k]);
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
529
            me.setSoftKeyColor(i,
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
530
                    contains(me.device.softkeys.colored, pathid ~ path.texts[k]),
531
                    contains(bindings, path.texts[k]));
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
532
        }
533
        # feeding the last boxes with empty string
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
534
        var end = (me.device.role == 'PFD') ? 10 : 12;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
535
        if (size(path.texts) + start < end) {
536
            start = size(path.texts) + start;
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
537
            for (var k = start; k < end; k += 1) {
538
                var sftk = sprintf("SoftKey%02i-", k);
539
                me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
540
                    .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
541
                me.screenElements[sftk ~ 'bg']
542
                    .setColorFill(0,0,0);
543
            }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
544
        }
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
545

            
546
        if (size(me.device.softkeys.path))
547
            me.timers2.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
548
        else
549
            me.timers2.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
550
    },
551
#}}}
552

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
553
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
554
#{{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
555
        var pitch = data.pitch;
556
        var roll = data.roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
557
        if (pitch > 80)
558
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
559
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
560
            pitch = -80;
561
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
562
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
563
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
564
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
565
        me.screenElements.bankPointer
566
            .setRotation(-roll * D2R);
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
567
        me.screenElements['SlipSkid']
568
            .setTranslation(getprop("/instrumentation/slip-skid-ball/indicated-slip-skid") * 10, 0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
569
        me.screenElements['Traffic']
570
            .setVisible(size(data.tcas));
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
571
        settimer(func me.updateAI(), 0.1);
AI disponible
Sébastien MARQUE authored on 2017-03-10
572
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
573
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
574

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
575
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
576
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
577
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
578
        me.screenElements.VSIText
579
            .setText(num(math.round(vsi, 10)));
580
        if (vsi > 4500)
581
            vsi = 4500;
582
        elsif (vsi < -4500)
583
            vsi = -4500;
584
        me.screenElements.VSI
585
            .setTranslation(0, vsi * -0.03465);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
586
        settimer(func me.updateVSI(), 0.1);
animation VSI
Sébastien MARQUE authored on 2017-03-10
587
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
588
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
589

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
590
    updateIAS: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
591
# animates the IAS lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
592
        var ias = data.ias;
animation IAS
Sébastien MARQUE authored on 2017-03-10
593
        if (ias >= 10)
594
            me.screenElements.Speed110
595
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
596
        else
597
            me.screenElements.Speed110
598
                .setText('');
599
        me.screenElements.SpeedLint1
600
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
601
        me.screenElements.SpeedTape
602
            .setTranslation(0,ias * 5.711);
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
603
        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
604
            me._ias_already_exceeded = 1;
605
            me.screenElements['IAS-bg']
606
                .setColorFill(1,0,0);
607
        }
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
608
        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
609
            me._ias_already_exceeded = 0;
610
            me.screenElements['IAS-bg']
611
                .setColorFill(0,0,0);
612
        }
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
613
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide']) {
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
614
            if (me.device.data[v ~ '-visible'] and abs(data[v] - ias) < 30)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
615
                me.screenElements['IAS-' ~ v]
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
616
                    .setTranslation(0, (ias - data[v]) * 5.711)
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
617
                    .show();
618
            else
619
                me.screenElements['IAS-' ~ v]
620
                    .hide();
621
        }
622

            
trends animation
Sébastien MARQUE authored on 2017-03-13
623
        var now = systime();
624
        # estimated speed in 6s
625
        var Sy = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
626
        if (abs(Sy) > 30)
627
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
628
        me.screenElements['Airspeed-Trend-Indicator']
629
            .setScale(1,Sy)
630
            .setTranslation(0, -284.5 * (Sy - 1));
631
        me._last_ias_kt = ias;
632
        me._last_ias_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
633
        settimer(func me.updateIAS(), 0.1);
animation IAS
Sébastien MARQUE authored on 2017-03-10
634
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
635
    _last_ias_kt : 0,
636
    _last_ias_s : systime(),
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
637
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
638
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
639

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
640
    updateTAS: func {
641
# updates the True Airspeed and GroundSpeed indicators {{{
642
        me.screenElements['TAS-text']
643
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
644
        me.screenElements['GSPD-text']
645
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
646
        settimer(func me.updateTAS(), 0.5);
647
    },
648
#}}}
649

            
650
    updateALT: func () {
651
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
652
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
653
        if (alt < 0)
654
            me.screenElements.Alt11100
655
                .setText(sprintf("% 3i",math.ceil(alt/100)));
656
        elsif (alt < 100)
657
            me.screenElements.Alt11100
658
                .setText('');
659
        else
660
            me.screenElements.Alt11100
661
                .setText(sprintf("% 3i",math.floor(alt/100)));
662
        me.screenElements.AltLint00011
663
            .setTranslation(0,math.fmod(alt,100) * 1.24);
664

            
665
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
666
        if (alt> -1000 and alt< 1000000) {
667
            var Offset10 = 0;
668
            var Offset100 = 0;
669
            var Offset1000 = 0;
670
            if (alt< 0) {
671
                var Ne = 1;
672
                var alt= -alt;
673
            }
674
            else
675
                var Ne = 0;
676

            
677
            var Alt10       = math.mod(alt,100);
678
            var Alt100      = int(math.mod(alt/100,10));
679
            var Alt1000     = int(math.mod(alt/1000,10));
680
            var Alt10000    = int(math.mod(alt/10000,10));
681
            var Alt20       = math.mod(Alt10,20)/20;
682
            if (Alt10 >= 80)
683
                var Alt100 += Alt20;
684

            
685
            if (Alt10 >= 80 and Alt100 >= 9)
686
                var Alt1000 += Alt20;
687

            
688
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
689
                var Alt10000 += Alt20;
690

            
691
            if (alt> 100)
692
                var Offset10 = 100;
693

            
694
            if (alt> 1000)
695
                var Offset100 = 10;
696

            
697
            if (alt> 10000)
698
                var Offset1000 = 10;
699

            
700
            if (!Ne) {
701
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
702
                var altCentral = (int(alt/100)*100);
703
            }
704
            elsif (Ne) {
705
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
706
                var altCentral = -(int(alt/100)*100);
707
            }
708
            me.screenElements["AltBigC"].setText("");
709
            me.screenElements["AltSmallC"].setText("");
710
            for (var place = 1; place <= 6; place += 1) {
711
                var altUP = altCentral + (place*100);
712
                var offset = -30.078;
713
                if (altUP < 0) {
714
                    var altUP = -altUP;
715
                    var prefix = "-";
716
                    var offset += 15.039;
717
                }
718
                else
719
                    var prefix = "";
720

            
721
                if (altUP == 0) {
722
                    var AltBigUP    = "";
723
                    var AltSmallUP  = "0";
724

            
725
                }
726
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
727
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
728
                    var AltSmallUP  = "";
729
                }
730
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
731
                    var AltBigUP    = "";
732
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
733
                    var offset = -30.078;
734
                }
735
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
736
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
737
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
738
                    var offset += 15.039;
739
                }
740
                else {
741
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
742
                    var mod = int(math.mod(altUP,1000));
743
                    var AltSmallUP  = sprintf("%1d", mod);
744
                    var offset += 30.078;
745
                }
746

            
747
                me.screenElements["AltBigU"~place].setText(AltBigUP);
748
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
749
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
750
                var altDOWN = altCentral - (place*100);
751
                var offset = -30.078;
752
                if (altDOWN < 0) {
753
                    var altDOWN = -altDOWN;
754
                    var prefix = "-";
755
                    var offset += 15.039;
756
                }
757
                else
758
                    var prefix = "";
759

            
760
                if (altDOWN == 0) {
761
                    var AltBigDOWN  = "";
762
                    var AltSmallDOWN    = "0";
763
                }
764
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
765
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
766
                    var AltSmallDOWN    = "";
767
                }
768
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
769
                    var AltBigDOWN  = "";
770
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
771
                    var offset = -30.078;
772
                }
773
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
774
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
775
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
776
                    var offset += 15.039;
777
                }
778
                else {
779
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
780
                    var mod = int(math.mod(altDOWN,1000));
781
                    var AltSmallDOWN    = sprintf("%1d", mod);
782
                    var offset += 30.078;
783
                }
784
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
785
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
786
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
787
            }
788
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
789
        me.updateSelectedALT();
trends animation
Sébastien MARQUE authored on 2017-03-13
790
        var now = systime();
791
        # altitude in 6s
792
        var Sy = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
793
        if (abs(Sy) > 15)
794
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
795
        me.screenElements['Altitude-Trend-Indicator']
796
            .setScale(1,Sy)
797
            .setTranslation(0, -284.5 * (Sy - 1));
798
        me._last_alt_ft = alt;
799
        me._last_alt_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
800
        settimer(func me.updateALT(), 0.2);
animation ALT
Sébastien MARQUE authored on 2017-03-11
801
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
802
    _last_alt_ft : 0,
803
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
804
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
805

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
806
    updateBARO : func () {
807
# update BARO widget {{{
808
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
809
        me.screenElements['BARO-text']
810
            .setText(sprintf(fmt,
811
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
812
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
813
                );
814
    },
815
    _baro_unit : 'inhg',
816
#}}}
817

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
818
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
819
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
820
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
821
        me.screenElements.Rose
822
            .setRotation(-hdg * D2R);
823
        me.screenElements['HDG-text']
824
            .setText(sprintf("%03u°", hdg));
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
825
        settimer(func me.updateHSI(), 0.1);
animation HSI
Sébastien MARQUE authored on 2017-03-11
826
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
827
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
828

            
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
829
    updateHDG : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
830
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
831
        if (me.device.role == 'MFD')
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
832
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
833
        var hdg = afcs.getValue('heading-bug-deg');
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
834
        me.screenElements['Heading-bug']
835
            .setRotation(hdg * D2R);
836
        me.screenElements['SelectedHDG-bg']
837
            .show();
838
        me.screenElements['SelectedHDG-bgtext']
839
            .show();
840
        me.screenElements['SelectedHDG-text']
841
            .setText(sprintf('%03d°%s', hdg, ''))
842
            .show();
843
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
844
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
845
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
846

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
847
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
848
# TODO: update display for NAV/GPS/BRG courses {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
849
        if (me.device.role == 'MFD')
anime CRS
Sébastien MARQUE authored on 2017-03-13
850
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
851
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
852
        if (source == 'OFF')
853
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
854
        var crs = cdi.getValue('course');
adds CDI
Sébastien MARQUE authored on 2017-03-18
855
        if (crs == nil)
856
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
857
        me.screenElements['SelectedCRS-bg']
858
            .show();
859
        me.screenElements['SelectedCRS-bgtext']
860
            .show();
861
        me.screenElements['SelectedCRS-text']
862
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
863
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
864
            .show();
865
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
866
    },
867
#}}}
868

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
869
    updateSelectedALT : func {
870
# animation for altitude section, called via updatedALT {{{
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
871
        if (! me.screenElements['SelectedALT'].getVisible())
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
872
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
873
        var selected_alt = afcs.getValue('selected-alt-ft');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
874
        var delta_alt = data.alt - selected_alt;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
875
        if (abs(delta_alt) > 300)
876
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
877
        me.screenElements['SelectedALT-symbol']
878
            .setVisible(abs(delta_alt) > 100);
879
        me.screenElements['SelectedALT-bg']
880
            .setVisible(abs(delta_alt) > 100);
881
        me.screenElements['SelectedALT-text']
882
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
883
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
884
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
885
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
886
    },
887
#}}}
888

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
889
    updateCDI : func {
890
# animation for CDI {{{
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
891
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
892
        if (source == 'OFF') {
893
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
894
                foreach (var t; ['pointer', 'CDI'])
895
                    me.screenElements[s ~ '-' ~ t].hide();
896
            me.screenElements['CDI-GPS-ANN-text'].hide();
897
            me.screenElements['CDI-GPS-XTK-text'].hide();
898
            me.screenElements['CDI-SRC-text'].hide();
899
            me.screenElements['CDI'].hide();
900
        }
901
        else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
902
            var course = cdi.getValue('course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
903
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
904
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
905
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
906
                .show();
907
            me.screenElements['GPS-CTI']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
908
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
909
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
910
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
911
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
912
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
913
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
914
                me.screenElements[s ~ '-pointer']
915
                    .setRotation(rot)
916
                    .setVisible(source == s);
917
                me.screenElements[s ~ '-CDI']
918
                    .setVisible(source == s);
919
                foreach (var f; ['FROM', 'TO'])
920
                    me.screenElements[s ~ '-' ~ f]
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
921
                        .setVisible(s == source and cdi.getValue(f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
922
                me.screenElements['CDI-SRC-text']
923
                    .setText(source)
924
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
925
                    .show();
926
            }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
927
            var deflection = cdi.getValue('course-deflection');
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
928
            if (left(source, 3) == 'NAV')
929
                var scale = deflection / 4;
930
            else { # GPS
931
                # TODO: deviation depending of the flight phase
932
                # for now fixed 1 dot = 1 nm course error
933
                var abs_deflection = abs(deflection);
934
                me.screenElements['CDI-GPS-XTK-text']
935
                    .setText(sprintf('XTK %iNM', abs_deflection))
936
                    .setVisible(abs_deflection > 2.4);
937
                var scale = deflection / 2;
938
            }
939
            scale = (abs(scale) > 1.2) ? 1.2 : scale;
940
            me.screenElements[source ~ '-CDI']
941
                .setTranslation(65 * scale, 0);
942
            settimer(func me.updateCDI(), 0.3);
adds CDI
Sébastien MARQUE authored on 2017-03-18
943
        }
944
    },
945
#}}}
946

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
947
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
948
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
949
        # arg[0]._r = <comm|nav>
950
        if (contains(arg[0], "active")) {
951
            if (arg[0]['active'] == 'none') {
952
                me.screenElements[arg[0]._r ~ '1-selected-freq']
953
                    .setColor(1,1,1);
954
                me.screenElements[arg[0]._r ~ '2-selected-freq']
955
                    .setColor(1,1,1);
956
            }
957
            else {
958
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
959
                    .setColor(0,1,0);
960
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
961
                    .setColor(1,1,1);
962
            }
963
        }
964
        if (contains(arg[0], 'tune')) {
965
            # n = 0 -> NAV1/COMM1
966
            # n = 1 -> NAV1/COMM2
967
            me.screenElements[arg[0]._r ~ '-freq-switch']
968
                .setTranslation(0, arg[0].tune * 25);
969
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
970
                .setColor(0,1,1);
971
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
972
                .setColor(1,1,1);
973
        }
974
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
975
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
976
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
977
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
978
                .setText(sprintf(fmt, getprop('/instrumentation/'
979
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
980
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
981
                .setText(sprintf(fmt, getprop('/instrumentation/'
982
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
983
        }
984
        if (contains(arg[0], 'set')) {
985
            # positionne la valeur modifiée, les listeners "trigguent" en permanence ces propriétés, donc exit
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
986
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
987
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
988
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
989
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
990
        }
991
        if (contains(arg[0], 'auto')) {
992
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
993
            var radio = arg[0].auto;
994
            me._updateRadio({refresh: 1, _r: radio});
995
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
996
            settimer(func me._updateRadio({auto: radio}), 2);
997
        }
998
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
999
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1000

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1001
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1002
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1003
        # made active via menu
1004
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1005
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1006
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1007
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1008
                me.screenElements['nav1-id']
1009
                    .setColor(1,1,1);
1010
                me.screenElements['nav2-id']
1011
                    .setColor(1,1,1);
1012
                me.screenElements['NAV1-pointer']
1013
                    .hide();
1014
                me.screenElements['NAV2-pointer']
1015
                    .hide();
1016
            }
1017
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1018
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1019
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1020
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1021
                    .setColor(0,1,0);
1022
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1023
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1024
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1025
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1026
#                me.screenElements['HDI']
1027
#                    .setRotation();
1028
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1029
#                    .hide();
1030
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1031
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1032
#                        .hide();
1033
            }
1034
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1035
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1036
            # 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
1037
            if (arg[0].val == nil)
1038
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1039
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1040
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1041
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1042
        else {
1043
            arg[0]._r = 'nav';
1044
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1045
        }
1046
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1047
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1048

            
1049
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1050
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1051
        arg[0]._r = 'comm';
1052
        me._updateRadio(arg[0]);
1053
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1054
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1055

            
1056
    updateTIME : func {
1057
# updates the displayed time botoom left {{{
1058
        me.screenElements['TIME-text']
1059
            .setText(getprop('/sim/time/gmt-string'));
1060
        settimer(func me.updateTIME(), 1);
1061
    },
1062
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1063

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1064
    updateXPDR : func {
1065
# updates transponder display {{{
1066
        for (var d = 0; d < 4; d+=1)
1067
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1068
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1069
        var tuning = radios.getValue('xpdr-tuning-digit');
1070
        var fms = radios.getValue('xpdr-tuning-fms-method');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1071
        for (var d = 0; d < 4; d+=1)
1072
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1073
                .setColor(1,1,1);
1074
        if (tuning != nil) {
1075
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1076
                .setColor(0,1,1);
1077
            if (fms)
1078
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1079
                    .setColor(0,1,1);
1080
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1081
        else {
1082
            if (getprop('/instrumentation/transponder/ident'))
1083
                var mode = 'IDENT';
1084
            else
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1085
                var mode = radios.getValue('xpdr-mode');
adds transponder
Sébastien MARQUE authored on 2017-03-17
1086
            var wow = getprop('/gear/gear/wow');
1087
            if (! wow and mode != 'STBY')
1088
                var color = [0, 1, 0];
1089
            else
1090
                var color = [1, 1, 1];
1091
            for (var d = 0; d < 4; d+=1)
1092
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1093
                    .setColor(color);
1094
            me.screenElements['XPDR-MODE-text']
1095
                .setColor(color)
1096
                .setText(mode);
1097
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1098
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1099
#}}}
1100

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1101
    updateOAT : func {
1102
# update OAT display on normal and reversionnary modes (every 3s) {{{
1103
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1104
        me.screenElements['OAT-text']
1105
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1106
        settimer(func me.updateOAT(), 3);
1107
    },
1108
    _oat_unit : 'c',
1109
#}}}
1110

            
1111
    updateWindData : func {
1112
# update the window text and arrows for OPTN1/2 {{{
1113
        if (me._winddata_optn == 0)
1114
            return;
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1115
        if (data.ias < 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1116
            me.screenElements['WindData-NODATA']
1117
                .hide();
1118
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1119
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1120
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1121
            if (me._winddata_optn == 1) {
1122
                me.screenElements['WindData-OPTN1-HDG']
1123
                    .setRotation((alpha + 180) * D2R)
1124
                    .show();
1125
                me.screenElements['WindData-OPTN1-HDG-text']
1126
                    .setText(sprintf("%03i°", wind_hdg))
1127
                    .show();
1128
                me.screenElements['WindData-OPTN1-SPD-text']
1129
                    .setText(int(wind_spd) ~ 'KT')
1130
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1131
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1132
            else { # me._winddata_optn == 2
1133
                alpha *= D2R;
1134
                var Vt = wind_spd * math.sin(alpha);
1135
                var Ve = wind_spd * math.cos(alpha);
1136
                if (Vt != 0) {
1137
                    me.screenElements['WindData-OPTN2-crosswind-text']
1138
                        .setText(sprintf('%i', abs(Vt)))
1139
                        .show();
1140
                    me.screenElements['WindData-OPTN2-crosswind']
1141
                        .setScale(-abs(Vt)/Vt, 1)
1142
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1143
                        .show();
1144
                }
1145
                if (Ve != 0) {
1146
                    me.screenElements['WindData-OPTN2-headwind-text']
1147
                        .setText(sprintf('%i', abs(Ve)))
1148
                        .show();
1149
                    me.screenElements['WindData-OPTN2-headwind']
1150
                        .setScale(1, abs(Ve)/Ve)
1151
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1152
                        .show();
1153
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1154
            }
1155
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1156
        else {
1157
            foreach (var e; [
1158
                    'WindData-OPTN1-HDG',
1159
                    'WindData-OPTN1-HDG-text',
1160
                    'WindData-OPTN1-SPD-text',
1161
                    'WindData-OPTN2-crosswind-text',
1162
                    'WindData-OPTN2-crosswind',
1163
                    'WindData-OPTN2-headwind-text',
1164
                    'WindData-OPTN2-headwind'
1165
            ])
1166
                me.screenElements[e].hide();
1167
            me.screenElements['WindData-NODATA'].show();
1168
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1169
        settimer(func me.updateWindData(), 0.5);
1170
    },
1171
    _winddata_optn : 0,
1172
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1173

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1174
    updateAOA : func {
1175
# update Angle Of Attack {{{
1176
        if (me.device.data.aoa == 0)
1177
            return;
1178
        var color = [1,1,1];
1179
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1180
        me.screenElements['AOA-text']
1181
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1182
        if (norm > 1) norm = 1;
1183
        if (norm > 0.9)
1184
            color = [1,0,0];
1185
        elsif (norm > 0.7)
1186
            color = [1,1,0];
1187
        elsif (norm < 0) {
1188
            norm = 0;
1189
            color = [1,0,0];
1190
        }
1191
        me.screenElements['AOA-needle']
1192
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1193
            .setColorFill(color);
1194
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1195
            .setColor(color);
1196
        settimer(func me.updateAOA(), 0.1);
1197
    },
1198
# }}}
1199

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

            
1205
            var dev = radios.getNode(source).getValue();
1206
            var el  = 'BRG' ~ brg;
1207
            if (dev != 'OFF') {
1208
                var info = {
1209
                    pointer : nil,
1210
                    id : 'NO DATA',
1211
                    hdg : nil,
1212
                    dst : '--.-NM'
1213
                };
1214
                if (left(dev, 3) == 'NAV') {
1215
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1216
                    if (info.pointer) {
1217
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1218
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1219
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1220
                    }
1221
                }
1222
                elsif (dev == 'GPS') {
1223
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1224
                    if (info.pointer) {
1225
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1226
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1227
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1228
                    }
1229
                }
1230
                else { # there are 2 available ADF in FG, but instrument manage only 1
1231
                    info.pointer = getprop('/instrumentation/adf/in-range');
1232
                    if (info.pointer) {
1233
                        info.id  = getprop('/instrumentation/adf/ident');
1234
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1235
                    }
1236
                }
1237

            
1238
                if (info.pointer)
1239
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1240
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1241
                        .show();
1242
                else
1243
                    me.screenElements[el ~ '-pointer']
1244
                        .hide();
1245
                me.screenElements[el ~ '-SRC-text']
1246
                    .setText(dev);
1247
                me.screenElements[el ~ '-DST-text']
1248
                    .setText(info.dst);
1249
                me.screenElements[el ~ '-WPID-text']
1250
                    .setText(info.id);
1251
                me.screenElements['BRG' ~ brg]
1252
                    .show();
1253
            }
1254
            else {
1255
                me.screenElements['BRG' ~ brg]
1256
                    .hide();
1257
            }
1258
        }
colorize BRG1/2 when needed,...
Sébastien MARQUE authored on 2017-03-21
1259
        settimer(func me.updateBRG(), 0.5);
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1260
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1261
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1262

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1263
    updateOMI : func {
1264
# display marker baecon Outer, Middle, Inner {{{
1265
        var marker = nil;
1266
        foreach (var m; ['outer', 'middle', 'inner'])
1267
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1268
                marker = m;
1269
                me.screenElements['OMI']
1270
                    .show();
1271
                break;
1272
            }
1273
        if (marker != nil) {
1274
            me.screenElements['MarkerText']
1275
                .setText(me._omi_data[marker].t)
1276
                .show();
1277
            me.screenElements['MarkerBG']
1278
                .setColorFill(me._omi_data[marker].bg)
1279
                .show();
1280
        }
1281
        else
1282
            me.screenElements['OMI']
1283
                .hide();
1284
        settimer(func me.updateOMI(), 1);
1285
    },
1286
    _omi_data : {
1287
        'outer':  {t: 'O', bg: [0,1,1]},
1288
        'middle': {t: 'M', bg: [1,1,1]},
1289
        'inner':  {t: 'I', bg: [1,1,0]},
1290
    },
1291
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1292
};