zkv1000 / Nasal / display.nas /
Newer Older
1366 lines | 52.692kb
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1
# vim: set foldmethod=marker foldmarker={{{,}}} :
commit initial
Sébastien MARQUE authored on 2017-03-07
2
var displayClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
3
    new: func(device) {
add new vim folds
Sébastien MARQUE authored on 2017-03-15
4
# the contructor {{{
commit initial
Sébastien MARQUE authored on 2017-03-07
5
        var m = { parents: [ displayClass ] };
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
6

            
commit initial
Sébastien MARQUE authored on 2017-03-07
7
        m.display = canvas.new({
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
8
                "name"      : device.name,
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
9
                "size"      : [1280, 1280],
10
                "view"      : [1024, 768],
commit initial
Sébastien MARQUE authored on 2017-03-07
11
                "mipmapping": 1
12
        });
13
        m.display.addPlacement({
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
14
                "node": device.data['screen-object'] != nil ? device.data['screen-object'] : "Screen",
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
15
                "parent": device.name
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
16
            });
commit initial
Sébastien MARQUE authored on 2017-03-07
17
        m.display.setColorBackground(0,0,0);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
18
        m.role = device.role;
pass device pointer to displ...
Sébastien MARQUE authored on 2017-03-14
19
        m.device = device;
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
20
        m.screenElements = {};
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
21
        m.screen = m.display
22
            .createGroup()
23
            .show();
commit initial
Sébastien MARQUE authored on 2017-03-07
24

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

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
30
        var groups = {
31
            show : [
32
                'Header',
33
                'SoftKeysTexts',
34
                'COMM',
35
                'NAV',
36
                'nav-freq-switch',
37
                'comm-freq-switch',
38
            ],
39
            text: [
40
                'nav1-standby-freq', 'nav1-selected-freq', 'nav1-id',
41
                'nav2-standby-freq', 'nav2-selected-freq', 'nav2-id',
42
                'comm1-standby-freq', 'comm1-selected-freq',
43
                'comm2-standby-freq', 'comm2-selected-freq',
44
            ],
45
            hide : [ 'Failures', 'NAV-COMM-Failures' ],
46
            clip: [ ],
47
        };
48

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

            
cosmetics
Sébastien MARQUE authored on 2020-05-12
54
        if (m.device.role == 'PFD') {
55
            append(groups.show,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
56
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
57
                'XPDR-TIME',
58
                'FlightInstruments',
59
                'Horizon',
60
                'bankPointer',
61
                'VSI',
62
                'Rose',
63
                'Heading-bug',
64
                'PFD-Widgets',
65
                'Trends',
66
                'Airspeed-Trend-Indicator',
67
                'Altitude-Trend-Indicator',
68
                'OAT',
69
                'IAS-bg',
70
                'TAS',
71
                'GSPD',
72
                'BARO-bg',
73
                'SlipSkid',
74
                'IAS-Vx', 'IAS-Vy', 'IAS-Vr', 'IAS-Vglide',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
75
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
76
            );
77
            append(groups.hide,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
78
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
79
                'EIS',
80
                'CDI',
81
                'OMI', 'MarkerBG', 'MarkerText',
82
                'VDI',
83
                'NAV1-pointer', 'NAV1-CDI', 'NAV1-FROM', 'NAV1-TO',
84
                'NAV2-pointer', 'NAV2-CDI', 'NAV2-FROM', 'NAV2-TO',
85
                'GPS-pointer', 'GPS-CDI', 'GPS-CTI', 'GPS-CTI-diamond', 'GPS-FROM', 'GPS-TO',
86
                'BRG1-pointer',
87
                'BRG2-pointer',
88
                'SelectedHDG-bg',
89
                'SelectedHDG-bgtext',
90
                'SelectedHDG-text',
91
                'SelectedCRS-bg',
92
                'SelectedCRS-bgtext',
93
                'SelectedCRS-text',
94
                'SelectedALT', 'SelectedALT-bug', 'SelectedALT-bg', 'SelectedALT-symbol',
95
                'TAS',
96
                'GSPD',
97
                'WindData',
98
                'Reversionnary',
99
                'Annunciation',
100
                'Comparator',
101
                'BRG1',
102
                'BRG2',
103
                'DME1',
104
                'PFD-Map-bg',
105
                'PFD-Multilines',
106
                'MapOrientation',
107
                'WindData', 'WindData-OPTN1', 'WindData-OPTN2', 'WindData-OPTN1-HDG', 'WindData-OPTN2-symbol', 'WindData-OPTN2-headwind', 'WindData-OPTN2-crosswind', 'WindData-NODATA',
108
                'AOA', 'AOA-needle', 'AOA-text', 'AOA-approach',
109
                'MFD-navbox',
110
                'Traffic',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
111
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
112
            );
113
            append(groups.clip,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
114
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
115
                'SpeedLint1',
116
                'SpeedTape',
117
                'LintAlt',
118
                'AltLint00011',
119
                'PitchScale',
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
120
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
121
            );
122
            append(groups.text,
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
123
# {{{
cosmetics
Sébastien MARQUE authored on 2020-05-12
124
                'SelectedALT-text',
125
                'TAS-text',
126
                'GSPD-text',
127
                'TIME-text',
128
                'OAT-text',
129
                'VSIText',
130
                'Speed110',
131
                'Alt11100',
132
                'HDG-text',
133
                'BARO-text',
134
                'CDI-SRC-text', 'CDI-GPS-ANN-text', 'CDI-GPS-XTK-text',
135
                'BRG1-pointer', 'BRG1-SRC-text', 'BRG1-DST-text', 'BRG1-WPID-text',
136
                'BRG2-pointer', 'BRG2-SRC-text', 'BRG2-DST-text', 'BRG2-WPID-text',
137
                'WindData-OPTN1-HDG-text', 'WindData-OPTN1-SPD-text',
138
                'WindData-OPTN2-crosswind-text', 'WindData-OPTN2-headwind-text',
139
                'XPDR-MODE-text', 'XPDR-DIGIT-3-text', 'XPDR-DIGIT-2-text', 'XPDR-DIGIT-1-text', 'XPDR-DIGIT-0-text',
140
                'ETE', 'ETE-text', 'DIS', 'DIS-text', 'LEG-text',
141
                'LATMOD-Armed-text', 'LATMOD-Active-text',
142
                'AP-Status-text', 'YD-Status-text',
143
                'VERMOD-Active-text', 'VERMOD-Armed-text', 'VERMOD-Reference-text',
144
                'AltBigC', 'AltSmallC'
adds some vim z-folds
Sébastien MARQUE authored on 2017-04-19
145
# }}}
cosmetics
Sébastien MARQUE authored on 2020-05-12
146
            );
147
            for (var place = 1; place <= 6; place +=1) {
148
                append(groups.text,
149
                    'AltBigU' ~ place,
150
                    'AltSmallU' ~ place,
151
                    'AltBigD' ~ place,
152
                    'AltSmallD' ~ place
séparation configuration PFD...
Sébastien MARQUE authored on 2017-03-12
153
                );
animation ALT
Sébastien MARQUE authored on 2017-03-11
154
            }
cosmetics
Sébastien MARQUE authored on 2020-05-12
155
            canvas.parsesvg(m.screen, data.zkv1000_reldir ~ 'Models/PFD.svg');
156
        }
157
        else {
158
            var eis_file = eis.getValue('type');
159
            if (eis_file == nil)
160
                eis_file = eis.getValue('file');
161

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

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

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

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

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

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

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

            
217
        m.navbox = {
218
# {{{ the data to show info in navbox
219
            DTK: [func {
220
                var dtk = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
221
                if (dtk == nil)
222
                    return '---°';
223
                else
224
                    return sprintf('%03i°', dtk);
225
            }, 'Desired Track'],
226
            ETE: [func {
227
                if (data.fpSize == 0) return '--:--';
228
                var eta = getprop('/autopilot/route-manager/wp/eta');
229
                return sprintf('%5s', eta != nil ? eta : '--:--');
230
            }, 'Estimated Time Enroute'],
231
            TDR: [func {
232
                if (data.fpSize == 0) return '---NM';
233
                var dist = getprop('/autopilot/route-manager/distance-remaining-nm');
234
                if (dist != nil)
235
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
236
                else
237
                    return '---NM';
238
            }, 'Total Distance Remaining'],
239
            DIS: [func {
240
                if (data.fpSize == 0) return '---NM';
241
                var dist = getprop('/autopilot/route-manager/wp/dist');
242
                if (dist != nil)
243
                    return sprintf(dist < 100 ? '%2.1fNM' : '%3iNM', dist);
244
                else
245
                    return '---NM';
246
            }, 'Distance remaining'],
247
            LEG: [func {
248
                if (data.fpSize == 0) return '';
249
                var route = m.device.map.layers.route;
250
                var wp = route.flightPlan[route.currentLeg.index];
251
                return sprintf(' %s %s %s', wp[0].name, utf8.chstr(9658), wp[1].name);
252
            }, ''], # not listed in MFD menu, on PFD only the leg is shown not the item
253
            LDG: [func {
254
                var eteSeconds = getprop('/autopilot/route-manager/ete');
255
                var eteHours = math.floor(eteSeconds / 3600);
256
                var eteMinutes = int((eteSeconds - (eteHours * 3600)) / 60);
257
                return sprintf(eteHours > 99 ? '--:--' : '%02i:%02i', eteHours, eteMinutes);
258
            }, 'ETA at Final Destination'],
259
            END: [func {
260
                var total_fuel = getprop('/consumables/fuel/total-fuel-gals');
261
                var gs = getprop('/velocities/groundspeed-kt');
262
                var consumption = 0;
263
                foreach(var engine; props.globals.getNode('/engines').getChildren('engine')) {
264
                    var ec = engine.getValue('fuel-flow-gph');
265
                    consumption += ec != nil ? ec : 0;
266
                }
267
                if (consumption > 0 and gs > 0)
268
                    return sprintf('%3iNM', (total_fuel * gs) / consumption);
269
                else
270
                    return '---NM';
271
            }, 'Endurance'],
272
            ETA: [func {
273
                var eteSeconds = getprop('/autopilot/route-manager/ete');
274
                var eta_hours = getprop('/sim/time/utc/hour');
275
                var eteHours = math.floor(eteSeconds / 3600);
276
                if (eteHours > 12)
277
                    return '--:--';
278
                var eta_minutes = int((eteSeconds - (eteHours * 3600)) / 60) + getprop('/sim/time/utc/minute');
279
                if (eta_minutes > 59) {
280
                    eta_minutes -= 60;
281
                    eta_hours += 1;
282
                }
283
                eta_hours += eteHours;
284
                if (eta_hours > 23)
285
                    eta_hours -= 24;
286
                return sprintf('%02i:%02i', eta_hours, eta_minutes);
287
            }, 'Estimated Time of Arrival'],
288
            GS:  [func return sprintf('%3iKT', getprop('/velocities/groundspeed-kt')), 'Ground Speed'],
289
            TRK: [func return sprintf('%03i°', getprop('/orientation/track-deg')), 'Track'],
290
            TAS: [func return sprintf('%i', getprop('/instrumentation/airspeed-indicator/true-speed-kt')), 'True Air Speed'],
291
            FOB: [func { return sprintf('%3ilbs', getprop('/consumables/fuel/total-fuel-lbs')); }, 'Fuel on Board'],
292
#            BRG: [func return '---°', 'Bearing'],
293
#            ESA: [func return '-----', 'Enroute Safe Altitude'],
294
#            ISA: [func return '-----', 'ISA Relative Temperature'],
295
#            MSA: [func return '----ft', 'Minimum Safe Altitude'],
296
#            TKE: [func return ' ---°', 'Track Angle Error'],
297
#            VSR: [func return ' ----', 'Vertical Speed Required'],
298
#            XTK: [func return ' ---NM', 'Crosstrack Error'],
299
# }}}
300
        };
301
        if (m.device.role == 'PFD')
302
            foreach (var item; keys(m.navbox))
303
                if (item != 'LEG' and item != 'DIS' and item != 'ETE')
304
                    delete(m.navbox, item);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
305
        return m;
306
    },
307
#}}}
makes map available for PFD ...
Sébastien MARQUE authored on 2017-04-19
308

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
309
    off: func {
310
        foreach(var timer; keys(me.timers2)) {
311
            me.timers2[timer].stop();
312
            delete(me.timers2, timer);
313
        }
314
        me.screen.del();
315
        me.display.del();
316
    },
317

            
318
# temporary Widget Display for HDG and CRS modification {{{
319

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

            
322
    timerTrigger : func {
323
        var now = systime();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
324
        foreach (var id; keys(me.temporaryWidgetDisplay)) {
325
            if (me.temporaryWidgetDisplay[id] < now) {
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
326
                me.screenElements[id].hide();
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
327
                delete(me.temporaryWidgetDisplay, id);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
328
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
329
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
330
    },
331

            
332
    addTimer : func (duration, element) {
333
        if (typeof(element) == 'scalar')
334
            element = [ element ];
335
        var end = systime() + duration;
336
        foreach (var e; element)
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
337
            me.temporaryWidgetDisplay[e] = end;
commit initial
Sébastien MARQUE authored on 2017-03-07
338
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
339
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
340

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
341
    showInitProgress : func {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
342
#{{{
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
343
        if (me.device.role == 'PFD') {
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
344
            me.timers.updateAI     = maketimer(0.1, me, me.updateAI     );
345
            me.timers.updateVSI    = maketimer(0.1, me, me.updateVSI    );
346
            me.timers.updateIAS    = maketimer(0.1, me, me.updateIAS    );
347
            me.timers.updateALT    = maketimer(0.2, me, me.updateALT    );
348
            me.timers.updateHSI    = maketimer(0.2, me, me.updateHSI    );
349
            me.timers.updateTIME   = maketimer(1.0, me, me.updateTIME   );
350
            me.timers.updateOAT    = maketimer(3.0, me, me.updateOAT    );
351
            me.timers.updateTAS    = maketimer(0.5, me, me.updateTAS    );
352
            me.timers.updateBRG    = maketimer(0.5, me, me.updateBRG    );
353
            me.timers.updateXPDR   = maketimer(0,   me, me.updateXPDR   ); me.timers.updateXPDR.singleShot=1;
354
            me.timers.updateBARO   = maketimer(0,   me, me.updateBARO   ); me.timers.updateBARO.singleShot=1;
355
            me.timers.updateOMI    = maketimer(1.0, me, me.updateOMI    );
356
            me.timers.timerTrigger = maketimer(1.0, me, me.timerTrigger );
357

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
358
            me.screen.show();
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
359
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
360
        }
361
        else {
362
            me.updateEIS();
363
            io.load_nasal(data.zkv1000_dir ~ 'Nasal/MFD.pages.nas', 'zkv1000');
364
            me['page selected'] = 0;
365
            me.setMFDPages();
366
            me.device.buttons.MENU = me.device.buttons.MapMenu;
367
        }
commit initial
Sébastien MARQUE authored on 2017-03-07
368

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

            
375
        foreach (var timer; keys(me.timers))
376
            me.timers[timer].start();
commit initial
Sébastien MARQUE authored on 2017-03-07
377
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
378
#}}}
commit initial
Sébastien MARQUE authored on 2017-03-07
379

            
some added comments
Sébastien MARQUE authored on 2017-03-18
380
    colors : {
381
# set of predefined colors {{{
382
        green : [0, 1, 0],
383
        white : [1, 1, 1],
384
        black : [0, 0, 0],
385
        lightblue : [0, 1, 1],
386
        darkblue : [0, 0, 1],
387
        red : [1, 0, 0],
adds CDI
Sébastien MARQUE authored on 2017-03-18
388
        magenta : [1, 0, 1],
add yellow predefined color
Sébastien MARQUE authored on 2020-05-11
389
        yellow : [1, 1, 0],
some added comments
Sébastien MARQUE authored on 2017-03-18
390
    },
391
#}}}
392

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
393
    loadGroup : func (h) {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
394
#{{{
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
395
        if (typeof(h) != 'hash') {
396
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
397
                    caller(0)[0],
398
                    typeof(h),
399
                    caller(1)[0]));
400
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
401
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
402
        var setMethod = func (e, t) {
403
            if (t == 'hide')
404
                me.screenElements[e].hide();
405
            elsif (t == 'show')
406
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
407
            elsif (t == 'rot' or t == 'trans') {
408
                if (! contains(me.screenElements[e], t))
409
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
410
            }
411
            elsif (t == 'clip') {
412
                if (contains(me.clips, e))
413
                    me.screenElements[e].set("clip", me.clips[e]);
414
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
415
                    logprint(LOG_WARN, 'no defined clip for ' ~ e);
AI disponible
Sébastien MARQUE authored on 2017-03-10
416
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
417
            elsif (t == 'text') {
418
                if (contains(me.texts, e)) {
419
                    if (contains(me.texts[e], 'alignment'))
420
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
421
                    if (contains(me.texts[e], 'default'))
422
                        me.screenElements[e].setText(me.texts[e].default);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
423
                    if (contains(me.texts[e], 'color'))
424
                        me.screenElements[e].setColor(me.texts[e].color);
adds CDI
Sébastien MARQUE authored on 2017-03-18
425
                    if (contains(me.texts[e], 'visible'))
426
                        me.screenElements[e].setVisible(me.texts[e].visible);
animation VSI
Sébastien MARQUE authored on 2017-03-10
427
                }
printlog with adapted level ...
Sébastien MARQUE authored on 2017-03-20
428
                else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
429
                    logprint(LOG_DEBUG, 'no text format for ' ~ e);
animation VSI
Sébastien MARQUE authored on 2017-03-10
430
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
431
            else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
432
                logprint(LOG_WARN, 'unknown method ' ~ t);
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
433
        };
434
        foreach (var todo; keys(h)) {
435
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
436
            foreach (var id; h[todo]) {
437
                if (! contains(me.screenElements, id)) {
438
                    me.screenElements[id] = me.screen.getElementById(id);
439
                    if (me.screenElements[id] != nil)
440
                        setMethod(id, todo);
441
                    else
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
442
                        logprint(LOG_WARN, 'SVG ID ' ~ id ~ ' not found');
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
443
                }
444
                else
445
                    setMethod(id, todo);
446
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
447
        }
448
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
449
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
450

            
451
    clips : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
452
#{{{
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
453
        PitchScale   : "rect(70,664,370,256)",
454
        SpeedLint1   : "rect(252,226,318,204)",
455
        SpeedTape    : "rect(115,239,455,156)",
456
        LintAlt      : "rect(115,808,455,704)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
457
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
458
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
459
#}}}
AI disponible
Sébastien MARQUE authored on 2017-03-10
460

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
461
    texts : {
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
462
#{{{
animation VSI
Sébastien MARQUE authored on 2017-03-10
463
        VSIText : {
464
            alignment: "right-bottom", default : num('0'),
465
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
466
        Speed110 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
467
            alignment : 'right-bottom'
animation IAS
Sébastien MARQUE authored on 2017-03-10
468
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
469
        Alt11100 : {
correct speed and altitude t...
Sébastien MARQUE authored on 2020-05-08
470
            alignment:'right-bottom'
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
471
        },
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
472
        "HDG-text" : {
473
            default: '---°'
474
        },
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
475
        'nav1-standby-freq' : {
476
            color: [0, 1, 1],
477
        },
478
        'nav1-id' : {
479
            default: ''
480
        },
481
        'nav2-id' : {
482
            default: ''
483
        },
adds CDI
Sébastien MARQUE authored on 2017-03-18
484
        'CDI-GPS-ANN-text' : {
485
            visible : 0
486
        },
487
        'CDI-GPS-XTK-text' : {
488
            visible : 0
489
        },
490
        'CDI-SRC-text' : {
491
            visible : 0
492
        },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
493
        'BARO-text' : {
494
            alignment : 'left-bottom',
improve route info display
Sébastien MARQUE authored on 2020-05-03
495
        },
496
        'LEG-text' : {
497
            alignment : 'center-center',
498
        },
some added comments
Sébastien MARQUE authored on 2017-03-18
499
#        'TAS-text' : {
500
#            alignment : 'right-bottom',
501
#        },
502
#        'GSPD-text' : {
503
#            alignment : 'right-bottom',
504
#        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
505
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
506
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
507

            
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
508
    softkeys_inactivity : func {
509
# automagically back to previous level after some delay {{{
510
        me.timers2.softkeys_inactivity = maketimer (
511
            me.softkeys_inactivity_delay,
512
            func {
513
                pop(me.device.softkeys.path);
514
                me.updateSoftKeys();
515
            }, me);
516
        me.timers2.softkeys_inactivity.singleShot = 1;
517
    },
518
#}}}
519

            
softkey is implemented by de...
Sébastien MARQUE authored on 2017-12-21
520
    setSoftKeyColor : func (n, active, implemented = 1, alert = 0) {
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
521
# set colors for active softkeys {{{
522
        var sftk = sprintf('SoftKey%02i-', n);
523
        if (active) {
524
            var bg = alert ? 1 : 0.5;
525
            me.screenElements[sftk ~ 'bg']
526
                .setColorFill(bg,bg,bg);
527
            me.screenElements[sftk ~ 'text']
528
                .setColor(0,0,0);
529
        }
530
        else {
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
531
            var tc = implemented ? 1 : 0.5;
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
532
            me.screenElements[sftk ~ 'bg']
533
                .setColorFill(0,0,0);
534
            me.screenElements[sftk ~ 'text']
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
535
                .setColor(tc,tc,tc);
add softkeys colors
Sébastien MARQUE authored on 2017-03-21
536
        }
537
    },
538
#}}}
539

            
navigation box content
Sébastien MARQUE authored on 2020-05-12
540
    updateNavigationBox : func {
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
541
# update Navigation Box on MFD and PFD header {{{
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
542
        var enroute = getprop('/autopilot/route-manager/current-wp') > -1;
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
543
        var route = me.device.map.layers.route;
navigation box content
Sébastien MARQUE authored on 2020-05-12
544
        data.fpSize = size(route.flightPlan);
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
545
        if (me.device.role == 'MFD') {
546
            for (var i=1; i<=4; i+=1)
547
                me.screenElements['DATA-FIELD' ~ i ~ '-VAL-text']
improve route info display
Sébastien MARQUE authored on 2020-05-03
548
                    .setVisible(enroute)
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
549
                    .setText(
navigation box content
Sébastien MARQUE authored on 2020-05-12
550
                        me.navbox[me.screenElements['DATA-FIELD' ~ i ~ '-ID-text'].setVisible(enroute).get('text')][0]()
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
551
                    );
552
        }
553
        else { # PFD
improve route info display
Sébastien MARQUE authored on 2020-05-03
554
            me.screenElements['ETE'].setVisible(enroute);
555
            me.screenElements['DIS'].setVisible(enroute);
navigation box content
Sébastien MARQUE authored on 2020-05-12
556
            me.screenElements['ETE-text'].setVisible(enroute).setText(me.navbox.ETE[0]());
557
            me.screenElements['DIS-text'].setVisible(enroute).setText(me.navbox.DIS[0]());
558
            me.screenElements['LEG-text'].setVisible(enroute).setText(me.navbox.LEG[0]());
add navigation infos on head...
Sébastien MARQUE authored on 2017-05-24
559
        }
560
    },
561
#}}}
562

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
563
    updateSoftKeys : func {
564
# update SoftKeys boxes {{{
565
        # on PFD the last boxes are always BACK and ALERTS
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
566
        if (me.device.role == 'PFD') {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
567
            me.screenElements[sprintf("SoftKey%02i-text", 11)]
568
                .setText('ALERTS');
569
            if (size(me.device.softkeys.path) != 0)
570
                me.screenElements[sprintf("SoftKey%02i-text", 10)]
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
571
                    .setText('BACK')
572
                    .setColor(1,1,1);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
573
        }
574

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
575
        var path = keyMap[me.device.role];
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
576
        var bindings = me.device.softkeys.bindings[me.device.role];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
577
        var pathid = '';
578
        foreach (var p; me.device.softkeys.path) {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
579
            path = path[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
580
            pathid ~= p;
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
581
            if (contains(bindings, p))
582
                bindings = bindings[p];
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
583
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
584

            
585
        # feeding with empty menus the first boxes
586
        var start = (contains(path, 'first')) ? path.first : 0;
587
        for (var k = 0; k < start; k+=1) {
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
588
            var sftk = sprintf("SoftKey%02i-", k);
589
            me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
590
                .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
591
            me.screenElements[sftk ~ 'bg']
592
                .setColorFill(0,0,0);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
593
        }
594
        # filling with the content the next boxes
595
        forindex (var k; path.texts) {
596
            var i = k + start;
597
            me.screenElements[sprintf("SoftKey%02i-text", i)]
598
                .setText(path.texts[k]);
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
599
            me.setSoftKeyColor(i,
not yet implemented softkeys...
Sébastien MARQUE authored on 2017-06-08
600
                    contains(me.device.softkeys.colored, pathid ~ path.texts[k]),
601
                    contains(bindings, path.texts[k]));
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
602
        }
603
        # feeding the last boxes with empty string
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
604
        var end = (me.device.role == 'PFD') ? 10 : 12;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
605
        if (size(path.texts) + start < end) {
606
            start = size(path.texts) + start;
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
607
            for (var k = start; k < end; k += 1) {
608
                var sftk = sprintf("SoftKey%02i-", k);
609
                me.screenElements[sftk ~ 'text']
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
610
                    .setText('');
improves softkeys coloring
Sébastien MARQUE authored on 2017-04-15
611
                me.screenElements[sftk ~ 'bg']
612
                    .setColorFill(0,0,0);
613
            }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
614
        }
Softkeys revert to the previ...
Sébastien MARQUE authored on 2017-03-21
615

            
616
        if (size(me.device.softkeys.path))
617
            me.timers2.softkeys_inactivity.restart(me.softkeys_inactivity_delay);
618
        else
619
            me.timers2.softkeys_inactivity.stop();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
620
    },
621
#}}}
622

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
623
    updateAI: func(){
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
624
#{{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
625
        var pitch = data.pitch;
626
        var roll = data.roll;
AI disponible
Sébastien MARQUE authored on 2017-03-10
627
        if (pitch > 80)
628
            pitch = 80;
clean pre-merge
Sébastien MARQUE authored on 2017-03-11
629
        elsif (pitch < -80)
AI disponible
Sébastien MARQUE authored on 2017-03-10
630
            pitch = -80;
631
        me.screenElements.Horizon
fix AI animation
Sébastien MARQUE authored on 2017-03-19
632
            .setCenter(459, 282.8 - 6.849 * pitch)
AI disponible
Sébastien MARQUE authored on 2017-03-10
633
            .setRotation(-roll * D2R)
fix AI animation
Sébastien MARQUE authored on 2017-03-19
634
            .setTranslation(0, pitch * 6.849);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
635
        me.screenElements.bankPointer
636
            .setRotation(-roll * D2R);
adds slipskid animation
Sébastien MARQUE authored on 2017-03-24
637
        me.screenElements['SlipSkid']
638
            .setTranslation(getprop("/instrumentation/slip-skid-ball/indicated-slip-skid") * 10, 0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
639
        me.screenElements['Traffic']
640
            .setVisible(size(data.tcas));
AI disponible
Sébastien MARQUE authored on 2017-03-10
641
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
642
#}}}
animation VSI
Sébastien MARQUE authored on 2017-03-10
643

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
644
    updateVSI: func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
645
# animate VSI {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
646
        var vsi = data.vsi;
animation VSI
Sébastien MARQUE authored on 2017-03-10
647
        me.screenElements.VSIText
648
            .setText(num(math.round(vsi, 10)));
649
        if (vsi > 4500)
650
            vsi = 4500;
651
        elsif (vsi < -4500)
652
            vsi = -4500;
653
        me.screenElements.VSI
654
            .setTranslation(0, vsi * -0.03465);
655
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
656
#}}}
animation IAS
Sébastien MARQUE authored on 2017-03-10
657

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

            
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
691
        var Sy = 0;
692
        for (var i = 8; i >= 0; i -= 1)
693
            me._last_ias_Sy[i+1] = me._last_ias_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
694
        var now = systime();
695
        # estimated speed in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
696
        me._last_ias_Sy[0] = 6 * (ias - me._last_ias_kt) / (now - me._last_ias_s);
697
        foreach (var _Sy; me._last_ias_Sy)
698
            Sy += _Sy;
699
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
700
        if (abs(Sy) > 30)
701
            Sy = 30 * abs(Sy)/Sy; # = -30 or 30
702
        me.screenElements['Airspeed-Trend-Indicator']
703
            .setScale(1,Sy)
704
            .setTranslation(0, -284.5 * (Sy - 1));
705
        me._last_ias_kt = ias;
706
        me._last_ias_s = now;
animation IAS
Sébastien MARQUE authored on 2017-03-10
707
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
708
    _last_ias_kt : 0,
709
    _last_ias_s : systime(),
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
710
    _last_ias_Sy : [0,0,0,0,0,0,0,0,0,0],
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
711
    _ias_already_exceeded : 0,
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
712
#}}}
animation ALT
Sébastien MARQUE authored on 2017-03-11
713

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
714
    updateTAS: func {
715
# updates the True Airspeed and GroundSpeed indicators {{{
716
        me.screenElements['TAS-text']
717
            .setText(sprintf('%iKT', getprop('/instrumentation/airspeed-indicator/true-speed-kt')));
718
        me.screenElements['GSPD-text']
719
            .setText(sprintf('%iKT', getprop('/velocities/groundspeed-kt')));
720
    },
721
#}}}
722

            
723
    updateALT: func () {
724
# animates the altitude lint (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
725
        var alt = data.alt;
animation ALT
Sébastien MARQUE authored on 2017-03-11
726
        if (alt < 0)
727
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
728
                .setText(sprintf("%3d",math.ceil(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
729
        elsif (alt < 100)
730
            me.screenElements.Alt11100
731
                .setText('');
732
        else
733
            me.screenElements.Alt11100
fix altitude indicator
Sébastien MARQUE authored on 2020-05-03
734
                .setText(sprintf("%3i",math.floor(alt/100)));
animation ALT
Sébastien MARQUE authored on 2017-03-11
735
        me.screenElements.AltLint00011
736
            .setTranslation(0,math.fmod(alt,100) * 1.24);
737

            
738
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
739
        if (alt> -1000 and alt< 1000000) {
740
            var Offset10 = 0;
741
            var Offset100 = 0;
742
            var Offset1000 = 0;
743
            if (alt< 0) {
744
                var Ne = 1;
745
                var alt= -alt;
746
            }
747
            else
748
                var Ne = 0;
749

            
750
            var Alt10       = math.mod(alt,100);
751
            var Alt100      = int(math.mod(alt/100,10));
752
            var Alt1000     = int(math.mod(alt/1000,10));
753
            var Alt10000    = int(math.mod(alt/10000,10));
754
            var Alt20       = math.mod(Alt10,20)/20;
755
            if (Alt10 >= 80)
756
                var Alt100 += Alt20;
757

            
758
            if (Alt10 >= 80 and Alt100 >= 9)
759
                var Alt1000 += Alt20;
760

            
761
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
762
                var Alt10000 += Alt20;
763

            
764
            if (alt> 100)
765
                var Offset10 = 100;
766

            
767
            if (alt> 1000)
768
                var Offset100 = 10;
769

            
770
            if (alt> 10000)
771
                var Offset1000 = 10;
772

            
773
            if (!Ne) {
774
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
775
                var altCentral = (int(alt/100)*100);
776
            }
777
            elsif (Ne) {
778
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
779
                var altCentral = -(int(alt/100)*100);
780
            }
781
            me.screenElements["AltBigC"].setText("");
782
            me.screenElements["AltSmallC"].setText("");
783
            for (var place = 1; place <= 6; place += 1) {
784
                var altUP = altCentral + (place*100);
785
                var offset = -30.078;
786
                if (altUP < 0) {
787
                    var altUP = -altUP;
788
                    var prefix = "-";
789
                    var offset += 15.039;
790
                }
791
                else
792
                    var prefix = "";
793

            
794
                if (altUP == 0) {
795
                    var AltBigUP    = "";
796
                    var AltSmallUP  = "0";
797

            
798
                }
799
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
800
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
801
                    var AltSmallUP  = "";
802
                }
803
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
804
                    var AltBigUP    = "";
805
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
806
                    var offset = -30.078;
807
                }
808
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
809
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
810
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
811
                    var offset += 15.039;
812
                }
813
                else {
814
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
815
                    var mod = int(math.mod(altUP,1000));
816
                    var AltSmallUP  = sprintf("%1d", mod);
817
                    var offset += 30.078;
818
                }
819

            
820
                me.screenElements["AltBigU"~place].setText(AltBigUP);
821
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
822
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
823
                var altDOWN = altCentral - (place*100);
824
                var offset = -30.078;
825
                if (altDOWN < 0) {
826
                    var altDOWN = -altDOWN;
827
                    var prefix = "-";
828
                    var offset += 15.039;
829
                }
830
                else
831
                    var prefix = "";
832

            
833
                if (altDOWN == 0) {
834
                    var AltBigDOWN  = "";
835
                    var AltSmallDOWN    = "0";
836
                }
837
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
838
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
839
                    var AltSmallDOWN    = "";
840
                }
841
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
842
                    var AltBigDOWN  = "";
843
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
844
                    var offset = -30.078;
845
                }
846
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
847
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
848
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
849
                    var offset += 15.039;
850
                }
851
                else {
852
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
853
                    var mod = int(math.mod(altDOWN,1000));
854
                    var AltSmallDOWN    = sprintf("%1d", mod);
855
                    var offset += 30.078;
856
                }
857
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
858
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
859
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
860
            }
861
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
862
        me.updateSelectedALT();
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
863
        var Sy = 0;
864
        for (var i = 8; i >= 0; i -= 1)
865
            me._last_alt_Sy[i+1] = me._last_alt_Sy[i];
trends animation
Sébastien MARQUE authored on 2017-03-13
866
        var now = systime();
867
        # altitude in 6s
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
868
        me._last_alt_Sy[0] = .3 * (alt - me._last_alt_ft) / (now - me._last_alt_s); # scale = 1/20ft
869
        foreach (var _Sy; me._last_alt_Sy)
870
            Sy += _Sy;
871
        Sy /= 10;
trends animation
Sébastien MARQUE authored on 2017-03-13
872
        if (abs(Sy) > 15)
873
            Sy = 15 * abs(Sy)/Sy; # = -15 or 15
874
        me.screenElements['Altitude-Trend-Indicator']
875
            .setScale(1,Sy)
876
            .setTranslation(0, -284.5 * (Sy - 1));
877
        me._last_alt_ft = alt;
878
        me._last_alt_s = now;
animation ALT
Sébastien MARQUE authored on 2017-03-11
879
    },
trends animation
Sébastien MARQUE authored on 2017-03-13
880
    _last_alt_ft : 0,
improve trends vor ALT and I...
Sébastien MARQUE authored on 2020-04-30
881
    _last_alt_Sy : [0,0,0,0,0,0,0,0,0,0],
trends animation
Sébastien MARQUE authored on 2017-03-13
882
    _last_alt_s  : systime(),
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
883
#}}}
animation HSI
Sébastien MARQUE authored on 2017-03-11
884

            
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
885
    updateBARO : func () {
886
# update BARO widget {{{
887
        var fmt = me._baro_unit == 'inhg' ? '%.2f%s' : '%i%s';
888
        me.screenElements['BARO-text']
889
            .setText(sprintf(fmt,
890
                        getprop('/instrumentation/altimeter/setting-' ~ me._baro_unit),
891
                        me._baro_unit == 'inhg' ? 'in' : 'hPa')
892
                );
893
    },
894
    _baro_unit : 'inhg',
895
#}}}
896

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
897
    updateHSI : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
898
# rotates the compass (PFD) {{{
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
899
        var hdg = data.hdg;
animation HSI
Sébastien MARQUE authored on 2017-03-11
900
        me.screenElements.Rose
901
            .setRotation(-hdg * D2R);
902
        me.screenElements['HDG-text']
903
            .setText(sprintf("%03u°", hdg));
904
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
905
#}}}
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
906

            
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
907
    updateHDG : func () {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
908
# moves the heading bug and display heading-deg for 3 seconds (PFD) {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
909
        if (me.device.role == 'MFD')
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
910
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
911
        var hdg = afcs.getValue('heading-bug-deg');
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
912
        me.screenElements['Heading-bug']
913
            .setRotation(hdg * D2R);
914
        me.screenElements['SelectedHDG-bg']
915
            .show();
916
        me.screenElements['SelectedHDG-bgtext']
917
            .show();
918
        me.screenElements['SelectedHDG-text']
919
            .setText(sprintf('%03d°%s', hdg, ''))
920
            .show();
921
        me.addTimer(3, ['SelectedHDG-text', 'SelectedHDG-bgtext', 'SelectedHDG-bg']);
922
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
923
#}}}
animation HDG bug
Sébastien MARQUE authored on 2017-03-13
924

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
925
    updateCRS : func () {
anime CRS
Sébastien MARQUE authored on 2017-03-13
926
# TODO: update display for NAV/GPS/BRG courses {{{
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
927
        if (me.device.role == 'MFD')
anime CRS
Sébastien MARQUE authored on 2017-03-13
928
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
929
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
930
        if (source == 'OFF')
931
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
932
        var crs = cdi.getValue('course');
adds CDI
Sébastien MARQUE authored on 2017-03-18
933
        if (crs == nil)
934
            return;
anime CRS
Sébastien MARQUE authored on 2017-03-13
935
        me.screenElements['SelectedCRS-bg']
936
            .show();
937
        me.screenElements['SelectedCRS-bgtext']
938
            .show();
939
        me.screenElements['SelectedCRS-text']
940
            .setText(sprintf('%03d°%s', crs, ''))
adds CDI
Sébastien MARQUE authored on 2017-03-18
941
            .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
anime CRS
Sébastien MARQUE authored on 2017-03-13
942
            .show();
943
        me.addTimer(3, ['SelectedCRS-text', 'SelectedCRS-bgtext', 'SelectedCRS-bg']);
944
    },
945
#}}}
946

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
947
    updateSelectedALT : func {
948
# animation for altitude section, called via updatedALT {{{
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
949
        if (! me.screenElements['SelectedALT'].getVisible())
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
950
            return;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
951
        var selected_alt = afcs.getValue('selected-alt-ft');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
952
        var delta_alt = data.alt - selected_alt;
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
953
        if (abs(delta_alt) > 300)
954
            delta_alt = 300 * abs(delta_alt)/delta_alt;
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
955
        me.screenElements['SelectedALT-symbol']
956
            .setVisible(abs(delta_alt) > 100);
957
        me.screenElements['SelectedALT-bg']
958
            .setVisible(abs(delta_alt) > 100);
959
        me.screenElements['SelectedALT-text']
960
            .setText(sprintf("%i", selected_alt))
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
961
            .setVisible(abs(delta_alt) > 100);
fix Selected Altitude displa...
Sébastien MARQUE authored on 2017-03-18
962
        me.screenElements['SelectedALT-bug']
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
963
            .setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567
964
    },
965
#}}}
966

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
967
    updateCDI : func {
968
# animation for CDI {{{
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
969
        var source = cdi.getValue('source');
adds CDI
Sébastien MARQUE authored on 2017-03-18
970
        if (source == 'OFF') {
971
            foreach (var s; ['GPS', 'NAV1', 'NAV2'])
972
                foreach (var t; ['pointer', 'CDI'])
973
                    me.screenElements[s ~ '-' ~ t].hide();
974
            me.screenElements['CDI-GPS-ANN-text'].hide();
975
            me.screenElements['CDI-GPS-XTK-text'].hide();
976
            me.screenElements['CDI-SRC-text'].hide();
977
            me.screenElements['CDI'].hide();
978
        }
979
        else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
980
            var course = cdi.getValue('course');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
981
            var rot = (course - data.hdg) * D2R;
adds CDI
Sébastien MARQUE authored on 2017-03-18
982
            me.screenElements['CDI']
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
983
                .setRotation(rot)
adds CDI
Sébastien MARQUE authored on 2017-03-18
984
                .show();
985
            me.screenElements['GPS-CTI']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
986
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
987
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
988
            me.screenElements['GPS-CTI-diamond']
animates GPS-CTI
Sébastien MARQUE authored on 2017-03-24
989
                .setVisible(getprop('/instrumentation/gps/wp/wp[1]/valid'))
990
                .setRotation(getprop('/instrumentation/gps/wp/wp[1]/course-deviation-deg') * D2R);
adds CDI
Sébastien MARQUE authored on 2017-03-18
991
            foreach (var s; ['GPS', 'NAV1', 'NAV2']) {
992
                me.screenElements[s ~ '-pointer']
993
                    .setRotation(rot)
994
                    .setVisible(source == s);
995
                me.screenElements[s ~ '-CDI']
996
                    .setVisible(source == s);
997
                foreach (var f; ['FROM', 'TO'])
998
                    me.screenElements[s ~ '-' ~ f]
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
999
                        .setVisible(s == source and cdi.getValue(f ~ '-flag'));
adds CDI
Sébastien MARQUE authored on 2017-03-18
1000
                me.screenElements['CDI-SRC-text']
1001
                    .setText(source)
1002
                    .setColor(source == 'GPS' ? me.colors.magenta : me.colors.green)
1003
                    .show();
1004
            }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1005
            var deflection = cdi.getValue('course-deflection');
makes the CDI available
Sébastien MARQUE authored on 2017-03-23
1006
            if (left(source, 3) == 'NAV')
1007
                var scale = deflection / 4;
1008
            else { # GPS
1009
                # TODO: deviation depending of the flight phase
1010
                # for now fixed 1 dot = 1 nm course error
1011
                var abs_deflection = abs(deflection);
1012
                me.screenElements['CDI-GPS-XTK-text']
1013
                    .setText(sprintf('XTK %iNM', abs_deflection))
1014
                    .setVisible(abs_deflection > 2.4);
1015
                var scale = deflection / 2;
1016
            }
1017
            scale = (abs(scale) > 1.2) ? 1.2 : scale;
1018
            me.screenElements[source ~ '-CDI']
1019
                .setTranslation(65 * scale, 0);
1020
            settimer(func me.updateCDI(), 0.3);
adds CDI
Sébastien MARQUE authored on 2017-03-18
1021
        }
1022
    },
1023
#}}}
1024

            
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1025
    _updateRadio: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1026
# common parts for NAV/LOC/COMM radios{{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1027
        # arg[0]._r = <comm|nav>
1028
        if (contains(arg[0], "active")) {
1029
            if (arg[0]['active'] == 'none') {
1030
                me.screenElements[arg[0]._r ~ '1-selected-freq']
1031
                    .setColor(1,1,1);
1032
                me.screenElements[arg[0]._r ~ '2-selected-freq']
1033
                    .setColor(1,1,1);
1034
            }
1035
            else {
1036
                me.screenElements[arg[0]._r ~ arg[0]['active'] ~ '-selected-freq']
1037
                    .setColor(0,1,0);
1038
                me.screenElements[arg[0]._r ~ arg[0].inactive ~ '-selected-freq']
1039
                    .setColor(1,1,1);
1040
            }
1041
        }
1042
        if (contains(arg[0], 'tune')) {
1043
            # n = 0 -> NAV1/COMM1
1044
            # n = 1 -> NAV1/COMM2
1045
            me.screenElements[arg[0]._r ~ '-freq-switch']
1046
                .setTranslation(0, arg[0].tune * 25);
1047
            me.screenElements[arg[0]._r ~ (arg[0].tune + 1) ~ '-standby-freq']
1048
                .setColor(0,1,1);
1049
            me.screenElements[arg[0]._r ~ ((arg[0].tune == 0) + 1) ~ '-standby-freq']
1050
                .setColor(1,1,1);
1051
        }
1052
        if (contains(arg[0], 'refresh')) {
small stuff
Sébastien MARQUE authored on 2017-03-22
1053
            # refresh only one line: NAV1/COMM1 or NAV2/COMM2
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1054
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1055
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-selected-freq']
1056
                .setText(sprintf(fmt, getprop('/instrumentation/'
1057
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/selected-mhz')));
1058
            me.screenElements[arg[0]._r ~ arg[0].refresh ~ '-standby-freq']
1059
                .setText(sprintf(fmt, getprop('/instrumentation/'
1060
                               ~ arg[0]._r ~ '[' ~ (arg[0].refresh - 1) ~ ']/frequencies/standby-mhz')));
1061
        }
1062
        if (contains(arg[0], 'set')) {
1063
            # 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
1064
            var n = radios.getValue(arg[0]._r ~ '-tune');
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1065
            var fmt = (arg[0]._r == 'nav') ? '%.2f' : '%.3f';
1066
            me.screenElements[arg[0]._r ~ (n + 1) ~ '-standby-freq']
fix freq display while setti...
Sébastien MARQUE authored on 2017-03-16
1067
                .setText(sprintf(fmt, getprop('/instrumentation/' ~ arg[0]._r ~ '[' ~ n ~ ']/frequencies/standby-mhz')));
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1068
        }
1069
        if (contains(arg[0], 'auto')) {
1070
            # pour rafraichir automagiquement, toutes les deux secondes un refresh pour un NAV
1071
            var radio = arg[0].auto;
1072
            me._updateRadio({refresh: 1, _r: radio});
1073
            settimer(func me._updateRadio({refresh: 2, _r: radio}), 1);
1074
            settimer(func me._updateRadio({auto: radio}), 2);
1075
        }
1076
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1077
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1078

            
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1079
    updateNAV : func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1080
# update NAV/LOC rodios display upper left (PFD/MFD){{{
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1081
        # made active via menu
1082
        if (contains(arg[0], "active")) {
adds CDI
Sébastien MARQUE authored on 2017-03-18
1083
            arg[0]._r = 'nav';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1084
            if (arg[0]['active'] == 'none') {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1085
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1086
                me.screenElements['nav1-id']
1087
                    .setColor(1,1,1);
1088
                me.screenElements['nav2-id']
1089
                    .setColor(1,1,1);
1090
                me.screenElements['NAV1-pointer']
1091
                    .hide();
1092
                me.screenElements['NAV2-pointer']
1093
                    .hide();
1094
            }
1095
            else {
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1096
                arg[0].inactive = (arg[0]['active'] == 1) + 1;
1097
                me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1098
                me.screenElements['nav' ~ arg[0]['active'] ~ '-id']
1099
                    .setColor(0,1,0);
1100
                me.screenElements['NAV' ~ arg[0]['active'] ~ '-pointer']
1101
                    .show();
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1102
                me.screenElements['nav' ~ arg[0].inactive ~ '-id']
1103
                    .setColor(1,1,1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1104
#                me.screenElements['HDI']
1105
#                    .setRotation();
1106
#                me.screenElements['NAV' ~ inactive ~ '-pointer']
1107
#                    .hide();
1108
#                foreach (var e; [ 'FROM', 'TO', 'CDI' ])
1109
#                    me.screenElements['NAV' ~ inactive ~ '-' ~ e]
1110
#                        .hide();
1111
            }
1112
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1113
        elsif (contains(arg[0], 'nav-id')) {
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
1114
            # 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
1115
            if (arg[0].val == nil)
1116
                arg[0].val = '';
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1117
            me.screenElements["nav" ~ arg[0]['nav-id'] ~ "-id"]
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1118
                    .setText(arg[0].val);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1119
        }
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1120
        else {
1121
            arg[0]._r = 'nav';
1122
            me._updateRadio(arg[0]);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1123
        }
1124
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1125
#}}}
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1126

            
1127
    updateCOMM: func {
comment on the folds
Sébastien MARQUE authored on 2017-03-13
1128
# update COMM radios display upper right (PFD/MFD){{{
ajout COMM, et factorisation...
Sébastien MARQUE authored on 2017-03-12
1129
        arg[0]._r = 'comm';
1130
        me._updateRadio(arg[0]);
1131
    },
cosmétique: folding pour les...
Sébastien MARQUE authored on 2017-03-13
1132
#}}}
anime time display
Sébastien MARQUE authored on 2017-03-13
1133

            
1134
    updateTIME : func {
1135
# updates the displayed time botoom left {{{
1136
        me.screenElements['TIME-text']
1137
            .setText(getprop('/sim/time/gmt-string'));
1138
    },
1139
#}}}
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1140

            
adds transponder
Sébastien MARQUE authored on 2017-03-17
1141
    updateXPDR : func {
1142
# updates transponder display {{{
1143
        for (var d = 0; d < 4; d+=1)
1144
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1145
                .setText(sprintf('%i', getprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']')));
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1146
        var tuning = radios.getValue('xpdr-tuning-digit');
1147
        var fms = radios.getValue('xpdr-tuning-fms-method');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1148
        for (var d = 0; d < 4; d+=1)
1149
            me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1150
                .setColor(1,1,1);
1151
        if (tuning != nil) {
1152
            me.screenElements['XPDR-DIGIT-' ~ tuning ~ '-text']
1153
                .setColor(0,1,1);
1154
            if (fms)
1155
                me.screenElements['XPDR-DIGIT-' ~ (tuning - 1) ~ '-text']
1156
                    .setColor(0,1,1);
1157
        }
adds transponder
Sébastien MARQUE authored on 2017-03-17
1158
        else {
1159
            if (getprop('/instrumentation/transponder/ident'))
1160
                var mode = 'IDENT';
1161
            else
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
1162
                var mode = radios.getValue('xpdr-mode');
adds transponder
Sébastien MARQUE authored on 2017-03-17
1163
            var wow = getprop('/gear/gear/wow');
1164
            if (! wow and mode != 'STBY')
1165
                var color = [0, 1, 0];
1166
            else
1167
                var color = [1, 1, 1];
1168
            for (var d = 0; d < 4; d+=1)
1169
                me.screenElements['XPDR-DIGIT-' ~ d ~ '-text']
1170
                    .setColor(color);
1171
            me.screenElements['XPDR-MODE-text']
1172
                .setColor(color)
1173
                .setText(mode);
1174
        }
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
1175
    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
1176
#}}}
1177

            
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1178
    updateOAT : func {
1179
# update OAT display on normal and reversionnary modes (every 3s) {{{
1180
        var tmp = getprop('/environment/temperature-deg' ~ me._oat_unit);
1181
        me.screenElements['OAT-text']
1182
            .setText(sprintf((abs(tmp) < 10) ? "%.1f %s" : "%i %s", tmp, (me._oat_unit == 'c') ? '°C' : 'F'));
1183
    },
1184
    _oat_unit : 'c',
1185
#}}}
1186

            
1187
    updateWindData : func {
1188
# update the window text and arrows for OPTN1/2 {{{
1189
        if (me._winddata_optn == 0)
1190
            return;
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1191
        if (data.ias < 30) {
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1192
            me.screenElements['WindData-NODATA']
1193
                .hide();
1194
            var wind_hdg = getprop('/environment/wind-from-heading-deg');
1195
            var wind_spd = getprop('/environment/wind-speed-kt');
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1196
            var alpha = wind_hdg - data.hdg;
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1197
            if (me._winddata_optn == 1) {
1198
                me.screenElements['WindData-OPTN1-HDG']
1199
                    .setRotation((alpha + 180) * D2R)
1200
                    .show();
1201
                me.screenElements['WindData-OPTN1-HDG-text']
1202
                    .setText(sprintf("%03i°", wind_hdg))
1203
                    .show();
1204
                me.screenElements['WindData-OPTN1-SPD-text']
1205
                    .setText(int(wind_spd) ~ 'KT')
1206
                    .show();
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1207
            }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1208
            else { # me._winddata_optn == 2
1209
                alpha *= D2R;
1210
                var Vt = wind_spd * math.sin(alpha);
1211
                var Ve = wind_spd * math.cos(alpha);
1212
                if (Vt != 0) {
1213
                    me.screenElements['WindData-OPTN2-crosswind-text']
1214
                        .setText(sprintf('%i', abs(Vt)))
1215
                        .show();
1216
                    me.screenElements['WindData-OPTN2-crosswind']
1217
                        .setScale(-abs(Vt)/Vt, 1)
1218
                        .setTranslation(-35 * (abs(Vt)/Vt + 1), 0)
1219
                        .show();
1220
                }
1221
                if (Ve != 0) {
1222
                    me.screenElements['WindData-OPTN2-headwind-text']
1223
                        .setText(sprintf('%i', abs(Ve)))
1224
                        .show();
1225
                    me.screenElements['WindData-OPTN2-headwind']
1226
                        .setScale(1, abs(Ve)/Ve)
1227
                        .setTranslation(0, 515 * (1 - abs(Ve)/Ve))
1228
                        .show();
1229
                }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1230
            }
1231
        }
improves WindData display
Sébastien MARQUE authored on 2017-03-16
1232
        else {
1233
            foreach (var e; [
1234
                    'WindData-OPTN1-HDG',
1235
                    'WindData-OPTN1-HDG-text',
1236
                    'WindData-OPTN1-SPD-text',
1237
                    'WindData-OPTN2-crosswind-text',
1238
                    'WindData-OPTN2-crosswind',
1239
                    'WindData-OPTN2-headwind-text',
1240
                    'WindData-OPTN2-headwind'
1241
            ])
1242
                me.screenElements[e].hide();
1243
            me.screenElements['WindData-NODATA'].show();
1244
        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
1245
        settimer(func me.updateWindData(), 0.5);
1246
    },
1247
    _winddata_optn : 0,
1248
#}}}
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1249

            
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1250
    updateAOA : func {
1251
# update Angle Of Attack {{{
1252
        if (me.device.data.aoa == 0)
1253
            return;
1254
        var color = [1,1,1];
1255
        var norm = data.aoa / data['stall-aoa'];
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1256
        me.screenElements['AOA-text']
1257
            .setText(sprintf('% .1f', norm));
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1258
        if (norm > 1) norm = 1;
1259
        if (norm > 0.9)
1260
            color = [1,0,0];
1261
        elsif (norm > 0.7)
1262
            color = [1,1,0];
1263
        elsif (norm < 0) {
1264
            norm = 0;
1265
            color = [1,0,0];
1266
        }
1267
        me.screenElements['AOA-needle']
1268
            .setRotation(-norm * math.pi)
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
1269
            .setColorFill(color);
1270
        me.screenElements['AOA-text']
adds AOA display
Sébastien MARQUE authored on 2017-04-15
1271
            .setColor(color);
1272
        settimer(func me.updateAOA(), 0.1);
1273
    },
1274
# }}}
1275

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

            
1281
            var dev = radios.getNode(source).getValue();
1282
            var el  = 'BRG' ~ brg;
1283
            if (dev != 'OFF') {
1284
                var info = {
1285
                    pointer : nil,
1286
                    id : 'NO DATA',
1287
                    hdg : nil,
1288
                    dst : '--.-NM'
1289
                };
1290
                if (left(dev, 3) == 'NAV') {
1291
                    info.pointer = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/in-range');
1292
                    if (info.pointer) {
1293
                        info.id  = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-id');
1294
                        info.hdg = getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/heading-deg');
1295
                        info.dst = sprintf('%.1d', getprop('/instrumentation/nav[' ~ (brg - 1) ~ ']/nav-distance') / 1852); # m -> /1852
1296
                    }
1297
                }
1298
                elsif (dev == 'GPS') {
1299
                    info.pointer = props.getNode('/instrumentation/gps/wp').getChild('wp[1])');
1300
                    if (info.pointer) {
1301
                        info.id  = getprop('/instrumentation/gps/wp/wp[1]/ID');
1302
                        info.hdg = getprop('/instrumentation/gps/wp/wp[1]/bearing-mag-deg');
1303
                        info.dst = sprintf('%.1d', getprop('/instrumentation/gps/wp/wp[1]/distance-nm'));
1304
                    }
1305
                }
1306
                else { # there are 2 available ADF in FG, but instrument manage only 1
1307
                    info.pointer = getprop('/instrumentation/adf/in-range');
1308
                    if (info.pointer) {
1309
                        info.id  = getprop('/instrumentation/adf/ident');
1310
                        info.hdg = getprop('/instrumentation/adf/indicated-bearing-deg');
1311
                    }
1312
                }
1313

            
1314
                if (info.pointer)
1315
                    me.screenElements[el ~ '-pointer']
make some data common to all...
Sébastien MARQUE authored on 2017-04-07
1316
                        .setRotation(-info.hdg - data.hdg * D2R)
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
1317
                        .show();
1318
                else
1319
                    me.screenElements[el ~ '-pointer']
1320
                        .hide();
1321
                me.screenElements[el ~ '-SRC-text']
1322
                    .setText(dev);
1323
                me.screenElements[el ~ '-DST-text']
1324
                    .setText(info.dst);
1325
                me.screenElements[el ~ '-WPID-text']
1326
                    .setText(info.id);
1327
                me.screenElements['BRG' ~ brg]
1328
                    .show();
1329
            }
1330
            else {
1331
                me.screenElements['BRG' ~ brg]
1332
                    .hide();
1333
            }
1334
        }
1335
    },
some added comments
Sébastien MARQUE authored on 2017-03-18
1336
#}}}
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
1337

            
adds OMI to PFD
Sébastien MARQUE authored on 2017-03-23
1338
    updateOMI : func {
1339
# display marker baecon Outer, Middle, Inner {{{
1340
        var marker = nil;
1341
        foreach (var m; ['outer', 'middle', 'inner'])
1342
            if (getprop('/instrumentation/marker-beacon/' ~ m)) {
1343
                marker = m;
1344
                me.screenElements['OMI']
1345
                    .show();
1346
                break;
1347
            }
1348
        if (marker != nil) {
1349
            me.screenElements['MarkerText']
1350
                .setText(me._omi_data[marker].t)
1351
                .show();
1352
            me.screenElements['MarkerBG']
1353
                .setColorFill(me._omi_data[marker].bg)
1354
                .show();
1355
        }
1356
        else
1357
            me.screenElements['OMI']
1358
                .hide();
1359
    },
1360
    _omi_data : {
1361
        'outer':  {t: 'O', bg: [0,1,1]},
1362
        'middle': {t: 'M', bg: [1,1,1]},
1363
        'inner':  {t: 'I', bg: [1,1,0]},
1364
    },
1365
#}}}
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
1366
};