zkv1000 / Nasal / core.nas /
Newer Older
316 lines | 13.799kb
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 = {};
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
141
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide'])
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))
181
                    traffic_displayed += flightdeck[name].map.layers.tcas.group.getVisible();
182
                var tcas_dirty = [];
183
                var level_dirty = 0;
184
                foreach (var AItype; [ 'aircraft', 'multiplayer' ])
185
                    foreach (var ac; props.globals.getNode("/ai/models").getChildren(AItype)) {
186
                        if (ac.getValue("valid")) {
187
                            var lat = ac.getNode("position/latitude-deg").getValue();
188
                            var lon = ac.getNode("position/longitude-deg").getValue();
189
                            var alt = ac.getNode("position/altitude-ft").getValue();
190
                            var vs  = ac.getNode("velocities/vertical-speed-fps").getValue();
191
                            if (isnum(lat) and isnum(lon) and isnum(vs) and isnum(alt)) {
192
                                alt = math.floor(((alt - data.alt) / 100) + 0.5);
193
                                var (course, dist) = courseAndDistance(lat, lon,
194
                                                     geo.Coord.new().set_latlon(data.lat, data.lon));
195
                                if (dist < 50) {
196
                                    var dir = ac.getNode('orientation/true-heading-deg').getValue() - course;
197
                                    if (dist < 5 and abs(alt) < 10)
198
                                        level = 3;
199
                                    elsif (dist < 10 and alt * vs < 0 and abs(dir) < 10)
200
                                        level = 3;
201
                                    elsif (dist < 15 and abs(alt) < 5)
202
                                        level = 2;
203
                                    elsif (dist < 15 and abs(alt) < 50)
204
                                        level = 1;
205
                                    else
206
                                        level = 0;
207
                                    level_dirty = level > level_dirty ? level : level_dirty;
208
                                    if (traffic_displayed)
209
                                        append(tcas_dirty, {
210
                                            lat: lat,
211
                                            lon: lon,
212
                                            vs: vs,
213
                                            alt: alt,
214
                                            level: level,
215
                                            callsign: ac.getValue('callsign')
216
                                        });
217
                                }
218
                            }
219
                        }
add TCAS
Sébastien MARQUE authored on 2017-12-21
220
                    }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
221
                data.tcas = tcas_dirty;
222
                data.tcas_level = level_dirty;
223
            });
224
            data.timers.tcas.start();
add TCAS
Sébastien MARQUE authored on 2017-12-21
225
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
226
        m.display.showInitProgress();
227

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

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

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

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

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

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

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

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

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

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

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