zkv1000 / Nasal / display.nas /
Newer Older
355 lines | 13.055kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var displayClass = {
2
    new: func(node, role) {
3
        var m = { parents: [ displayClass ] };
4
        
5
        m.display = canvas.new({
6
                "name"      : role,
7
                "size"      : [1024, 768],
8
                "view"      : [1024, 768],
9
                "mipmapping": 1
10
        });
11
        m.display.addPlacement({
12
                "node": "Screen",
13
                "parent": role
14
        });
15
        m.display.setColorBackground(0,0,0);
16
        m.role = role;
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
17
        m.screenElements = {};
commit initial
Sébastien MARQUE authored on 2017-03-07
18

            
19
        return m;
20
    },
21

            
22
    loadsvg : func () {
23
        me.screen = me.display.createGroup();
24
        me.screen.hide();
25
        canvas.parsesvg(me.screen, "Aircraft/Instruments-3d/zkv1000/Systems/screen.svg");
26
    },
27

            
28
    _showInitProgress : func (p,t) {
29
        p.setText(t);
30
        if (zkv.getNode(me.role ~ 'init').getValue() != 0) {
31
            if (size(t) >= 10) t = '';
32
            settimer(func { me._showInitProgress(p, t ~ '.'); }, 0.1);
33
        }
34
        else {
35
            me.progress.hide();
36
            me.screen.show();
animation VSI
Sébastien MARQUE authored on 2017-03-10
37
            me.loadGroup({
38
                show : [
commit initial
Sébastien MARQUE authored on 2017-03-07
39
                    'SoftKeysTexts', 
40
                    'COMM', 
41
                    'NAV', 
42
                    'XPDR-TIME', 
AI disponible
Sébastien MARQUE authored on 2017-03-10
43
                    'FlightInstruments',
44
                    'Horizon',
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
45
                    'bankPointer',
animation VSI
Sébastien MARQUE authored on 2017-03-10
46
                    'VSI',
47
                ],
animation IAS
Sébastien MARQUE authored on 2017-03-10
48
                text: [
49
                    'VSIText',
animation ALT
Sébastien MARQUE authored on 2017-03-11
50
                    'Speed110',
51
                    'Alt11100'
animation IAS
Sébastien MARQUE authored on 2017-03-10
52
                ],
53
                clip: [
54
                    'SpeedLint1',
animation ALT
Sébastien MARQUE authored on 2017-03-11
55
                    'SpeedTape',
56
                    'LintAlt',
57
                    'AltLint00011'
animation IAS
Sébastien MARQUE authored on 2017-03-10
58
                ],
animation VSI
Sébastien MARQUE authored on 2017-03-10
59
            });
animation IAS
Sébastien MARQUE authored on 2017-03-10
60

            
animation ALT
Sébastien MARQUE authored on 2017-03-11
61
            var AltBigAltSmall = [ 'AltBigC', 'AltSmallC' ];
62
            for (var place = 1; place <= 6; place +=1) {
63
                append(AltBigAltSmall,
64
                    'AltBigU' ~ place,
65
                    'AltSmallU' ~ place,
66
                    'AltBigD' ~ place,
67
                    'AltSmallD' ~ place
68
                );
69
            }
70
            me.loadGroup({text: AltBigAltSmall});
71

            
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
72
            me.updateAI(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg'));
animation VSI
Sébastien MARQUE authored on 2017-03-10
73
            me.updateVSI(getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm'));
animation IAS
Sébastien MARQUE authored on 2017-03-10
74
            me.updateIAS(getprop('/velocities/airspeed-kt'));
animation ALT
Sébastien MARQUE authored on 2017-03-11
75
            me.updateALT(getprop('instrumentation/altimeter/indicated-altitude-ft'));
commit initial
Sébastien MARQUE authored on 2017-03-07
76
            me.progress.removeAllChildren();
77
            me.progress = nil;
78
            me.showInitProgress = nil;
79
            me._showInitProgress = nil;
80
            zkv.removeChild(me.role ~ 'init');
81
        }
82
    },
83

            
84
    showInitProgress : func (role) {
85
        me.progress = me.display.createGroup();
86
        me.progress.show();
87
        me.progress.createChild("text", role ~ " title")
88
            .setTranslation(512, 384)
89
            .setAlignment("center-center")
90
            .setFont("LiberationFonts/LiberationSans-Italic.ttf")
91
            .setFontSize(64, 1)
92
            .setColor(1,1,1)
93
            .setText("ZKV1000 " ~ role ~ " init");
94

            
95
        zkv.getNode(role ~ 'init',1).setIntValue(1);
96

            
97
        me._showInitProgress(me.progress.createChild("text", role ~ "progress")
98
            .setTranslation(512, 484)
99
            .setAlignment("center-center")
100
            .setFont("LiberationFonts/LiberationSans-Bold.ttf")
101
            .setFontSize(128, 1)
102
            .setColor(1,0,0), '.');
103
    },
104

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
105
    loadGroup : func (h) {
106
        if (typeof(h) != 'hash') {
107
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
108
                    caller(0)[0],
109
                    typeof(h),
110
                    caller(1)[0]));
111
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
112
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
113
        var setMethod = func (e, t) {
114
            if (t == 'hide')
115
                me.screenElements[e].hide();
116
            elsif (t == 'show')
117
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
118
            elsif (t == 'rot' or t == 'trans') {
119
                if (! contains(me.screenElements[e], t))
120
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
121
            }
122
            elsif (t == 'clip') {
123
                if (contains(me.clips, e))
124
                    me.screenElements[e].set("clip", me.clips[e]);
125
                else
126
                    print('no defined clip for ' ~ e);
127
            }
animation VSI
Sébastien MARQUE authored on 2017-03-10
128
            elsif (t == 'text') {
129
                if (contains(me.texts, e)) {
130
                    if (contains(me.texts[e], 'alignment'))
131
                        me.screenElements[e].setAlignment(me.texts[e].alignment);
132
                    if (contains(me.texts[e], 'default'))
133
                        me.screenElements[e].setText(me.texts[e].default);
134
                }
135
                else
136
                    print('no alignment for ' ~ e);
137
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
138
            else
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
139
                print('unknown method ' ~ t);
140
        };
141
        foreach (var todo; keys(h)) {
142
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
143
            foreach (var id; h[todo]) {
144
                if (! contains(me.screenElements, id)) {
145
                    me.screenElements[id] = me.screen.getElementById(id);
146
                    if (me.screenElements[id] != nil)
147
                        setMethod(id, todo);
148
                    else
149
                        print('SVG ID ' ~ id ~ ' not found');
150
                }
151
                else
152
                    setMethod(id, todo);
153
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
154
        }
155
    },
AI disponible
Sébastien MARQUE authored on 2017-03-10
156

            
157
    clips : {
158
        PitchScale : "rect(70,664,370,256)",
animation IAS
Sébastien MARQUE authored on 2017-03-10
159
        SpeedLint1 : "rect(252,226,318,204)",
160
        SpeedTape : "rect(115,239,455,156)",
animation ALT
Sébastien MARQUE authored on 2017-03-11
161
        LintAlt : "rect(115,808,455,704)",
162
        AltLint00011 : "rect(252,804,318,771)",
AI disponible
Sébastien MARQUE authored on 2017-03-10
163
    },
164

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
165
    texts : {
166
        VSIText : {
167
            alignment: "right-bottom", default : num('0'),
168
        },
animation IAS
Sébastien MARQUE authored on 2017-03-10
169
        Speed110 : {
170
            default: '', alignment : 'left-bottom'
171
        },
animation ALT (2)
Sébastien MARQUE authored on 2017-03-11
172
        Alt11100 : {
173
            default:'', alignment:'left-bottom'
174
        },
animation VSI
Sébastien MARQUE authored on 2017-03-10
175
    },
176

            
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
177
    updateAI: func(roll,pitch){
AI disponible
Sébastien MARQUE authored on 2017-03-10
178
        if (pitch > 80)
179
            pitch = 80;
180
        elsif(pitch < -80)
181
            pitch = -80;
182
        me.screenElements.Horizon
183
            .setRotation(-roll * D2R)
184
            .setTranslation(0, pitch * 6.8571428);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
185
        me.screenElements.bankPointer
186
            .setRotation(-roll * D2R);
187
        settimer(func me.updateAI(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg')), 0.1);
AI disponible
Sébastien MARQUE authored on 2017-03-10
188
    },
animation VSI
Sébastien MARQUE authored on 2017-03-10
189

            
190
    updateVSI: func (vsi) {
191
        me.screenElements.VSIText
192
            .setText(num(math.round(vsi, 10)));
193
        if (vsi > 4500)
194
            vsi = 4500;
195
        elsif (vsi < -4500)
196
            vsi = -4500;
197
        me.screenElements.VSI
198
            .setTranslation(0, vsi * -0.03465);
199
        settimer(func me.updateVSI(getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm')), 0.1);
200
    },
animation IAS
Sébastien MARQUE authored on 2017-03-10
201

            
202
    updateIAS: func (ias) {
203
        if (ias >= 10)
204
            me.screenElements.Speed110
205
                .setText(sprintf("% 2u",num(math.floor(ias/10))));
206
        else
207
            me.screenElements.Speed110
208
                .setText('');
209
        me.screenElements.SpeedLint1
210
            .setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36);
211
        me.screenElements.SpeedTape
212
            .setTranslation(0,ias * 5.711);
213
        settimer(func me.updateIAS(getprop('/velocities/airspeed-kt')), 0.1);
214
    },
animation ALT
Sébastien MARQUE authored on 2017-03-11
215

            
216
    updateALT: func (alt) {
217
        if (alt < 0)
218
            me.screenElements.Alt11100
219
                .setText(sprintf("% 3i",math.ceil(alt/100)));
220
        elsif (alt < 100)
221
            me.screenElements.Alt11100
222
                .setText('');
223
        else
224
            me.screenElements.Alt11100
225
                .setText(sprintf("% 3i",math.floor(alt/100)));
226
        me.screenElements.AltLint00011
227
            .setTranslation(0,math.fmod(alt,100) * 1.24);
228

            
229
        # From Farmin/G1000 http://wiki.flightgear.org/Project_Farmin/FG1000
230
        if (alt> -1000 and alt< 1000000) {
231
            var Offset10 = 0;
232
            var Offset100 = 0;
233
            var Offset1000 = 0;
234
            if (alt< 0) {
235
                var Ne = 1;
236
                var alt= -alt;
237
            }
238
            else
239
                var Ne = 0;
240

            
241
            var Alt10       = math.mod(alt,100);
242
            var Alt100      = int(math.mod(alt/100,10));
243
            var Alt1000     = int(math.mod(alt/1000,10));
244
            var Alt10000    = int(math.mod(alt/10000,10));
245
            var Alt20       = math.mod(Alt10,20)/20;
246
            if (Alt10 >= 80)
247
                var Alt100 += Alt20;
248

            
249
            if (Alt10 >= 80 and Alt100 >= 9)
250
                var Alt1000 += Alt20;
251

            
252
            if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9)
253
                var Alt10000 += Alt20;
254

            
255
            if (alt> 100)
256
                var Offset10 = 100;
257

            
258
            if (alt> 1000)
259
                var Offset100 = 10;
260

            
261
            if (alt> 10000)
262
                var Offset1000 = 10;
263

            
264
            if (!Ne) {
265
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*0.57375);
266
                var altCentral = (int(alt/100)*100);
267
            }
268
            elsif (Ne) {
269
                me.screenElements.LintAlt.setTranslation(0,(math.mod(alt,100))*-0.57375);
270
                var altCentral = -(int(alt/100)*100);
271
            }
272
            me.screenElements["AltBigC"].setText("");
273
            me.screenElements["AltSmallC"].setText("");
274
            for (var place = 1; place <= 6; place += 1) {
275
                var altUP = altCentral + (place*100);
276
                var offset = -30.078;
277
                if (altUP < 0) {
278
                    var altUP = -altUP;
279
                    var prefix = "-";
280
                    var offset += 15.039;
281
                }
282
                else
283
                    var prefix = "";
284

            
285
                if (altUP == 0) {
286
                    var AltBigUP    = "";
287
                    var AltSmallUP  = "0";
288

            
289
                }
290
                elsif (math.mod(altUP,500) == 0 and altUP != 0) {
291
                    var AltBigUP    = sprintf(prefix~"%1d", altUP);
292
                    var AltSmallUP  = "";
293
                }
294
                elsif (altUP < 1000 and (math.mod(altUP,500))) {
295
                    var AltBigUP    = "";
296
                    var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
297
                    var offset = -30.078;
298
                }
299
                elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
300
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
301
                    var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
302
                    var offset += 15.039;
303
                }
304
                else {
305
                    var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
306
                    var mod = int(math.mod(altUP,1000));
307
                    var AltSmallUP  = sprintf("%1d", mod);
308
                    var offset += 30.078;
309
                }
310

            
311
                me.screenElements["AltBigU"~place].setText(AltBigUP);
312
                me.screenElements["AltSmallU"~place].setText(AltSmallUP);
313
                me.screenElements["AltSmallU"~place].setTranslation(offset,0);
314
                var altDOWN = altCentral - (place*100);
315
                var offset = -30.078;
316
                if (altDOWN < 0) {
317
                    var altDOWN = -altDOWN;
318
                    var prefix = "-";
319
                    var offset += 15.039;
320
                }
321
                else
322
                    var prefix = "";
323

            
324
                if (altDOWN == 0) {
325
                    var AltBigDOWN  = "";
326
                    var AltSmallDOWN    = "0";
327
                }
328
                elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
329
                    var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
330
                    var AltSmallDOWN    = "";
331
                }
332
                elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
333
                    var AltBigDOWN  = "";
334
                    var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
335
                    var offset = -30.078;
336
                }
337
                elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
338
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
339
                    var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
340
                    var offset += 15.039;
341
                }
342
                else {
343
                    var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
344
                    var mod = int(math.mod(altDOWN,1000));
345
                    var AltSmallDOWN    = sprintf("%1d", mod);
346
                    var offset += 30.078;
347
                }
348
                me.screenElements["AltBigD"~place].setText(AltBigDOWN);
349
                me.screenElements["AltSmallD"~place].setText(AltSmallDOWN);
350
                me.screenElements["AltSmallD"~place].setTranslation(offset,0);
351
            }
352
        }
353
        settimer(func me.updateALT(getprop('instrumentation/altimeter/indicated-altitude-ft')), 0.2);
354
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
355
};