zkv1000 / Nasal / display.nas /
Newer Older
352 lines | 12.975kb
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 VSI
Sébastien MARQUE authored on 2017-03-10
172
    },
173

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

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

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

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

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

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

            
246
            if (Alt10 >= 80 and Alt100 >= 9)
247
                var Alt1000 += Alt20;
248

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

            
252
            if (alt> 100)
253
                var Offset10 = 100;
254

            
255
            if (alt> 1000)
256
                var Offset100 = 10;
257

            
258
            if (alt> 10000)
259
                var Offset1000 = 10;
260

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

            
282
                if (altUP == 0) {
283
                    var AltBigUP    = "";
284
                    var AltSmallUP  = "0";
285

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

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

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