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

            
18
    # 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
19
    prop = afcs.getNode('selected-alt-ft').getPath();
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
20
    data.listeners[prop] = setlistener(prop,
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
21
            func (n) {
22
                var val = n.getValue();
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
23
                if (val != nil)
24
                    foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
25
                        if (flightdeck[c].role == 'PFD') {
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
26
                            if (! flightdeck[c].display.screenElements['SelectedALT'].getVisible()) {
27
                                flightdeck[c].display.screenElements['SelectedALT'].show();
28
                                flightdeck[c].display.screenElements['SelectedALT-text'].show();
29
                                flightdeck[c].display.screenElements['SelectedALT-symbol'].show();
30
                                flightdeck[c].display.screenElements['SelectedALT-bug'].show();
31
                                flightdeck[c].display.screenElements['SelectedALT-bg'].show();
32
                            }
33
                            flightdeck[c].display.updateSelectedALT();
34
                        }
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
35
            }, 0, 2);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
36

            
37
    prop = '/gear/gear/wow';
38
    data.listeners[prop] = setlistener(prop,
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
39
            func foreach (var c; keys(flightdeck))
removes unecessary listeners
Sébastien MARQUE authored on 2017-04-08
40
                if (flightdeck[c].role == 'PFD')
creates flightdeck hash to p...
Sébastien MARQUE authored on 2017-04-07
41
                    flightdeck[c].display.updateXPDR(),
adds transponder
Sébastien MARQUE authored on 2017-03-17
42
            0, 0);
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
43

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

            
50
    prop = '/autopilot/route-manager/signals/edited';
51
    data.listeners[prop] = setlistener(prop,
52
            func foreach (var c; keys(flightdeck))
53
                flightdeck[c].map.layers.route.onFlightPlanChange(),
54
                0, 1);
55

            
56
    prop = '/autopilot/route-manager/current-wp';
57
    data.listeners[prop] = setlistener(prop,
fix map display makes FG to ...
Sébastien MARQUE authored on 2020-05-03
58
            func (n) {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
59
                var wp_idx = n.getValue();
60
                if (wp_idx > 0) {
61
                    var wp_path = '/autopilot/route-manager/route/wp[' ~ wp_idx ~ ']/';
62
                    var wp = findNavaidsByID(getprop(wp_path ~ 'latitude-deg'),
63
                                             getprop(wp_path ~ 'longitude-deg'),
64
                                             getprop(wp_path ~ 'id'));
65
                    call(func {return wp[0].frequency}, [], nil, nil, var errors = []);
66
#                    if (!size(errors)) debuginfo ~ sprintf('; freq: %d', wp[0].frequency);
67
                    call(func {return wp[0].type}, [], nil, nil, var errors = []);
68
#                    if (!size(errors)) debuginfo ~ sprintf('; type: %s', wp[0].type);
69
                }
fix map display makes FG to ...
Sébastien MARQUE authored on 2020-05-03
70
                var delay = maketimer(2, func {
71
                    foreach (var c; keys(flightdeck))
72
                        flightdeck[c].map.layers.route.onCurrentWaypointChange(
73
                                props.globals.getNode('/autopilot/route-manager/current-wp'));
74
                    });
75
                delay.singleShot = 1;
76
                delay.start();
77
            }, 0, 1);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
78

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

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
85
    if (zkv.getChild('serviceable') != nil) {
86
        prop = zkv.getPath() ~ '/serviceable';
87
        data.listeners[prop] = setlistener(prop,
88
                func (n) {
89
                    var type = n.getType();
90
                    if (type == 'BOOL') {
91
                        if (n.getBoolValue())
92
                            zkv1000.powerOn();
93
                        else
94
                            zkv1000.powerOff();
95
                    }
96
                    elsif (type == 'INT' or type == 'LONG' or type == 'FLOAT' or type == 'DOUBLE') {
97
                        if (n.getValue() > 12)
98
                            zkv1000.powerOn();
99
                        else
100
                            zkv1000.powerOff();
101
                    }
102
                }, 0, 0);
103
    }
add a way to power off
Sébastien MARQUE authored on 2020-05-06
104

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

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

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

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
130
        if (! contains(data.timers, 'alt-setting-inhg')) {
131
            data.timers['alt-setting-inhg'] = maketimer(0.1, m, func {
132
                    var inhg = getprop('/instrumentation/altimeter/setting-inhg');
133
                    if (inhg != misc.getValue('alt-setting-inhg'))
134
                        misc.getNode('alt-setting-inhg').setValue(inhg);
135
                });
136
            data.timers['alt-setting-inhg'].start();
137
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
138
        if (! contains(data.timers, 'map')) {
139
            data.timers.map = maketimer(1, m, func {
140
                    foreach (var d; keys(flightdeck))
141
                        flightdeck[d].map.update();
142
                    var gspd = getprop('/velocities/groundspeed-kt');
143
                    if (gspd != 0)
144
                        var next = (me.data['range-nm']/(gspd/3600))/(me.display.display.get('view[1]')/2);
145
                    else
146
                        var next = 10;
147
                    if (next > 10)
148
                        next = 10;
149
                    data.timers.map.restart(next);
150
                });
151
            data.timers.map.singleShot = 1;
152
            data.timers.map.start();
153
        }
add TCAS
Sébastien MARQUE authored on 2017-12-21
154
        if (getprop('/instrumentation/tcas/serviceable') != nil) {
155
            m.data.tcas = 0;
156
            if (!contains(data.timers, 'tcas')) {
157
                data.timers.tcas = maketimer ( 1,
158
                    func {
159
                        var tcas_dirty = [];
160
                        var _range = 6;
161
                        var _minLevel = -1;
162
                        foreach (var ac; props.globals.getNode("/ai/models").getChildren("multiplayer")) {
163
                            if (ac.getValue("valid")) {
164
                                var range = ac.getNode("radar/range-nm").getValue();
165
                                if (range != nil) {
166
                                    if (debug.isnan(range) == 0) {
167
                                        if ( (range > 0) and (range <= _range) ) {
168
                                            var nTcasThreat = ac.getNode("tcas/threat-level");
169
                                            if (nTcasThreat != nil) {
170
                                                var level = nTcasThreat.getValue();
171
                                                if (level > _minLevel) {
172
                                                    var lat     = ac.getNode("position/latitude-deg").getValue();
173
                                                    var lon     = ac.getNode("position/longitude-deg").getValue();
174
                                                    var aAlt    = ac.getNode("position/altitude-ft").getValue();
175
                                                    var vs      = ac.getNode("velocities/vertical-speed-fps").getValue();
176
                                                    var alt     = math.floor(((aAlt - data.alt) / 100) + 0.5);
177
                                                    if (debug.isnan(lat) == 0 and
178
                                                        debug.isnan(lon) == 0 and
179
                                                        debug.isnan(vs)  == 0 and
180
                                                        debug.isnan(alt) == 0) {
181
                                                            append(tcas_dirty, {
182
                                                                lat: lat,
183
                                                                lon: lon,
184
                                                                vs: vs,
185
                                                                alt: alt,
186
                                                                level: level,
187
                                                            });
188
                                                    } } } } } } } }
189
                        data.tcas = tcas_dirty;
190
                    }
191
                );
192
                data.timers.tcas.start();
193
            }
194
        }
195
        else {
196
            delete(m.softkeys.bindings.PFD.INSET, 'TRAFFIC');
197
            delete(m.softkeys.bindings.MFD.MAP,   'TRAFFIC');
198
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
199
        m.display.showInitProgress();
200

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

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
236
var powerOff = func {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
237
    foreach (var listener; keys(data.listeners)) {
238
        if (listener == '/instrumentation/zkv1000/serviceable')
239
            continue;
add autopwer
Sébastien MARQUE authored on 2020-05-07
240
        removelistener(data.listeners[listener]);
poweroff improved
Sébastien MARQUE authored on 2020-05-16
241
        delete(data.listeners, listener);
242
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
243

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
244
    foreach (var timer; keys(data.timers)) {
245
        data.timers[timer].stop();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
246
        if (timer == '20Hz' or timer == '1Hz')
247
            continue;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
248
        delete(data.timers, timer);
249
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
250

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
251
    foreach (var k; keys(autopilot))
252
        delete(autopilot, k);
253

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
254
    foreach (var name; keys(flightdeck)) {
255
        flightdeck[name].off();
poweroff improved
Sébastien MARQUE authored on 2020-05-16
256
        flightdeck[name] = nil;
add a way to power off
Sébastien MARQUE authored on 2020-05-06
257
    }
258
}
259

            
PFD+MFD allumés ensemble
Sébastien MARQUE authored on 2017-03-11
260
var powerOn = func {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
261
    if (!zkv.getValue('serviceable')) {
262
        msg('not yet serviceable (check power)!');
263
        return;
264
    }
265

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
266
    if (contains(data.listeners, '/instrumentation/zkv1000/serviceable')) {
267
        removelistener(data.listeners['/instrumentation/zkv1000/serviceable']);
268
        delete(data.listeners, '/instrumentation/zkv1000/serviceable');
269
    }
add autopwer
Sébastien MARQUE authored on 2020-05-07
270

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

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

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

            
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
284
    if (! contains(data.timers, 'listeners')) {
poweroff improved
Sébastien MARQUE authored on 2020-05-16
285
        data.timers.listeners = maketimer(1, setListeners);
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
286
        data.timers.listeners.singleShot = 1;
287
        data.timers.listeners.start();
288
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
289
}