zkv1000 / Nasal / display.nas /
Newer Older
1183 lines | 44.569kb
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 = {
pass device pointer to displ...
Sébastien MARQUE authored on 2017-03-14
3
    new: func(device, role) {
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({
8
                "name"      : role,
9
                "size"      : [1024, 768],
10
                "view"      : [1024, 768],
11
                "mipmapping": 1
12
        });
13
        m.display.addPlacement({
14
                "node": "Screen",
15
                "parent": role
16
        });
17
        m.display.setColorBackground(0,0,0);
18
        m.role = 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 = {};
commit initial
Sébastien MARQUE authored on 2017-03-07
21

            
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
22
        if (role == 'MFD') {
23
            m.MFDMapTiles = MapTiles.new(m.display);
24
            m.MFDMapNavDisplay = MapNavDisplay.new(m.display);
25
        }
26

            
commit initial
Sébastien MARQUE authored on 2017-03-07
27
        return m;
28
    },
add new vim folds
Sébastien MARQUE authored on 2017-03-15
29
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
30

            
add new vim folds
Sébastien MARQUE authored on 2017-03-15
31
# timers stuff {{{
ajoute un timer pour cacher ...
Sébastien MARQUE authored on 2017-03-13
32
    timers : {},
33

            
34
    timerTrigger : func {
35
        var now = systime();
36
        foreach (var id; keys(me.timers)) {
37
            if (me.timers[id] < now) {
38
                me.screenElements[id].hide();
39
                delete(me.timers, id);
40
            }
41
        }
42
        settimer(func me.timerTrigger(), 1);
43
    },
44

            
45
    addTimer : func (duration, element) {
46
        if (typeof(element) == 'scalar')
47
            element = [ element ];
48
        var end = systime() + duration;
49
        foreach (var e; element)
50
            me.timers[e] = end;
51
    },
add new vim folds
Sébastien MARQUE authored on 2017-03-15
52
#}}}
ajoute un timer pour cacher ...
Sébastien MARQUE authored on 2017-03-13
53

            
commit initial
Sébastien MARQUE authored on 2017-03-07
54
    loadsvg : func () {
55
        me.screen = me.display.createGroup();
56
        me.screen.hide();
57
        canvas.parsesvg(me.screen, "Aircraft/Instruments-3d/zkv1000/Systems/screen.svg");
58
    },
59

            
60
    _showInitProgress : func (p,t) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
61
#{{{
commit initial
Sébastien MARQUE authored on 2017-03-07
62
        p.setText(t);
63
        if (zkv.getNode(me.role ~ 'init').getValue() != 0) {
64
            if (size(t) >= 10) t = '';
65
            settimer(func { me._showInitProgress(p, t ~ '.'); }, 0.1);
66
        }
67
        else {
68
            me.progress.hide();
69
            me.screen.show();
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
70
            var groups = {
animation VSI
Sébastien MARQUE authored on 2017-03-10
71
                show : [
makes header visible on MFD ...
Sébastien MARQUE authored on 2017-03-18
72
                    'Header',
commit initial
Sébastien MARQUE authored on 2017-03-07
73
                    'SoftKeysTexts', 
74
                    'COMM', 
75
                    'NAV', 
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
76
                    'nav-freq-switch',
77
                    'comm-freq-switch',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
78
                ],
79
                text: [
80
                    'nav1-standby-freq', 'nav1-selected-freq', 'nav1-id',
81
                    'nav2-standby-freq', 'nav2-selected-freq', 'nav2-id',
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
82
                    'comm1-standby-freq', 'comm1-selected-freq',
83
                    'comm2-standby-freq', 'comm2-selected-freq',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
84
                ],
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
85
                hide : [ ],
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
86
                clip: [ ],
87
            };
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
88

            
89
            for (var k = 0; k < 12; k += 1)
90
                append(groups.text, sprintf("SoftKey%02i-text", k));
91

            
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
92
            if (me.role == 'PFD') {
93
                append(groups.show,
commit initial
Sébastien MARQUE authored on 2017-03-07
94
                    'XPDR-TIME', 
AI disponible
Sébastien MARQUE authored on 2017-03-10
95
                    'FlightInstruments',
96
                    'Horizon',
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
97
                    'bankPointer',
animation VSI
Sébastien MARQUE authored on 2017-03-10
98
                    'VSI',
animation HSI
Sébastien MARQUE authored on 2017-03-11
99
                    'Rose',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
100
                    'Heading-bug',
101
                    'PFD-Widgets',
trends animation
Sébastien MARQUE authored on 2017-03-13
102
                    'Trends',
103
                    'Airspeed-Trend-Indicator',
104
                    'Altitude-Trend-Indicator',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
105
                    'OAT',
106
                    'IAS-bg',
107
                    'TAS',
108
                    'GSPD',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
109
                );
110
                append(groups.hide,
adds EIS
Sébastien MARQUE authored on 2017-03-18
111
                    'EIS',
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
112
                    'CDI',
adds CDI
Sébastien MARQUE authored on 2017-03-18
113
                    'NAV1-pointer', 'NAV1-CDI', 'NAV1-FROM', 'NAV1-TO',
114
                    'NAV2-pointer', 'NAV2-CDI', 'NAV2-FROM', 'NAV2-TO',
115
                    '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
116
                    'BRG1-pointer',
117
                    'BRG2-pointer',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
118
                    'SelectedHDG-bg',
119
                    'SelectedHDG-bgtext',
120
                    'SelectedHDG-text',
121
                    'SelectedCRS-bg',
122
                    'SelectedCRS-bgtext',
123
                    'SelectedCRS-text',
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
124
                    'SelectedALT', 'SelectedALT-bug', 'SelectedALT-bg', 'SelectedALT-symbol',
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
125
                    'TAS',
126
                    'GSPD',
127
                    'BARO',
128
                    'WindData',
129
                    'Reversionnary',
130
                    'Annunciation',
131
                    'Comparator',
132
                    'BRG1',
133
                    'BRG2',
134
                    'DME1',
135
                    'PFD-Map',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
136
                    'PFD-Multilines',
improves WindData display
Sébastien MARQUE authored on 2017-03-16
137
                    'WindData', 'WindData-OPTN1', 'WindData-OPTN2', 'WindData-OPTN1-HDG', 'WindData-OPTN2-symbol', 'WindData-OPTN2-headwind', 'WindData-OPTN2-crosswind', 'WindData-NODATA',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
138
                );
139
                append(groups.clip,
animation IAS
Sébastien MARQUE authored on 2017-03-10
140
                    'SpeedLint1',
animation ALT
Sébastien MARQUE authored on 2017-03-11
141
                    'SpeedTape',
142
                    'LintAlt',
143
                    'AltLint00011'
144
                );
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
145
                append(groups.text,
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
146
                    'SelectedALT-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
147
                    'TAS-text',
148
                    'GSPD-text',
anime time display
Sébastien MARQUE authored on 2017-03-13
149
                    'TIME-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
150
                    'OAT-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
151
                    'VSIText',
152
                    'Speed110',
153
                    'Alt11100',
154
                    'HDG-text',
adds CDI
Sébastien MARQUE authored on 2017-03-18
155
                    'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
156
                    'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
157
                    'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
158
                    'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
159
                    'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
adds transponder
Sébastien MARQUE authored on 2017-03-17
160
                    'XPDR-MODE-text', 'XPDR-DIGIT-3-text', 'XPDR-DIGIT-2-text', 'XPDR-DIGIT-1-text', 'XPDR-DIGIT-0-text',
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
161
                    'AltBigC', 'AltSmallC'
162
                );
163
                for (var place = 1; place <= 6; place +=1) {
164
                    append(groups.text,
165
                        'AltBigU' ~ place,
166
                        'AltSmallU' ~ place,
167
                        'AltBigD' ~ place,
168
                        'AltSmallD' ~ place
169
                    );
170
                }
animation ALT
Sébastien MARQUE authored on 2017-03-11
171
            }
adds EIS
Sébastien MARQUE authored on 2017-03-18
172
            else {
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
173
                append(groups.show, 'EIS', 'POWER-pointer');
174
                append(groups.text,
175
                        'RPM-text', 'EGT-text', 'CHT-text', 'FUEL-USED-text',
176
                        'FUEL-FLOW-text', 'MAN-Hg-text', 'POWER-PERCENT-text',
177
                        'RPM-text', 'BUS-V-text', 'BATT-text', 'PSI-text',
178
                        'OIL-TEMP-text'
179
                    );
adds EIS
Sébastien MARQUE authored on 2017-03-18
180
            }
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
181

            
182
            me.loadGroup(groups);
animation ALT
Sébastien MARQUE authored on 2017-03-11
183

            
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
184
            if (me.role == 'PFD') {
refresh of vital information...
Sébastien MARQUE authored on 2017-03-18
185
                me.update20Hz();
186
                me.update1Hz();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
187
                me.updateAI();
188
                me.updateVSI();
189
                me.updateIAS();
190
                me.updateALT();
191
                me.updateHSI();
anime time display
Sébastien MARQUE authored on 2017-03-13
192
                me.updateTIME();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
193
                me.updateOAT();
194
                me.updateTAS();
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
195
                me.updateBRG();
adds transponder
Sébastien MARQUE authored on 2017-03-17
196
                me.updateXPDR();
ajoute un timer pour cacher ...
Sébastien MARQUE authored on 2017-03-13
197
                me.timerTrigger();
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
198
            }
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
199
            else {
200
                me.updateEIS();
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
201
                me.MFDMapNavDisplay.showMap();
202
                me.MFDMapTiles.initialize_grid();
203
                me.MFDMapTiles.update_timer.start();
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
204
            }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
205
            me._updateRadio({auto:'nav'});
206
            me._updateRadio({auto:'comm'});
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
207
            me.updateSoftKeys();
commit initial
Sébastien MARQUE authored on 2017-03-07
208
            me.progress.removeAllChildren();
209
            me.progress = nil;
210
            me.showInitProgress = nil;
211
            me._showInitProgress = nil;
212
            zkv.removeChild(me.role ~ 'init');
213
        }
214
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
215
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
216

            
217
    showInitProgress : func (role) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
218
#{{{
commit initial
Sébastien MARQUE authored on 2017-03-07
219
        me.progress = me.display.createGroup();
220
        me.progress.show();
221
        me.progress.createChild("text", role ~ " title")
222
            .setTranslation(512, 384)
223
            .setAlignment("center-center")
224
            .setFont("LiberationFonts/LiberationSans-Italic.ttf")
225
            .setFontSize(64, 1)
226
            .setColor(1,1,1)
227
            .setText("ZKV1000 " ~ role ~ " init");
228

            
229
        zkv.getNode(role ~ 'init',1).setIntValue(1);
230

            
231
        me._showInitProgress(me.progress.createChild("text", role ~ "progress")
232
            .setTranslation(512, 484)
233
            .setAlignment("center-center")
234
            .setFont("LiberationFonts/LiberationSans-Bold.ttf")
235
            .setFontSize(128, 1)
236
            .setColor(1,0,0), '.');
237
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
238
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
239

            
some added comments
Sébastien MARQUE authored on 2017-03-18
240
    colors : {
241
# set of predefined colors {{{
242
        green : [0, 1, 0],
243
        white : [1, 1, 1],
244
        black : [0, 0, 0],
245
        lightblue : [0, 1, 1],
246
        darkblue : [0, 0, 1],
247
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
248
        magenta : [1, 0, 1],
some added comments
Sébastien MARQUE authored on 2017-03-18
249
    },
250
#}}}
251

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
252
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
253
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
254
        if (typeof(h) != 'hash') {
255
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
256
                    caller(0)[0],
257
                    typeof(h),
258
                    caller(1)[0]));
259
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
260
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
261
        var setMethod = func (e, t) {
262
            if (t == 'hide')
263
                me.screenElements[e].hide();
264
            elsif (t == 'show')
265
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
266
            elsif (t == 'rot' or t == 'trans') {
267
                if (! contains(me.screenElements[e], t))
268
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
269
            }
270
            elsif (t == 'clip') {
271
                if (contains(me.clips, e))
272
                    me.screenElements[e].set("clip", me.clips[e]);
273
                else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
274
                    printlog('warn', 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
275
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
276
            elsif (t == 'text') {
277
                if (contains(me.texts, e)) {
278
                    if (contains(me.texts[e], 'alignment'))
279
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
280
                    if (contains(me.texts[e], 'default'))
281
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
282
                    if (contains(me.texts[e], 'color'))
283
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
284
                    if (contains(me.texts[e], 'visible'))
285
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
286
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
287
                else
288
                    printlog('debug', 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
289
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
290
            else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
291
                printlog('warn', 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
292
        };
293
        foreach (var todo; keys(h)) {
294
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
295
            foreach (var id; h[todo]) {
296
                if (! contains(me.screenElements, id)) {
297
                    me.screenElements[id] = me.screen.getElementById(id);
298
                    if (me.screenElements[id] != nil)
299
                        setMethod(id, todo);
300
                    else
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
301
                        printlog('warn', 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
302
                }
303
                else
304
                    setMethod(id, todo);
305
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
306
        }
307
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
308
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
309

            
310
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
311
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
312
        PitchScale   : "rect(70,664,370,256)",
313
        SpeedLint1   : "rect(252,226,318,204)",
314
        SpeedTape    : "rect(115,239,455,156)",
315
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
316
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
317
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
318
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
319

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
320
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
321
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
322
        VSIText : {
323
            alignment: "right-bottom", default : num('0'),
324
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
325
        Speed110 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
326
            alignment : 'left-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
327
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
328
        Alt11100 : {
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
329
            alignment:'left-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
330
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
331
        "HDG-text" : {
332
            default: '---°'
333
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
334
        'nav1-standby-freq' : {
335
            color: [0, 1, 1],
336
        },
337
        'nav1-id' : {
338
            default: ''
339
        },
340
        'nav2-id' : {
341
            default: ''
342
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
343
        'CDI-GPS-ANN-text' : {
344
            visible : 0
345
        },
346
        'CDI-GPS-XTK-text' : {
347
            visible : 0
348
        },
349
        'CDI-SRC-text' : {
350
            visible : 0
351
        },
some added comments
Sébastien MARQUE authored on 2017-03-18
352
#        'TAS-text' : {
353
#            alignment : 'right-bottom',
354
#        },
355
#        'GSPD-text' : {
356
#            alignment : 'right-bottom',
357
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
358
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
359
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
360

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
361
    updateSoftKeys : func {
362
# update SoftKeys boxes {{{
363
        # grey background code = #353939
364
        # on PFD the last boxes are always BACK and ALERTS
365
        if (me.role == 'PFD') {
366
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
367
                .setText('ALERTS');
368
            if (size(me.device.softkeys.path) != 0)
369
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
370
                    .setText('BACK');
371
        }
372

            
373
        var path = keyMap[me.role];
374
        foreach (var p; me.device.softkeys.path)
375
            path = path[p];
376

            
377
        # feeding with empty menus the first boxes
378
        var start = (contains(path, 'first')) ? path.first : 0;
379
        for (var k = 0; k < start; k+=1) {
380
            me.screenElements[sprintf("SoftKey%02i-text", k)]
381
                .setText('');
382
        }
383
        # filling with the content the next boxes
384
        forindex (var k; path.texts) {
385
            var i = k + start;
386
            me.screenElements[sprintf("SoftKey%02i-text", i)]
387
                .setText(path.texts[k]);
388
        }
389
        # feeding the last boxes with empty string
390
        var end = (me.role == 'PFD') ? 10 : 12;
391
        if (size(path.texts) + start < end) {
392
            start = size(path.texts) + start;
393
            for (var k = start; k < end; k += 1)
394
                me.screenElements[sprintf("SoftKey%02i-text", k)]
395
                    .setText('');
396
        }
397
    },
398
#}}}
399

            
refresh of vital information...
Sébastien MARQUE authored on 2017-03-18
400
    update20Hz : func {
401
# 20Hz updates roll, pitch, VSI, IAS, altitude and HDG {{{
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
402
        me._updated_roll = getprop('/orientation/roll-deg');
403
        me._updated_pitch = getprop('orientation/pitch-deg');
404
        me._updated_vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm');
405
        me._updated_ias = getprop('/velocities/airspeed-kt');
406
        me._updated_alt = getprop('/instrumentation/altimeter/indicated-altitude-ft');
407
        me._updated_hdg = getprop('/orientation/heading-deg');
refresh of vital information...
Sébastien MARQUE authored on 2017-03-18
408
        settimer(func me.update20Hz(), 0.05);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
409
     },
410
    _updated_roll : 0,
411
    _updated_pitch : 0,
412
    _updated_vsi : 0,
413
    _updated_ias : 0,
414
    _updated_alt : 0,
415
    _updated_hdg : 0,
416
#}}}
417

            
refresh of vital information...
Sébastien MARQUE authored on 2017-03-18
418
    update1Hz : func {
419
# 1Hz updates {{{
420
        me._updated_wow = getprop('/gear/gear/wow');
421
        settimer(func me.update20Hz(), 1);
422
    },
423
    _updated_wow : 1,
424
#}}}
425

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
426
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
427
#{{{
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
428
        var pitch = me._updated_pitch;
429
        var roll = me._updated_roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
430
        if (pitch > 80)
431
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
432
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
433
            pitch = -80;
434
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
435
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
436
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
437
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
438
        me.screenElements.bankPointer
439
            .setRotation(-roll * D2R);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
440
        settimer(func me.updateAI(), 0.1);
AI disponible
Sébastien MARQUE authored on 2017-03-10
441
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
442
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
443

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
444
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
445
# animate VSI {{{
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
446
        var vsi = me._updated_vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
447
        me.screenElements.VSIText
448
            .setText(num(math.round(vsi, 10)));
449
        if (vsi > 4500)
450
            vsi = 4500;
451
        elsif (vsi < -4500)
452
            vsi = -4500;
453
        me.screenElements.VSI
454
            .setTranslation(0, vsi * -0.03465);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
455
        settimer(func me.updateVSI(), 0.1);
animation VSI
Sébastien MARQUE authored on 2017-03-10
456
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
457
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
458

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
459
    updateIAS: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
460
# animates the IAS lint (PFD) {{{
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
461
        var ias = me._updated_ias;
animation IAS
Sébastien MARQUE authored on 2017-03-10
462
        if (ias >= 10)
463
            me.screenElements.Speed110
464
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
465
        else
466
            me.screenElements.Speed110
467
                .setText('');
468
        me.screenElements.SpeedLint1
469
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
470
        me.screenElements.SpeedTape
471
            .setTranslation(0,ias * 5.711);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
472
        if (ias > me._ias_vne and ! me._ias_already_exceeded) { # easier than .getColorFill
473
            me._ias_already_exceeded = 1;
474
            me.screenElements['IAS-bg']
475
                .setColorFill(1,0,0);
476
        }
477
        elsif (ias < me._ias_vne and me._ias_already_exceeded) { # easier than .getColorFill
478
            me._ias_already_exceeded = 0;
479
            me.screenElements['IAS-bg']
480
                .setColorFill(0,0,0);
481
        }
trends animation
Sébastien MARQUE authored on 2017-03-13
482
        var now = systime();
483
        # estimated speed in 6s
484
        var Sy = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
485
        if (abs(Sy) > 30)
486
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
487
        me.screenElements['Airspeed-Trend-Indicator']
488
            .setScale(1,Sy)
489
            .setTranslation(0, -284.5 * (Sy - 1));
490
        me._last_ias_kt = ias;
491
        me._last_ias_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
492
        settimer(func me.updateIAS(), 0.1);
animation IAS
Sébastien MARQUE authored on 2017-03-10
493
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
494
    _last_ias_kt : 0,
495
    _last_ias_s : systime(),
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
496
    _ias_vne : 999,
497
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
498
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
499

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
500
    updateTAS: func {
501
# updates the True Airspeed and GroundSpeed indicators {{{
502
        me.screenElements['TAS-text']
503
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
504
        me.screenElements['GSPD-text']
505
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
506
        settimer(func me.updateTAS(), 0.5);
507
    },
508
#}}}
509

            
510
    updateALT: func () {
511
# animates the altitude lint (PFD) {{{
512
        var alt = me._updated_alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
513
        if (alt < 0)
514
            me.screenElements.Alt11100
515
                .setText(sprintf("% 3i",math.ceil(alt/100)));
516
        elsif (alt < 100)
517
            me.screenElements.Alt11100
518
                .setText('');
519
        else
520
            me.screenElements.Alt11100
521
                .setText(sprintf("% 3i",math.floor(alt/100)));
522
        me.screenElements.AltLint00011
523
            .setTranslation(0,math.fmod(alt,100) * 1.24);
524

            
525
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
526
        if (alt> -1000 and alt< 1000000) {
527
            var Offset10 = 0;
528
            var Offset100 = 0;
529
            var Offset1000 = 0;
530
            if (alt< 0) {
531
                var Ne = 1;
532
                var alt= -alt;
533
            }
534
            else
535
                var Ne = 0;
536

            
537
            var Alt10       = math.mod(alt,100);
538
            var Alt100      = int(math.mod(alt/100,10));
539
            var Alt1000     = int(math.mod(alt/1000,10));
540
            var Alt10000    = int(math.mod(alt/10000,10));
541
            var Alt20       = math.mod(Alt10,20)/20;
542
            if (Alt10 >= 80)
543
                var Alt100 += Alt20;
544

            
545
            if (Alt10 >= 80 and Alt100 >= 9)
546
                var Alt1000 += Alt20;
547

            
548
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
549
                var Alt10000 += Alt20;
550

            
551
            if (alt> 100)
552
                var Offset10 = 100;
553

            
554
            if (alt> 1000)
555
                var Offset100 = 10;
556

            
557
            if (alt> 10000)
558
                var Offset1000 = 10;
559

            
560
            if (!Ne) {
561
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
562
                var altCentral = (int(alt/100)*100);
563
            }
564
            elsif (Ne) {
565
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
566
                var altCentral = -(int(alt/100)*100);
567
            }
568
            me.screenElements["AltBigC"].setText("");
569
            me.screenElements["AltSmallC"].setText("");
570
            for (var place = 1; place <= 6; place += 1) {
571
                var altUP = altCentral + (place*100);
572
                var offset = -30.078;
573
                if (altUP < 0) {
574
                    var altUP = -altUP;
575
                    var prefix = "-";
576
                    var offset += 15.039;
577
                }
578
                else
579
                    var prefix = "";
580

            
581
                if (altUP == 0) {
582
                    var AltBigUP    = "";
583
                    var AltSmallUP  = "0";
584

            
585
                }
586
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
587
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
588
                    var AltSmallUP  = "";
589
                }
590
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
591
                    var AltBigUP    = "";
592
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
593
                    var offset = -30.078;
594
                }
595
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
596
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
597
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
598
                    var offset += 15.039;
599
                }
600
                else {
601
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
602
                    var mod = int(math.mod(altUP,1000));
603
                    var AltSmallUP  = sprintf("%1d", mod);
604
                    var offset += 30.078;
605
                }
606

            
607
                me.screenElements["AltBigU"~place].setText(AltBigUP);
608
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
609
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
610
                var altDOWN = altCentral - (place*100);
611
                var offset = -30.078;
612
                if (altDOWN < 0) {
613
                    var altDOWN = -altDOWN;
614
                    var prefix = "-";
615
                    var offset += 15.039;
616
                }
617
                else
618
                    var prefix = "";
619

            
620
                if (altDOWN == 0) {
621
                    var AltBigDOWN  = "";
622
                    var AltSmallDOWN    = "0";
623
                }
624
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
625
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
626
                    var AltSmallDOWN    = "";
627
                }
628
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
629
                    var AltBigDOWN  = "";
630
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
631
                    var offset = -30.078;
632
                }
633
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
634
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
635
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
636
                    var offset += 15.039;
637
                }
638
                else {
639
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
640
                    var mod = int(math.mod(altDOWN,1000));
641
                    var AltSmallDOWN    = sprintf("%1d", mod);
642
                    var offset += 30.078;
643
                }
644
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
645
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
646
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
647
            }
648
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
649
        me.updateSelectedALT();
trends animation
Sébastien MARQUE authored on 2017-03-13
650
        var now = systime();
651
        # altitude in 6s
652
        var Sy = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
653
        if (abs(Sy) > 15)
654
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
655
        me.screenElements['Altitude-Trend-Indicator']
656
            .setScale(1,Sy)
657
            .setTranslation(0, -284.5 * (Sy - 1));
658
        me._last_alt_ft = alt;
659
        me._last_alt_s = now;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
660
        settimer(func me.updateALT(), 0.2);
animation ALT
Sébastien MARQUE authored on 2017-03-11
661
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
662
    _last_alt_ft : 0,
663
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
664
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
665

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
666
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
667
# rotates the compass (PFD) {{{
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
668
        var hdg = me._updated_hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
669
        me.screenElements.Rose
670
            .setRotation(-hdg * D2R);
671
        me.screenElements['HDG-text']
672
            .setText(sprintf("%03u°", hdg));
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
673
        settimer(func me.updateHSI(), 0.1);
animation HSI
Sébastien MARQUE authored on 2017-03-11
674
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
675
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
676

            
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
677
    updateHDG : func (hdg) {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
678
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
679
        if (me.role == 'MFD')
680
            return;
681
        me.screenElements['Heading-bug']
682
            .setRotation(hdg * D2R);
683
        me.screenElements['SelectedHDG-bg']
684
            .show();
685
        me.screenElements['SelectedHDG-bgtext']
686
            .show();
687
        me.screenElements['SelectedHDG-text']
688
            .setText(sprintf('%03d°%s', hdg, ''))
689
            .show();
690
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
691
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
692
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
693

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
694
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
695
# TODO: update display for NAV/GPS/BRG courses {{{
696
        if (me.role == 'MFD')
697
            return;
adds CDI
Sébastien MARQUE authored on 2017-03-18
698
        var source = getprop('/instrumentation/zkv1000/cdi/source');
699
        if (source == 'OFF')
700
            return;
701
        var crs = getprop('/instrumentation/zkv1000/cdi/course');
702
        if (crs == nil)
703
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
704
        me.screenElements['SelectedCRS-bg']
705
            .show();
706
        me.screenElements['SelectedCRS-bgtext']
707
            .show();
708
        me.screenElements['SelectedCRS-text']
709
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
710
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
711
            .show();
712
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
713
    },
714
#}}}
715

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
716
    updateSelectedALT : func {
717
# animation for altitude section, called via updatedALT {{{
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
718
        if (! device[0].display.screenElements['SelectedALT'].getVisible())
719
            return;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
720
        var selected_alt = getprop('/instrumentation/zkv1000/afcs/selected-alt-ft');
721
        var delta_alt = me._updated_alt - selected_alt;
722
        if (abs(delta_alt) > 300)
723
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
724
        me.screenElements['SelectedALT-symbol']
725
            .setVisible(abs(delta_alt) > 100);
726
        me.screenElements['SelectedALT-bg']
727
            .setVisible(abs(delta_alt) > 100);
728
        me.screenElements['SelectedALT-text']
729
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
730
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
731
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
732
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
733
    },
734
#}}}
735

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
736
    updateCDI : func {
737
# animation for CDI {{{
738
        var source = getprop('/instrumentation/zkv1000/cdi/source');
739
        if (source == 'OFF') {
740
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
741
                foreach (var t; ['pointer', 'CDI'])
742
                    me.screenElements[s ~ '-' ~ t].hide();
743
            me.screenElements['CDI-GPS-ANN-text'].hide();
744
            me.screenElements['CDI-GPS-XTK-text'].hide();
745
            me.screenElements['CDI-SRC-text'].hide();
746
            me.screenElements['CDI'].hide();
747
        }
748
        else {
749
            var course = getprop('/instrumentation/zkv1000/cdi/course');
750
            me.screenElements['CDI']
751
                .show();
752
            me.screenElements['GPS-CTI']
753
                .setVisible(source == 'GPS');
754
            me.screenElements['GPS-CTI-diamond']
755
                .setVisible(source == 'GPS');
756
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
757
                var rot = (course - me._updated_hdg) * D2R;
758
                me.screenElements[s ~ '-pointer']
759
                    .setRotation(rot)
760
                    .setVisible(source == s);
761
                me.screenElements[s ~ '-CDI']
762
                    .setVisible(source == s);
763
                foreach (var f; ['FROM', 'TO'])
764
                    me.screenElements[s ~ '-' ~ f]
765
                        .setVisible(s == source and getprop('/instrumentation/zkv1000/cdi/', f, '-flag'));
766
                me.screenElements['CDI-SRC-text']
767
                    .setText(source)
768
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
769
                    .show();
770
                var deflection = getprop('/instrumentation/zkv1000/cdi/course-deflection');
771
                if (left(source, 3) == 'NAV') {
772
                    var scale = deflection / 4;
773
                    scale = (abs(scale) > 1.2) ? 1.2 : scale;
774
                }
775
                else {
776
                    me.screenElements['CDI-SRC-text']
777
                        .setText('GPS')
778
                        .setColor(1,0,1);
779
                }
780
                me.screenElements[source ~ '-CDI']
781
                    .setTranslation(65 * scale, 0);
782
            }
783
            settimer(func me.updateCDI(), 0.5);
784
        }
785
    },
786
#}}}
787

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
788
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
789
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
790
        # arg[0]._r = <comm|nav>
791
        if (contains(arg[0], "active")) {
792
            if (arg[0]['active'] == 'none') {
793
                me.screenElements[arg[0]._r ~ '1-selected-freq']
794
                    .setColor(1,1,1);
795
                me.screenElements[arg[0]._r ~ '2-selected-freq']
796
                    .setColor(1,1,1);
797
            }
798
            else {
799
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
800
                    .setColor(0,1,0);
801
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
802
                    .setColor(1,1,1);
803
            }
804
        }
805
        if (contains(arg[0], 'tune')) {
806
            # n = 0 -> NAV1/COMM1
807
            # n = 1 -> NAV1/COMM2
808
            me.screenElements[arg[0]._r ~ '-freq-switch']
809
                .setTranslation(0, arg[0].tune * 25);
810
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
811
                .setColor(0,1,1);
812
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
813
                .setColor(1,1,1);
814
        }
815
        if (contains(arg[0], 'refresh')) {
816
            # rafraichi une seule ligne NAV1/COMM1 ou NAV2/COMM2
817
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
818
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
819
                .setText(sprintf(fmt, getprop('/instrumentation/'
820
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
821
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
822
                .setText(sprintf(fmt, getprop('/instrumentation/'
823
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
824
        }
825
        if (contains(arg[0], 'set')) {
826
            # positionne la valeur modifiée, les listeners "trigguent" en permanence ces propriétés, donc exit
827
            var n = getprop('/instrumentation/zkv1000/radios/' ~ arg[0]._r ~ '-tune');
828
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
829
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
830
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
831
        }
832
        if (contains(arg[0], 'auto')) {
833
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
834
            var radio = arg[0].auto;
835
            me._updateRadio({refresh: 1, _r: radio});
836
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
837
            settimer(func me._updateRadio({auto: radio}), 2);
838
        }
839
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
840
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
841

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
842
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
843
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
844
        # made active via menu
845
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
846
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
847
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
848
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
849
                me.screenElements['nav1-id']
850
                    .setColor(1,1,1);
851
                me.screenElements['nav2-id']
852
                    .setColor(1,1,1);
853
                me.screenElements['NAV1-pointer']
854
                    .hide();
855
                me.screenElements['NAV2-pointer']
856
                    .hide();
857
            }
858
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
859
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
860
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
861
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
862
                    .setColor(0,1,0);
863
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
864
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
865
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
866
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
867
#                me.screenElements['HDI']
868
#                    .setRotation();
869
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
870
#                    .hide();
871
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
872
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
873
#                        .hide();
874
            }
875
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
876
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
877
            # 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
878
            if (arg[0].val == nil)
879
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
880
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
881
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
882
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
883
        else {
884
            arg[0]._r = 'nav';
885
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
886
        }
887
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
888
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
889

            
890
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
891
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
892
        arg[0]._r = 'comm';
893
        me._updateRadio(arg[0]);
894
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
895
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
896

            
897
    updateTIME : func {
898
# updates the displayed time botoom left {{{
899
        me.screenElements['TIME-text']
900
            .setText(getprop('/sim/time/gmt-string'));
901
        settimer(func me.updateTIME(), 1);
902
    },
903
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
904

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
905
    updateXPDR : func {
906
# updates transponder display {{{
907
        for (var d = 0; d < 4; d+=1)
908
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
909
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
910
        var tuning = getprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit');
911
        if (tuning != nil)
912
            for (var d = 0; d < 4; d+=1) {
913
                if (d != tuning)
914
                    me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
915
                        .setColor(1,1,1);
916
                else
917
                    me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
918
                        .setColor(0,1,1);
919
            }
920
        else {
921
            if (getprop('/instrumentation/transponder/ident'))
922
                var mode = 'IDENT';
923
            else
924
                var mode = getprop('/instrumentation/zkv1000/radio/xpdr-mode');
925
            var wow = getprop('/gear/gear/wow');
926
            if (! wow and mode != 'STBY')
927
                var color = [0, 1, 0];
928
            else
929
                var color = [1, 1, 1];
930
            for (var d = 0; d < 4; d+=1)
931
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
932
                    .setColor(color);
933
            me.screenElements['XPDR-MODE-text']
934
                .setColor(color)
935
                .setText(mode);
936
        }
937
},
938
#}}}
939

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
940
    updateOAT : func {
941
# update OAT display on normal and reversionnary modes (every 3s) {{{
942
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
943
        me.screenElements['OAT-text']
944
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
945
        settimer(func me.updateOAT(), 3);
946
    },
947
    _oat_unit : 'c',
948
#}}}
949

            
950
    updateWindData : func {
951
# update the window text and arrows for OPTN1/2 {{{
952
        if (me._winddata_optn == 0)
953
            return;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
954
        if (me._updated_ias < 30) {
955
            me.screenElements['WindData-NODATA']
956
                .hide();
957
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
958
            var wind_spd = getprop('/environment/wind-speed-kt');
959
            var alpha = wind_hdg - me._updated_hdg;
960
            if (me._winddata_optn == 1) {
961
                me.screenElements['WindData-OPTN1-HDG']
962
                    .setRotation((alpha + 180) * D2R)
963
                    .show();
964
                me.screenElements['WindData-OPTN1-HDG-text']
965
                    .setText(sprintf("%03i°", wind_hdg))
966
                    .show();
967
                me.screenElements['WindData-OPTN1-SPD-text']
968
                    .setText(int(wind_spd) ~ 'KT')
969
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
970
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
971
            else { # me._winddata_optn == 2
972
                alpha *= D2R;
973
                var Vt = wind_spd * math.sin(alpha);
974
                var Ve = wind_spd * math.cos(alpha);
975
                if (Vt != 0) {
976
                    me.screenElements['WindData-OPTN2-crosswind-text']
977
                        .setText(sprintf('%i', abs(Vt)))
978
                        .show();
979
                    me.screenElements['WindData-OPTN2-crosswind']
980
                        .setScale(-abs(Vt)/Vt, 1)
981
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
982
                        .show();
983
                }
984
                if (Ve != 0) {
985
                    me.screenElements['WindData-OPTN2-headwind-text']
986
                        .setText(sprintf('%i', abs(Ve)))
987
                        .show();
988
                    me.screenElements['WindData-OPTN2-headwind']
989
                        .setScale(1, abs(Ve)/Ve)
990
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
991
                        .show();
992
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
993
            }
994
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
995
        else {
996
            foreach (var e; [
997
                    'WindData-OPTN1-HDG',
998
                    'WindData-OPTN1-HDG-text',
999
                    'WindData-OPTN1-SPD-text',
1000
                    'WindData-OPTN2-crosswind-text',
1001
                    'WindData-OPTN2-crosswind',
1002
                    'WindData-OPTN2-headwind-text',
1003
                    'WindData-OPTN2-headwind'
1004
            ])
1005
                me.screenElements[e].hide();
1006
            me.screenElements['WindData-NODATA'].show();
1007
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1008
        settimer(func me.updateWindData(), 0.5);
1009
    },
1010
    _winddata_optn : 0,
1011
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1012

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

            
1018
            var dev = radios.getNode(source).getValue();
1019
            var el  = 'BRG' ~ brg;
1020
            if (dev != 'OFF') {
1021
                var info = {
1022
                    pointer : nil,
1023
                    id : 'NO DATA',
1024
                    hdg : nil,
1025
                    dst : '--.-NM'
1026
                };
1027
                if (left(dev, 3) == 'NAV') {
1028
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1029
                    if (info.pointer) {
1030
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1031
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1032
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1033
                    }
1034
                }
1035
                elsif (dev == 'GPS') {
1036
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1037
                    if (info.pointer) {
1038
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1039
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1040
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1041
                    }
1042
                }
1043
                else { # there are 2 available ADF in FG, but instrument manage only 1
1044
                    info.pointer = getprop('/instrumentation/adf/in-range');
1045
                    if (info.pointer) {
1046
                        info.id  = getprop('/instrumentation/adf/ident');
1047
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1048
                    }
1049
                }
1050

            
1051
                if (info.pointer)
1052
                    me.screenElements[el ~ '-pointer']
1053
                        .setRotation(-info.hdg-me._updated_hdg * D2R)
1054
                        .show();
1055
                else
1056
                    me.screenElements[el ~ '-pointer']
1057
                        .hide();
1058
                me.screenElements[el ~ '-SRC-text']
1059
                    .setText(dev);
1060
                me.screenElements[el ~ '-DST-text']
1061
                    .setText(info.dst);
1062
                me.screenElements[el ~ '-WPID-text']
1063
                    .setText(info.id);
1064
                me.screenElements['BRG' ~ brg]
1065
                    .show();
1066
            }
1067
            else {
1068
                me.screenElements['BRG' ~ brg]
1069
                    .hide();
1070
            }
1071
        }
1072
        settimer(func me.updateBRG(), 1);
1073
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1074
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1075

            
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1076
    updateEIS : func {
1077
# displays Engine Informations System {{{
1078
        var power = getprop('/controls/engines/engine/throttle') * getprop('/engines/engine/running');
1079
        me.screenElements['POWER-pointer']
1080
            .setRotation(D2R * 140 * power);
1081
        me.screenElements['POWER-PERCENT-text']
1082
            .setText(sprintf('%u', power));
1083
        me.screenElements['RPM-text']
1084
            .setText(sprintf(math.round(getprop('/engines/engine/rpm'), 50)));
1085
        me.screenElements['MAN-Hg-text']
1086
            .setText(sprintf('%.1d', getprop('/engines/engine/mp-inhg')));
1087
        me.screenElements['FUEL-FLOW-text']
1088
            .setText(sprintf('%.1f', getprop('/engines/engine/fuel-flow-gph')));
1089
        if (math.mod(me._eis_count, 10) == 0) {
1090
            var psi = getprop('/engines/engine/oil-pressure-psi');
1091
            me.screenElements['PSI-text']
1092
                .setText(psi == nil ? '--' : sprintf('%u', psi));
1093
            me.screenElements['OIL-TEMP-text']
1094
                .setText(sprintf('%i', getprop('/engines/engine/oil-temperature-degf')));
1095
            var used_fuel = getprop('/instrumentation/zkv1000/eis/fuel-qty-at-start')
1096
                          - getprop('/consumables/fuel/tank/level-gal_us')
1097
                          - getprop('/consumables/fuel/tank[1]/level-gal_us');
1098
            me.screenElements['FUEL-USED-text']
1099
                .setText(sprintf('%.1d', used_fuel > 0 ? used_fuel : 0));
1100
            me.screenElements['BUS-V-text']
1101
                .setText(sprintf('%.1i', getprop('/systems/electrical/outputs/bus')));
1102
            me.screenElements['BATT-text']
1103
                .setText(sprintf('%+i', getprop('/systems/electrical/amps')));
1104
            var cht = getprop('/engines/engine/cht-degf');
1105
            me.screenElements['CHT-text']
1106
                .setText(cht == nil ? '--' : sprintf('%i', cht));
1107
            me.screenElements['EGT-text']
1108
                .setText(sprintf('%i', getprop('/engines/engine/egt-degf')));
1109
        }
1110
        settimer(func me.updateEIS(), 1);
1111
        me._eis_count += 1;
1112
    },
1113
    _eis_count : 0,
1114
#}}}
1115
};
1116

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1117
var keyMap = {
add new vim folds
Sébastien MARQUE authored on 2017-03-15
1118
# softkeys map for PFD and MFD {{{
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1119
    PFD : {
1120
        first : 1,
1121
        texts : ['INSET', 'SENSOR', 'PFD', 'OBS', 'CDI', 'DME', 'XPDR', 'IDENT', 'TMR/REF', 'NRST' ],
1122
        INSET : {
1123
            texts : ['OFF', 'DCLTR', 'WXLGND', 'TRAFFIC', 'TOPO', 'TERRAIN', 'STRMSCP', 'NEXRAD-C', 'XM LTNG', 'METAR'],
1124
        },
1125
        SENSOR : {
1126
            first : 2,
1127
            texts : [ 'ADC1', 'ADC2', '', 'AHRS1', 'AHRS2'],
1128
        },
1129
        PFD : {
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1130
            texts : [ 'SYN VIS', 'DFLTS', 'AOA/WIND', 'DME', 'BRG1', 'HSI FMT', 'BRG2', '', 'ALT UNIT', 'STD BARO' ],
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1131
            'SYN VIS' : {
1132
                texts : [ 'PATHWAY', 'SYN TERR', 'HR2NHDG', 'APTSIGNS', 'FPM'],
1133
            },
1134
            'AOA/WIND' : {
1135
                first : 4,
1136
                texts : ['AOA', 'WIND'],
1137
                AOA : {
1138
                    first : 5,
1139
                    texts : ['AOA ON', 'AOA AUTO'],
1140
                },
1141
                WIND : {
1142
                    first : 2,
1143
                    texts : ['OPTN1', 'OPTN2', '', 'OFF'],
1144
                },
1145
            },
1146
            'HSI FMT' : {
1147
                first : 6,
1148
                texts : ['360 HSI', 'ARC HSI'],
1149
            },
1150
            'ALT UNIT' : {
1151
                first : 5,
1152
                texts : ['METERS', '', 'IN', 'HPA'],
1153
            },
1154
        },
1155
        XPDR : {
1156
            first : 2,
1157
            texts : ['STBY', 'ON', 'ALT', '', 'VFR', 'CODE', 'IDENT'],
1158
            CODE : {
1159
                texts : ['0', '1', '2', '3', '4', '5', '6', '7', 'IDENT', 'BKSP'],
1160
            },
1161
        },
1162
    },
1163
    MFD : {
1164
        texts : ['ENGINE', '', 'MAP', '', '', '', '', '', '', 'DCLTR', 'SHW CHRT', 'CHKLIST'],
1165
        MAP : {
1166
            texts: ['TRAFFIC', 'PROFILE', 'TOPO', 'TERRAIN', 'AIRWAYS', 'STRMSCP','NEXRAD-C', 'XM LTNG', 'METAR', 'LEGEND', 'BACK'],
1167
        },
1168
        CHKLIST : {
1169
            texts : ['ENGINE', '', '', '', '', 'DONE', '', '', '', '', 'EXIT', 'EMERGCY'],
1170
        },
1171
        ENGINE : {
1172
            texts : ['ENGINE', 'ANTI-ICE', '', 'DCLTR', '', 'ASSIST', '', '', '', '', 'FUEL'],
1173
            'ANTI-ICE' : {
1174
                texts : ['LEFT', 'AUTO', 'RIGHT', '', '', '', '', '', '', '', '', 'BACK'],
1175
            },
1176
            FUEL : {
1177
                first : 1,
1178
                texts : ['FULL', 'TABS', '', '', '', '', '', '', '', 'UNDO', 'ENTER'],
1179
            },
1180
        },
1181
    },
1182
};
add new vim folds
Sébastien MARQUE authored on 2017-03-15
1183
#}}}