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

            
85
    prop = zkv.getPath() ~ '/serviceable';
86
    data.listeners[prop] = setlistener(prop, zkv1000.powerOff, 0, 0);
87

            
88
    # the timer isn't necessary anymore
89
    data.timers.listeners.stop();
90
    delete(data.timers, 'listeners');
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
91
}
92

            
commit initial
Sébastien MARQUE authored on 2017-03-07
93
var deviceClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
94
    new: func (name) {
commit initial
Sébastien MARQUE authored on 2017-03-07
95
        var m = { parents: [ deviceClass ] };
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
96
        m.name = name;
97
        m.role = substr(name, 0, 3);
98
        m.node = zkv.getNode(name, 1);
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
99
        m.data = {};
first attempt to centralize ...
Sébastien MARQUE authored on 2017-04-15
100
        m.timers = {};
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
101
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide'])
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
102
            m.data[v ~ '-visible'] = 1;
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
103
        foreach (var v; ['screen-object', 'screen-view', 'screen-size'])
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
104
            m.data[v] = getprop(zkv.getPath() ~ '/' ~ name ~ '/' ~ v);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
105

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

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

            
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
184
        setprop(zkv.getPath() ~ '/' ~ m.name ~ '/status', 1);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
185
        msg(m.name ~ ' switched on!');
commit initial
Sébastien MARQUE authored on 2017-03-07
186
        return m;
187
    },
add a way to power off
Sébastien MARQUE authored on 2020-05-06
188
    off: func {
189
        foreach (var timer; keys(me.timers)) {
190
            me.timers[timer].stop();
191
            delete(me.timers, timer);
192
        }
193
        foreach (var member; keys(me)) {
194
            if (contains(me[member], 'off')) me[class].off();
195
            delete(me, member);
196
        }
197
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
198
};
199

            
add a way to power off
Sébastien MARQUE authored on 2020-05-06
200
var powerOff = func {
201
    foreach (var timer; keys(data.timers)) {
202
        data.timers[timer].stop();
203
        delete(data.timers, timer);
204
    }
205
    foreach (var name; keys(flightdeck)) {
206
        flightdeck[name].off();
207
        delete(flightdeck, name);
208
        setprop(zkv.getPath() ~ '/' ~ name ~ '/status', 0);
209
    }
210
}
211

            
PFD+MFD allumés ensemble
Sébastien MARQUE authored on 2017-03-11
212
var powerOn = func {
add a way to power off
Sébastien MARQUE authored on 2020-05-06
213
    if (!zkv.getValue('serviceable')) {
214
        msg('not yet serviceable (check power)!');
215
        return;
216
    }
217

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

            
adds AFCS
Sébastien MARQUE authored on 2020-05-06
221
    autopilot = APClass.new();
222

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
223
    foreach (var name; keys(flightdeck))
224
        if (zkv.getNode(name) != nil)
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
225
#            thread.newthread(func {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
226
                flightdeck[name] = deviceClass.new(name);
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
227
#            });
replace settimer by maketime...
Sébastien MARQUE authored on 2020-05-06
228

            
229
    if (! contains(data.timers, 'listeners')) {
230
        data.timers.listeners = maketimer(5, setListeners);
231
        data.timers.listeners.singleShot = 1;
232
        data.timers.listeners.start();
233
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
234
}