zkv1000 / Nasal / core.nas /
Newer Older
320 lines | 13.961kb
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
1
var setListeners = func {
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
2
    var prop = '/instrumentation/nav/nav-id';
3
    data.listeners[prop] = setlistener(prop,
correction listeners
Sébastien MARQUE authored on 2017-03-12
4
            func (n) {
5
                var val = n.getValue();
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
6
                foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
7
                    flightdeck[c].display.updateNAV({'nav-id': 1, val: val});
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
8
            }, 1, 2);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
9

            
10
    prop = '/instrumentation/nav[1]/nav-id';
11
    data.listeners[prop] = setlistener(prop,
correction listeners
Sébastien MARQUE authored on 2017-03-12
12
            func (n) {
13
                var val = n.getValue();
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
14
                foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
15
                    flightdeck[c].display.updateNAV({'nav-id': 2, val: val});
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
16
            }, 1, 2);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
17

            
adds ILS glideslope
Sébastien MARQUE authored on 2020-06-09
18
    prop = '/instrumentation/nav/has-gs';
19
    data.listeners[prop] = setlistener(prop,
20
            func (n) {
21
                if (n.getValue()) {
22
                    foreach (var c; keys(flightdeck)) {
23
                        if (flightdeck[c].role == 'PFD') {
24
                            flightdeck[c].display.screenElements['VDI-scale'].show();
25
                            flightdeck[c].display.screenElements['GS-ILS'].show();
26
                            flightdeck[c].display.timers.updateGS.start();
27
                        }
28
                    }
29
                }
30
                else {
31
                    foreach (var c; keys(flightdeck)) {
32
                        if (flightdeck[c].role == 'PFD') {
33
                            flightdeck[c].display.screenElements['VDI-scale'].hide();
34
                            flightdeck[c].display.screenElements['GS-ILS'].hide();
35
                            flightdeck[c].display.timers.updateGS.stop();
36
                        }
37
                    }
38
                }
39
            }, 1, 0);
40

            
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
41
    # keep this listener as long as the code is to heavy to be modified in multiple places
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
42
    prop = afcs.getNode('selected-alt-ft').getPath();
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
43
    data.listeners[prop] = setlistener(prop,
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
44
            func (n) {
45
                var val = n.getValue();
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
46
                if (val != nil)
47
                    foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
48
                        if (flightdeck[c].role == 'PFD') {
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
49
                            if (! flightdeck[c].display.screenElements['SelectedALT'].getVisible()) {
50
                                flightdeck[c].display.screenElements['SelectedALT'].show();
51
                                flightdeck[c].display.screenElements['SelectedALT-text'].show();
52
                                flightdeck[c].display.screenElements['SelectedALT-symbol'].show();
53
                                flightdeck[c].display.screenElements['SelectedALT-bug'].show();
54
                                flightdeck[c].display.screenElements['SelectedALT-bg'].show();
55
                            }
56
                            flightdeck[c].display.updateSelectedALT();
57
                        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
58
            }, 0, 2);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
59

            
60
    prop = '/gear/gear/wow';
61
    data.listeners[prop] = setlistener(prop,
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
62
            func foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
63
                if (flightdeck[c].role == 'PFD')
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
64
                    flightdeck[c].display.updateXPDR(),
adds transponder
Sébastien MARQUE authored on 2017-03-17
65
            0, 0);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
66

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
67
    prop = misc.getNode('alt-setting-inhg').getPath();
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
68
    data.listeners[prop] = setlistener(prop,
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
69
            func foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
70
                if (flightdeck[c].role == 'PFD')
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
71
                    flightdeck[c].display.updateBARO(), 0, 2);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
72

            
73
    prop = '/autopilot/route-manager/signals/edited';
74
    data.listeners[prop] = setlistener(prop,
75
            func foreach (var c; keys(flightdeck))
76
                flightdeck[c].map.layers.route.onFlightPlanChange(),
77
                0, 1);
78

            
79
    prop = '/autopilot/route-manager/current-wp';
80
    data.listeners[prop] = setlistener(prop,
fix map display makes FG to ...
Sébastien MARQUE authored on 2020-05-03
81
            func (n) {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
82
                var wp_idx = n.getValue();
83
                if (wp_idx > 0) {
84
                    var wp_path = '/autopilot/route-manager/route/wp[' ~ wp_idx ~ ']/';
85
                    var wp = findNavaidsByID(getprop(wp_path ~ 'latitude-deg'),
86
                                             getprop(wp_path ~ 'longitude-deg'),
87
                                             getprop(wp_path ~ 'id'));
88
                    call(func {return wp[0].frequency}, [], nil, nil, var errors = []);
89
#                    if (!size(errors)) debuginfo ~ sprintf('; freq: %d', wp[0].frequency);
90
                    call(func {return wp[0].type}, [], nil, nil, var errors = []);
91
#                    if (!size(errors)) debuginfo ~ sprintf('; type: %s', wp[0].type);
92
                }
fix map display makes FG to ...
Sébastien MARQUE authored on 2020-05-03
93
                var delay = maketimer(2, func {
94
                    foreach (var c; keys(flightdeck))
95
                        flightdeck[c].map.layers.route.onCurrentWaypointChange(
96
                                props.globals.getNode('/autopilot/route-manager/current-wp'));
97
                    });
98
                delay.singleShot = 1;
99
                delay.start();
100
            }, 0, 1);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
101

            
102
    prop = '/autopilot/route-manager/active';
103
    data.listeners[prop] = setlistener(prop,
104
            func foreach (var c; keys(flightdeck))
105
                    flightdeck[c].map.layers.route.onCurrentWaypointChange(props.globals.getNode('/autopilot/route-manager/current-wp')),
106
                0, 1);
add a way to power off
Sébastien MARQUE authored on 2020-05-06
107

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
108
    if (zkv.getChild('serviceable') != nil) {
109
        prop = zkv.getPath() ~ '/serviceable';
110
        data.listeners[prop] = setlistener(prop,
111
                func (n) {
112
                    var type = n.getType();
113
                    if (type == 'BOOL') {
114
                        if (n.getBoolValue())
115
                            zkv1000.powerOn();
116
                        else
117
                            zkv1000.powerOff();
118
                    }
119
                    elsif (type == 'INT' or type == 'LONG' or type == 'FLOAT' or type == 'DOUBLE') {
120
                        if (n.getValue() > 12)
121
                            zkv1000.powerOn();
122
                        else
123
                            zkv1000.powerOff();
124
                    }
125
                }, 0, 0);
126
    }
add a way to power off
Sébastien MARQUE authored on 2020-05-06
127

            
128
    # the timer isn't necessary anymore
129
    data.timers.listeners.stop();
130
    delete(data.timers, 'listeners');
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
131
}
132

            
commit initial
Sébastien MARQUE authored on 2017-03-07
133
var deviceClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
134
    new: func (name) {
commit initial
Sébastien MARQUE authored on 2017-03-07
135
        var m = { parents: [ deviceClass ] };
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
136
        m.name = name;
137
        m.role = substr(name, 0, 3);
138
        m.node = zkv.getNode(name, 1);
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
139
        m.data = {};
first attempt to centralize ...
Sébastien MARQUE authored on 2017-04-15
140
        m.timers = {};
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
141
        foreach (var v; keys(data.Vspeeds))
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
142
            m.data[v ~ '-visible'] = 1;
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
143
        foreach (var v; ['screen-object', 'screen-view', 'screen-size'])
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
144
            m.data[v] = getprop(zkv.getPath() ~ '/' ~ name ~ '/' ~ v);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
145

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
146
        m.display  = displayClass.new(m);
147
        m.softkeys = softkeysClass.new(m);
148
        m.buttons  = buttonsClass.new(m);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
149
        m.knobs    = knobsClass.new(m);
just a alignment
Sébastien MARQUE authored on 2017-12-21
150
        m.map      = mapClass.new(m);
TMR/REF window
Sébastien MARQUE authored on 2017-03-28
151
        m.windows  = pageClass.new(m);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
152

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
153
        if (! contains(data.timers, 'alt-setting-inhg')) {
154
            data.timers['alt-setting-inhg'] = maketimer(0.1, m, func {
155
                    var inhg = getprop('/instrumentation/altimeter/setting-inhg');
156
                    if (inhg != misc.getValue('alt-setting-inhg'))
157
                        misc.getNode('alt-setting-inhg').setValue(inhg);
158
                });
159
            data.timers['alt-setting-inhg'].start();
160
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
161
        if (! contains(data.timers, 'map')) {
162
            data.timers.map = maketimer(1, m, func {
163
                    foreach (var d; keys(flightdeck))
164
                        flightdeck[d].map.update();
165
                    var gspd = getprop('/velocities/groundspeed-kt');
166
                    if (gspd != 0)
167
                        var next = (me.data['range-nm']/(gspd/3600))/(me.display.display.get('view[1]')/2);
168
                    else
169
                        var next = 10;
170
                    if (next > 10)
171
                        next = 10;
172
                    data.timers.map.restart(next);
173
                });
174
            data.timers.map.singleShot = 1;
175
            data.timers.map.start();
176
        }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
177
        if (!contains(data.timers, 'tcas')) {
178
            data.timers.tcas = maketimer ( 5, func {
179
                var traffic_displayed = 0;
180
                foreach (var name; keys(flightdeck))
removes traffic from PFD ins...
Sébastien MARQUE authored on 2020-06-14
181
                    if (contains(flightdeck[name].map.layers, 'tcas'))
182
                        traffic_displayed += flightdeck[name].map.layers.tcas.group.getVisible();
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
183
                var tcas_dirty = [];
184
                var level_dirty = 0;
185
                foreach (var AItype; [ 'aircraft', 'multiplayer' ])
186
                    foreach (var ac; props.globals.getNode("/ai/models").getChildren(AItype)) {
187
                        if (ac.getValue("valid")) {
188
                            var lat = ac.getNode("position/latitude-deg").getValue();
189
                            var lon = ac.getNode("position/longitude-deg").getValue();
190
                            var alt = ac.getNode("position/altitude-ft").getValue();
191
                            var vs  = ac.getNode("velocities/vertical-speed-fps").getValue();
192
                            if (isnum(lat) and isnum(lon) and isnum(vs) and isnum(alt)) {
193
                                alt = math.floor(((alt - data.alt) / 100) + 0.5);
194
                                var (course, dist) = courseAndDistance(lat, lon,
195
                                                     geo.Coord.new().set_latlon(data.lat, data.lon));
196
                                if (dist < 50) {
197
                                    var dir = ac.getNode('orientation/true-heading-deg').getValue() - course;
198
                                    if (dist < 5 and abs(alt) < 10)
199
                                        level = 3;
200
                                    elsif (dist < 10 and alt * vs < 0 and abs(dir) < 10)
201
                                        level = 3;
202
                                    elsif (dist < 15 and abs(alt) < 5)
203
                                        level = 2;
204
                                    elsif (dist < 15 and abs(alt) < 50)
205
                                        level = 1;
206
                                    else
207
                                        level = 0;
208
                                    level_dirty = level > level_dirty ? level : level_dirty;
209
                                    if (traffic_displayed)
210
                                        append(tcas_dirty, {
211
                                            lat: lat,
212
                                            lon: lon,
213
                                            vs: vs,
214
                                            alt: alt,
215
                                            level: level,
216
                                            callsign: ac.getValue('callsign')
217
                                        });
218
                                }
219
                            }
220
                        }
add TCAS
Sébastien MARQUE authored on 2017-12-21
221
                    }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
222
                data.tcas = tcas_dirty;
223
                data.tcas_level = level_dirty;
224
            });
225
            data.timers.tcas.start();
add TCAS
Sébastien MARQUE authored on 2017-12-21
226
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
227
        m.display.showInitProgress();
228

            
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
229
        setprop(zkv.getPath() ~ '/' ~ m.name ~ '/status', 1);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
230
        msg(m.name ~ ' switched on!');
commit initial
Sébastien MARQUE authored on 2017-03-07
231
        return m;
232
    },
add a way to power off
Sébastien MARQUE authored on 2020-05-06
233
    off: func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
234
        var name = me.name;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
235
        foreach (var timer; keys(me.timers)) {
236
            me.timers[timer].stop();
237
            delete(me.timers, timer);
238
        }
239
        foreach (var member; keys(me)) {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
240
            if (member == 'parents')
241
                continue;
242
            if (contains(me[member], 'parents')) {
243
                if (contains(me[member].parents[0], 'new')
244
                and typeof(me[member].parents[0].new) == 'func') {
245
                    if (contains(me[member].parents[0], 'removeAllChildren')
246
                    and !contains(me[member].parents[0], 'setVisible')) # this one is a props node, but not canvas
247
                        me[member].removeAllChildren();
248
                    elsif (contains(me[member].parents[0], 'off')
249
                    and typeof(me[member].parents[0].off) == 'func')
250
                        me[member].off();
251
                }
252
            }
253
        }
254
        foreach (var member; keys(me)) {
255
            if (member == 'parents')
256
                continue;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
257
            delete(me, member);
258
        }
poweroff improved
Sébastien MARQUE authored on 2020-05-16
259
        zkv.getNode(name).setValue('status', 0);
260
        msg(name ~ ' switched off');
add a way to power off
Sébastien MARQUE authored on 2020-05-06
261
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
262
};
263

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
264
var powerOff = func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
265
    foreach (var listener; keys(data.listeners)) {
266
        if (listener == '/instrumentation/zkv1000/serviceable')
267
            continue;
add autopwer
Sébastien MARQUE authored on 2020-05-07
268
        removelistener(data.listeners[listener]);
poweroff improved
Sébastien MARQUE authored on 2020-05-16
269
        delete(data.listeners, listener);
270
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
271

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
272
    foreach (var timer; keys(data.timers)) {
273
        data.timers[timer].stop();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
274
        if (timer == '20Hz' or timer == '1Hz')
275
            continue;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
276
        delete(data.timers, timer);
277
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
278

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
279
    foreach (var k; keys(autopilot))
280
        delete(autopilot, k);
281

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
282
    foreach (var name; keys(flightdeck)) {
283
        flightdeck[name].off();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
284
        flightdeck[name] = nil;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
285
    }
286
}
287

            
PFD+MFD allumés ensemble
Sébastien MARQUE authored on 2017-03-11
288
var powerOn = func {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
289
    if (!zkv.getValue('serviceable')) {
290
        msg('not yet serviceable (check power)!');
291
        return;
292
    }
293

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
294
    if (contains(data.listeners, '/instrumentation/zkv1000/serviceable')) {
295
        removelistener(data.listeners['/instrumentation/zkv1000/serviceable']);
296
        delete(data.listeners, '/instrumentation/zkv1000/serviceable');
297
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
298

            
global timers started at pow...
Sébastien MARQUE authored on 2017-04-12
299
    foreach (var freq; keys(data.timers))
300
        data.timers[freq].start();
301

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
302
    foreach (var name; keys(flightdeck))
303
        if (zkv.getNode(name) != nil)
poweroff improved
Sébastien MARQUE authored on 2020-05-16
304
            if (zkv.getNode(name).getValue('status') == nil or zkv.getNode(name).getValue('status') == 0)
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
305
#            thread.newthread(func {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
306
                flightdeck[name] = deviceClass.new(name);
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
307
#            });
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
308

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
309
    if (! contains(autopilot, 'parents'))
310
        autopilot = APClass.new();
makes autopilot up after all...
Sébastien MARQUE authored on 2020-05-08
311

            
adds alerting system
Sébastien MARQUE authored on 2020-07-09
312
    if (! contains(annunciations, 'parents'))
313
        annunciations = annunciationsClass.new();
314

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
315
    if (! contains(data.timers, 'listeners')) {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
316
        data.timers.listeners = maketimer(1, setListeners);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
317
        data.timers.listeners.singleShot = 1;
318
        data.timers.listeners.start();
319
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
320
}