zkv1000 / Nasal / core.nas /
Newer Older
318 lines | 13.866kb
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

            
108
    # the timer isn't necessary anymore
109
    data.timers.listeners.stop();
110
    delete(data.timers, 'listeners');
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
111
}
112

            
commit initial
Sébastien MARQUE authored on 2017-03-07
113
var deviceClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
114
    new: func (name) {
commit initial
Sébastien MARQUE authored on 2017-03-07
115
        var m = { parents: [ deviceClass ] };
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
116
        m.name = name;
117
        m.role = substr(name, 0, 3);
118
        m.node = zkv.getNode(name, 1);
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
119
        m.data = {};
first attempt to centralize ...
Sébastien MARQUE authored on 2017-04-15
120
        m.timers = {};
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
121
        foreach (var v; keys(data.Vspeeds))
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
122
            m.data[v ~ '-visible'] = 1;
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
123
        foreach (var v; ['screen-object', 'screen-view', 'screen-size'])
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
124
            m.data[v] = getprop(zkv.getPath() ~ '/' ~ name ~ '/' ~ v);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
125

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

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

            
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
209
        setprop(zkv.getPath() ~ '/' ~ m.name ~ '/status', 1);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
210
        msg(m.name ~ ' switched on!');
commit initial
Sébastien MARQUE authored on 2017-03-07
211
        return m;
212
    },
add a way to power off
Sébastien MARQUE authored on 2020-05-06
213
    off: func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
214
        var name = me.name;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
215
        foreach (var timer; keys(me.timers)) {
216
            me.timers[timer].stop();
217
            delete(me.timers, timer);
218
        }
219
        foreach (var member; keys(me)) {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
220
            if (member == 'parents')
221
                continue;
222
            if (contains(me[member], 'parents')) {
223
                if (contains(me[member].parents[0], 'new')
224
                and typeof(me[member].parents[0].new) == 'func') {
225
                    if (contains(me[member].parents[0], 'removeAllChildren')
226
                    and !contains(me[member].parents[0], 'setVisible')) # this one is a props node, but not canvas
227
                        me[member].removeAllChildren();
228
                    elsif (contains(me[member].parents[0], 'off')
229
                    and typeof(me[member].parents[0].off) == 'func')
230
                        me[member].off();
231
                }
232
            }
233
        }
234
        foreach (var member; keys(me)) {
235
            if (member == 'parents')
236
                continue;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
237
            delete(me, member);
238
        }
poweroff improved
Sébastien MARQUE authored on 2020-05-16
239
        zkv.getNode(name).setValue('status', 0);
240
        msg(name ~ ' switched off');
add a way to power off
Sébastien MARQUE authored on 2020-05-06
241
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
242
};
243

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
244
var powerOff = func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
245
    foreach (var listener; keys(data.listeners)) {
improve power on and off usi...
Sébastien MARQUE authored on 2023-08-08
246
        if (listener == '/instrumentation/zkv1000/serviceable') {
247
            var prop = zkv.getNode('serviceable',1).getPath();
248
            data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0);
poweroff improved
Sébastien MARQUE authored on 2020-05-16
249
            continue;
improve power on and off usi...
Sébastien MARQUE authored on 2023-08-08
250
        }
add autopwer
Sébastien MARQUE authored on 2020-05-07
251
        removelistener(data.listeners[listener]);
poweroff improved
Sébastien MARQUE authored on 2020-05-16
252
        delete(data.listeners, listener);
253
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
254

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
255
    foreach (var timer; keys(data.timers)) {
256
        data.timers[timer].stop();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
257
        if (timer == '20Hz' or timer == '1Hz')
258
            continue;
improve power on and off usi...
Sébastien MARQUE authored on 2023-08-08
259
        if (timer == 'serviceable') {
260
            data.timers[timer] = maketimer(1, func {
261
                if (zkv.getNode('serviceable').getValue() != 0)
262
                    zkv1000.powerOn();
263
            });
264
            data.timers.serviceable.restart();
265
            continue;
266
        }
add a way to power off
Sébastien MARQUE authored on 2020-05-06
267
        delete(data.timers, timer);
268
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
269

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
270
    foreach (var k; keys(autopilot))
271
        delete(autopilot, k);
272

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
273
    foreach (var name; keys(flightdeck)) {
274
        flightdeck[name].off();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
275
        flightdeck[name] = nil;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
276
    }
277
}
278

            
PFD+MFD allumés ensemble
Sébastien MARQUE authored on 2017-03-11
279
var powerOn = func {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
280
    if (!zkv.getValue('serviceable')) {
281
        msg('not yet serviceable (check power)!');
282
        return;
283
    }
284

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
285
    if (contains(data.listeners, '/instrumentation/zkv1000/serviceable')) {
improve power on and off usi...
Sébastien MARQUE authored on 2023-08-08
286
        var prop = zkv.getNode('serviceable',1).getPath();
287
        data.listeners[prop] = setlistener(prop, zkv1000.powerOff, 0, 0);
288
    }
289
    if (contains(data.timers, 'serviceable')) {
290
        data.timers.serviceable = maketimer(1, func {
291
            if (zkv.getNode('serviceable').getValue() == 0)
292
                zkv1000.powerOff();
293
        });
294
        data.timers.serviceable.start();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
295
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
296

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

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
300
    foreach (var name; keys(flightdeck))
301
        if (zkv.getNode(name) != nil)
poweroff improved
Sébastien MARQUE authored on 2020-05-16
302
            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
303
#            thread.newthread(func {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
304
                flightdeck[name] = deviceClass.new(name);
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
305
#            });
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
306

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

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

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