zkv1000 / Nasal / buttons.nas /
Newer Older
372 lines | 17.204kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var buttonsClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
2
    new : func (device) {
commit initial
Sébastien MARQUE authored on 2017-03-07
3
        var m = { parents: [ buttonsClass ] };
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
4
        m.device = device;
commit initial
Sébastien MARQUE authored on 2017-03-07
5
        return m;
6
    },
7

            
8
    PAN : func (xdir = 0, ydir = 0) {
9
    },
10

            
11
    AsSwitchNAV : func {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
12
        var n = radios.getValue('nav-tune');
commit initial
Sébastien MARQUE authored on 2017-03-07
13
        var tmp = getprop('/instrumentation/nav[' ~ n ~ ']/frequencies/selected-mhz');
14
        setprop('/instrumentation/nav[' ~ n ~ ']/frequencies/selected-mhz', getprop('/instrumentation/nav[' ~ n ~ ']/frequencies/standby-mhz'));
15
        setprop('/instrumentation/nav[' ~ n ~ ']/frequencies/standby-mhz', tmp);
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
16
        foreach (var c; keys(flightdeck))
17
            if (contains(flightdeck[c], 'display'))
18
                flightdeck[c].display.updateNAV({refresh: n+1});
commit initial
Sébastien MARQUE authored on 2017-03-07
19
    },
20

            
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
21
    AsSwitchCOM : func (x) {
commit initial
Sébastien MARQUE authored on 2017-03-07
22
        if (x) {
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
23
            me.AsSwitchCOM_pushed = getprop('/sim/time/elapsed-sec');
commit initial
Sébastien MARQUE authored on 2017-03-07
24
        }
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
25
        else {
26
            var pressed = getprop('/sim/time/elapsed-sec') - me.AsSwitchCOM_pushed;
27
            if (pressed > 2) {
28
                setprop('/instrumentation/comm/frequencies/selected-mhz', 121.500);
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
29
                radios.setValue('comm1-selected', 1);
30
                radios.setValue('comm2-selected', 0);
fix COMM display standby fre...
Sébastien MARQUE authored on 2017-04-09
31
                foreach (var d; keys(flightdeck))
32
                    if (contains(flightdeck[d], 'display')) {
33
                        flightdeck[d].display.updateCOMM({refresh: 1});
34
                        flightdeck[d].display.updateCOMM({refresh: 2});
35
                    }
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
36
            }
37
            else {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
38
                var c = radios.getValue('comm-tune');
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
39
                var tmp = getprop('/instrumentation/comm[' ~ c ~ ']/frequencies/selected-mhz');
40
                setprop('/instrumentation/comm[' ~ c ~ ']/frequencies/selected-mhz', getprop('/instrumentation/comm[' ~ c ~ ']/frequencies/standby-mhz'));
41
                setprop('/instrumentation/comm[' ~ c ~ ']/frequencies/standby-mhz', tmp);
fix COMM display standby fre...
Sébastien MARQUE authored on 2017-04-09
42
                foreach (var d; keys(flightdeck))
43
                    if (contains(flightdeck[d], 'display'))
44
                        flightdeck[d].display.updateCOMM({refresh: c+1});
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
45
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
46
        }
47
    },
48

            
ajout de l'animation des bou...
Sébastien MARQUE authored on 2017-03-08
49
    ALT : func () {
50
        var alt = getprop('instrumentation/altimeter/indicated-altitude-ft');
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
51
        afcs.setIntValue('selected-alt-ft', math.round(alt, 10));
commit initial
Sébastien MARQUE authored on 2017-03-07
52
    },
53

            
TMR/REF available
Sébastien MARQUE authored on 2017-04-10
54
    ValidateTMRREF : func (a = 0) {
55
        if (a)
56
            return;
57
        var (id, selected) = split('-', me.device.windows.selected);
58
        var state = me.device.windows.state[id];
59
        selected += state.scroll.offset;
60
        if (contains(state.objects[selected], 'callback'))
61
            call(state.objects[selected].callback, [id, selected], me);
62
    },
63

            
64
    ClearTMRREF : func (a = 0) {
65
        if (a)
66
            return;
67
        me.device.windows.del();
68
        me.device.data.TMRtimer = nil;
69
        me.device.knobs.FmsInner = func;
70
        me.device.knobs.FmsOuter = func;
71
        me.device.buttons.ENT = func;
72
        me.device.buttons.FMS = func;
73
        me.device.buttons.CLR = func;
74
    },
75

            
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
76
    MFD_page_wrapper : func (id, selected) {
77
        var s = me.device.data[id][me.device.display['page selected']];
78
        var group = s.name;
79
        var subpage = s.objects[selected].text;
80

            
81
        foreach (var k; keys(me.device.windows.window))
allows only implemented MFD ...
Sébastien MARQUE authored on 2017-06-02
82
            if (find(id, k) == 0) {
83
                me.device.windows.del(id);
84
                break;
85
            }
86
        call(me.device.display.MFD[group][subpage], [], me);
fix MFD page selection syste...
Sébastien MARQUE authored on 2017-04-13
87
    },
88

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
89
    MapMenu : func (a = 0) {
90
        if (a == 1)
91
            return;
92
        var menu_label = 'MAP MENU';
93
        if (!contains(me.device.windows.window, menu_label ~ '-bg')) {
94
            var level_min = 13;
95
            var level_max = 7;
selection of map display by ...
Sébastien MARQUE authored on 2020-06-14
96
            var range_from_level = func (l) {
97
                var r = (me.device.display.display.get('view[1]') / 2 * 84.53 * math.cos(data.lat) / math.pow(2, l)) * units.distance.from_nm;
98
                return sprintf('% 3u%s', math.round(r, r > 10 ? 5 : 1), units.distance.from_nm == 1 ? 'NM' : 'km');
99
            }
100
            var ranges = [ sprintf('  %s >', range_from_level(level_max)) ];
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
101
            for (var i = level_max + 1; i <= level_min; i += 1)
selection of map display by ...
Sébastien MARQUE authored on 2020-06-14
102
                append(ranges, sprintf(i < level_min ? '< %s >' : '< %s  ', range_from_level(i)));
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
103
            var orientation = [ '  NORTH UP >', '<  TRK UP  >' ];
104
            if (getprop('/instrumentation/gps/route-distance-nm') != nil)
105
                append(orientation, '<  DTK UP  >');
106
            append(orientation, '<  HDG UP   ');
107
            me.device.windows.draw(
108
                    menu_label,
109
                    {x: 720, y: 100, w: 300, l:3, sep: 1},
110
                    [
111
                        {text: menu_label, type: 'title'},
112
                        {type: 'separator'},
selection of map display by ...
Sébastien MARQUE authored on 2020-06-14
113
                        {text: 'RANGE: ', type: 'normal'},
114
                        {text: ranges[me.device.data.zoom - level_max],
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
115
                         type: 'selected|end-of-line',
selection of map display by ...
Sébastien MARQUE authored on 2020-06-14
116
                         choices: ranges,
117
                         level_max: level_max,
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
118
                         callback: func (id, selected) {
selection of map display by ...
Sébastien MARQUE authored on 2020-06-14
119
                             me.device.data.zoom = vecindex(me.device.windows.state[id].objects[selected].choices,
120
                                                            me.device.windows.state[id].objects[selected].text)
121
                                                   + me.device.windows.state[id].objects[selected].level_max;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
122
                             me.device.map.changeZoom();
123
                             me.device.map.update();
124
                         }
125
                        },
126
                        {text: 'ORIENTATION', type: 'normal'},
127
                        {text: (func foreach (var o; orientation) if (find(me.device.data.orientation.text, o) > -1) return o;)(),
128
                         type: 'editable|end-of-line',
129
                         choices: orientation,
130
                         callback: func (id, selected) {
131
                             var o = me.device.windows.state[id].objects[selected].text;
132
                             o = substr(o, 2);
133
                             o = substr(o, 0, size(o) - 2);
134
                             o = string.trim(o);
135
                             me.device.data.orientation.text = o;
136
                             me.device.map.update();
137
                         }
138
                        },
139
                    ]
140
                );
141
            me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
142
            me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
143
            me.device.buttons.CLR = me.device.buttons.MapMenu;
144
            me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
145
        }
146
        else {
147
            me.device.buttons.ENT = func;
148
            me.device.buttons.CLR = func;
149
            me.device.knobs.FmsInner = func;
150
            me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
151
            me.device.windows.del(menu_label);
152
        }
153
    },
154

            
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
155
    GlobalParams: func (a) {
156
        if (a == 1)
157
            return;
158
        var windowId = 'GLOBAL SETTINGS';
159
        var obj_infos = [
160
            {text: 'DISPLAY', type: 'title'},
161
            {type: 'separator'},
162
            {text: 'Brightness: ', type: 'normal'},
creates settings management
Sébastien MARQUE authored on 2020-05-16
163
            {text: sprintf( '% 3u %%', zkv.getValue('display-brightness-norm') * 100 / 0.7),
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
164
                type: 'selected immediate end-of-line',
creates settings management
Sébastien MARQUE authored on 2020-05-16
165
                format: ' % 3u %% ',
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
166
                range: {max: 100, min: 0},
167
                callback: func (id, selected) {
168
                    var b = num(string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == `%` or c == ` `));
169
                    zkv.setDoubleValue('display-brightness-norm', b * 0.7 / 100);
170
                },
171
            },
creates settings management
Sébastien MARQUE authored on 2020-05-16
172
            {text: 'Light    : ', type: 'normal'},
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
173
            {text: '  0 >',
174
                type: 'editable|immediate|end-of-line',
creates settings management
Sébastien MARQUE authored on 2020-05-16
175
                choices: ['  0 >', '< 1 >', '< 2 >', '< 3  '],
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
176
                callback: func (id, selected) {
creates settings management
Sébastien MARQUE authored on 2020-05-16
177
                    var l = num(string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`));
178
                    zkv.setDoubleValue('lightmap', l * 3);
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
179
                }
creates settings management
Sébastien MARQUE authored on 2020-05-16
180
            },
181
            {text: 'UNITS', type: 'title'},
182
            {type: 'separator'},
183
            {text: 'Pressure  :', type: 'normal'},
settings now have effect
Sébastien MARQUE authored on 2020-06-12
184
            {text: data.settings.units.pressure == 'inhg' ? '  inHg >' : '<  hPa  ',
creates settings management
Sébastien MARQUE authored on 2020-05-16
185
                type: 'editable|end-of-line',
186
                choices: [ '  inHg >', '<  hPa  '],
187
                callback: func (id, selected) {
188
                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
189
                    if (u == 'inHg')
190
                        data.settings.units.pressure = 'inhg';
191
                    else
192
                        data.settings.units.pressure = 'hpa';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
193
                    me.device.display.updateBARO();
creates settings management
Sébastien MARQUE authored on 2020-05-16
194
                }
195
            },
196
            {text: 'Altitude  :', type: 'normal'},
settings now have effect
Sébastien MARQUE authored on 2020-06-12
197
            {text: units.altitude.from_ft == 1 ? '   feet  >' : '< meters  ',
creates settings management
Sébastien MARQUE authored on 2020-05-16
198
                type: 'editable|end-of-line',
199
                choices: [ '   feet  >', '< meters  ' ],
200
                callback: func (id, selected) {
201
                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
settings now have effect
Sébastien MARQUE authored on 2020-06-12
202
                    if (u == 'feet') {
creates settings management
Sébastien MARQUE authored on 2020-05-16
203
                        data.settings.units.altitude = 'ft';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
204
                        units.altitude.from_ft = 1;
205
                        units.altitude.from_m  = M2FT;
206
                    }
207
                    else {
creates settings management
Sébastien MARQUE authored on 2020-05-16
208
                        data.settings.units.altitude = 'm';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
209
                        units.altitude.from_ft = FT2M;
210
                        units.altitude.from_m  = 1;
211
                    }
212
                }
213
            },
214
            {text: 'Distance  :', type: 'normal'},
215
            {text: units.distance.from_nm == 1 ? '  NM >' : '< km  ',
216
                type: 'editable|end-of-line',
217
                choices: ['  NM >', '< km  '],
218
                callback: func (id, selected) {
219
                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
220
                    if (u == 'NM') {
221
                        data.settings.units.distance = 'nm';
222
                        units.distance.from_nm = 1;
223
                        units.distance.from_m  = M2NM * 1000;
224
                    }
225
                    else {
226
                        data.settings.units.distance = 'km';
227
                        units.distance.from_nm = NM2M / 1000;
228
                        units.distance.from_m  = 0.001;
229
                    }
creates settings management
Sébastien MARQUE authored on 2020-05-16
230
                }
231
            },
232
            {text: 'Speed     :', type: 'normal'},
settings now have effect
Sébastien MARQUE authored on 2020-06-12
233
            {text: units.speed.from_kt == 1 ? '  knots  >' : '<  km/h   ',
creates settings management
Sébastien MARQUE authored on 2020-05-16
234
                type: 'editable|end-of-line',
235
                choices: [ '  knots  >', '<  km/h   ' ],
236
                callback: func (id, selected) {
237
                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
settings now have effect
Sébastien MARQUE authored on 2020-06-12
238
                    if (u == 'knots') {
creates settings management
Sébastien MARQUE authored on 2020-05-16
239
                        data.settings.units.altitude = 'kt';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
240
                        units.speed.from_kt  = 1;
241
                        units.speed.from_kmh = MPS2KT / 3.6;
242
                    }
243
                    else {
creates settings management
Sébastien MARQUE authored on 2020-05-16
244
                        data.settings.units.altitude = 'kmh';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
245
                        units.speed.from_kt  = KT2MPS * 3.6;
246
                        units.speed.from_kmh = 1;
247
                    }
248
                    foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide', 'Vne']) {
249
                        var speed = alerts.getValue(v) * units.speed.from_kt;
250
                        data[v] = speed != nil ? speed : 9999;
251
                    }
creates settings management
Sébastien MARQUE authored on 2020-05-16
252
                }
253
            },
254
            {text: 'Vert. Spd :', type: 'normal'},
settings now have effect
Sébastien MARQUE authored on 2020-06-12
255
            {text: units.vspeed.from_fpm == 1 ? '  ft/min >' : '<  m/min  ',
creates settings management
Sébastien MARQUE authored on 2020-05-16
256
                type: 'editable|end-of-line',
257
                choices: [ '  ft/min >', '<  m/min  ' ],
258
                callback: func (id, selected) {
259
                    var u = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
settings now have effect
Sébastien MARQUE authored on 2020-06-12
260
                    if (u == 'ft/min') {
creates settings management
Sébastien MARQUE authored on 2020-05-16
261
                        data.settings.units.altitude = 'fpm';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
262
                        units.vspeed.from_fpm = 1;
263
                        units.vspeed.from_mpm = M2FT;
264
                    }
265
                    else {
creates settings management
Sébastien MARQUE authored on 2020-05-16
266
                        data.settings.units.altitude = 'mpm';
settings now have effect
Sébastien MARQUE authored on 2020-06-12
267
                        units.vspeed.from_fpm = FT2M;
268
                        units.vspeed.from_mpm = 1;
269
                    }
creates settings management
Sébastien MARQUE authored on 2020-05-16
270
                }
271
            },
adds time display setting
Sébastien MARQUE authored on 2020-06-11
272
            {type: 'separator'},
273
            {text: 'TIME REF: ', type: 'normal'},
274
            {text: data.settings.time.actual,
275
                type: 'editable|end-of-line',
276
                choices: [ '  GMT >', '< LCL >', '< UTC >', '< RL   ' ],
277
                callback: func (id, selected) {
278
                    data.settings.time.actual = me.device.windows.state[id].objects[selected].text;
279
                    data.settings.time.label = string.trim(me.device.windows.state[id].objects[selected].text, 0, func (c) c == ` ` or c == `<` or c == `>`);
280
                }
281
            },
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
282
        ];
creates settings management
Sébastien MARQUE authored on 2020-05-16
283
        me.device.windows.draw( windowId, {autogeom: 1}, obj_infos);
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
284
        me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
285
        me.device.knobs.FmsInner = me.device.knobs.MenuSettings;
creates settings management
Sébastien MARQUE authored on 2020-05-16
286
        me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
287
        me.device.buttons.CLR = func {
288
            me.device.windows.del(windowId);
289
            me.device.knobs.FmsOuter = func;
290
            me.device.knobs.FmsInner = func;
291
            foreach (var b; ['ENT', 'CLR'])
292
                me.device.buttons[b] = func;
293
            me.device.buttons.MENU = me.device.buttons.GlobalParams;
294
        }
295
        me.device.buttons.MENU = me.device.buttons.CLR;
296
    },
297

            
handle DTO button
Sébastien MARQUE authored on 2020-05-16
298
    DirectTo : func (a) {
299
        if (a) return;
300
        if (me.device.windows.selected == nil) return;
301
        var (id, selected) = split('-', me.device.windows.selected);
302
        var state = me.device.windows.state[id];
303
        selected += state.scroll.offset;
304
        var scratch = props.globals.getNode('/instrumentation/gps/scratch');
305
        if (contains(state.objects[selected], 'dto')) {
306
            scratch.setValue('longitude-deg', state.objects[selected].dto.lon);
307
            scratch.setValue('latitude-deg', state.objects[selected].dto.lat);
308
            scratch.setValue('ident', state.objects[selected].dto.id);
309
            scratch.setValue('altitude-ft', data.alt);
310
            setprop('/instrumentation/gps/command', 'direct');
311
        }
312
    },
313

            
adds FPL button
Sébastien MARQUE authored on 2020-06-11
314
    FPL : func (a) {
315
        if (a or data.fpSize == 0 or me.device.windows.selected != '')
316
            return;
317
        var windowId = 'FLIGHTPLAN LIST';
318
        var flightplan = props.globals.getNode('/autopilot/route-manager');
319
        var route = flightplan.getNode('route');
320
        var obj_infos = [];
321
        var firstEntry = 1;
322
        var current = flightplan.getValue('current-wp');
323
        for (var i = current; i <= data.fpSize; i += 1) {
324
            var wp = route.getChild('wp', i);
325
            append(obj_infos, {
326
                type: (firstEntry ? 'selected' : 'editable'),
327
                text: sprintf('#%2d %-10s', data.fpSize - i, wp.getValue('id')),
328
                scrollgroup: i - current,
329
                dto: {
330
                    lon: wp.getValue('lon'),
331
                    lat: wp.getValue('lat'),
332
                    id:  wp.getValue('id')
333
                },
334
            });
335
            append(obj_infos, {
336
                type: 'normal|end-of-line',
337
                scrollgroup: i - current,
338
                text: sprintf(' %3dNM %3d°',
339
                              math.round(wp.getValue('leg-distance-nm')),
340
                              math.round(wp.getValue('leg-bearing-true-deg')))
341
            });
342
            firstEntry = 0;
343
        }
344
        me.device.windows.draw(windowId, obj_infos, {lines: 6, columns: 2});
345
        me.device.knobs.FmsOuter = me.device.knobs.NavigateMenu;
346
        me.device.knobs.FmsInner = me.device.knobs.NavigateMenu;
347
        me.device.buttons.ENT = func;
348
        me.device.buttons.MENU = func;
349
        me.device.buttons.CLR = func {
350
            me.device.windows.del(windowId);
351
            if (me.device.role == 'PFD') {
352
                me.device.knobs.FmsOuter = func;
353
                me.device.knobs.FmsInner = func;
354
                me.device.buttons.MENU   = me.device.buttons.GlobalParams;
355
            }
356
            else {
357
                me.device.knobs.FmsInner = func;
358
                me.device.knobs.FmsOuter = me.device.knobs.MFD_select_page_group;
359
                me.device.buttons.MENU   = me.device.buttons.MapMenu;
360
            }
361
            foreach (var b; ['ENT', 'CLR'])
362
                me.device.buttons[b] = func;
363
        }
364
        me.device.buttons.MENU = me.device.buttons.CLR;
365
    },
366

            
commit initial
Sébastien MARQUE authored on 2017-03-07
367
    MENU : void,
368
    PROC : void,
369
    CLR : void,
370
    ENT : void,
371
    FMS : void,
372
};