zkv1000 / Nasal / core.nas /
Newer Older
293 lines | 12.758kb
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
        }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
154
        if (!contains(data.timers, 'tcas')) {
155
            data.timers.tcas = maketimer ( 5, func {
156
                var traffic_displayed = 0;
157
                foreach (var name; keys(flightdeck))
158
                    traffic_displayed += flightdeck[name].map.layers.tcas.group.getVisible();
159
                var tcas_dirty = [];
160
                var level_dirty = 0;
161
                foreach (var AItype; [ 'aircraft', 'multiplayer' ])
162
                    foreach (var ac; props.globals.getNode("/ai/models").getChildren(AItype)) {
163
                        if (ac.getValue("valid")) {
164
                            var lat = ac.getNode("position/latitude-deg").getValue();
165
                            var lon = ac.getNode("position/longitude-deg").getValue();
166
                            var alt = ac.getNode("position/altitude-ft").getValue();
167
                            var vs  = ac.getNode("velocities/vertical-speed-fps").getValue();
168
                            if (isnum(lat) and isnum(lon) and isnum(vs) and isnum(alt)) {
169
                                alt = math.floor(((alt - data.alt) / 100) + 0.5);
170
                                var (course, dist) = courseAndDistance(lat, lon,
171
                                                     geo.Coord.new().set_latlon(data.lat, data.lon));
172
                                if (dist < 50) {
173
                                    var dir = ac.getNode('orientation/true-heading-deg').getValue() - course;
174
                                    if (dist < 5 and abs(alt) < 10)
175
                                        level = 3;
176
                                    elsif (dist < 10 and alt * vs < 0 and abs(dir) < 10)
177
                                        level = 3;
178
                                    elsif (dist < 15 and abs(alt) < 5)
179
                                        level = 2;
180
                                    elsif (dist < 15 and abs(alt) < 50)
181
                                        level = 1;
182
                                    else
183
                                        level = 0;
184
                                    level_dirty = level > level_dirty ? level : level_dirty;
185
                                    if (traffic_displayed)
186
                                        append(tcas_dirty, {
187
                                            lat: lat,
188
                                            lon: lon,
189
                                            vs: vs,
190
                                            alt: alt,
191
                                            level: level,
192
                                            callsign: ac.getValue('callsign')
193
                                        });
194
                                }
195
                            }
196
                        }
add TCAS
Sébastien MARQUE authored on 2017-12-21
197
                    }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
198
                data.tcas = tcas_dirty;
199
                data.tcas_level = level_dirty;
200
            });
201
            data.timers.tcas.start();
add TCAS
Sébastien MARQUE authored on 2017-12-21
202
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
203
        m.display.showInitProgress();
204

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

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

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

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
255
    foreach (var k; keys(autopilot))
256
        delete(autopilot, k);
257

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

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

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

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

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

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

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