zkv1000 / Nasal / core.nas /
Newer Older
176 lines | 8.353kb
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,
58
            func (n) foreach (var c; keys(flightdeck))
59
                    flightdeck[c].map.layers.route.onCurrentWaypointChange(n),
60
                0, 1);
61

            
62
    prop = '/autopilot/route-manager/active';
63
    data.listeners[prop] = setlistener(prop,
64
            func foreach (var c; keys(flightdeck))
65
                    flightdeck[c].map.layers.route.onCurrentWaypointChange(props.globals.getNode('/autopilot/route-manager/current-wp')),
66
                0, 1);
NAV disponible (hors CDI)
Sébastien MARQUE authored on 2017-03-11
67
}
68

            
commit initial
Sébastien MARQUE authored on 2017-03-07
69
var deviceClass = {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
70
    new: func (name) {
commit initial
Sébastien MARQUE authored on 2017-03-07
71
        var m = { parents: [ deviceClass ] };
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
72
        m.name = name;
73
        m.role = substr(name, 0, 3);
74
        m.node = zkv.getNode(name, 1);
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
75
        m.data = {};
first attempt to centralize ...
Sébastien MARQUE authored on 2017-04-15
76
        m.timers = {};
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
77
        foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide'])
add V-speeds bugs
Sébastien MARQUE authored on 2017-04-04
78
            m.data[v ~ '-visible'] = 1;
configurable display size, v...
Sébastien MARQUE authored on 2017-04-15
79
        foreach (var v; ['screen-object', 'screen-view', 'screen-size'])
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
80
            m.data[v] = getprop(zkv.getPath() ~ '/' ~ name ~ '/' ~ v);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
81

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

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
89
        if (! contains(data.timers, 'alt-setting-inhg')) {
90
            data.timers['alt-setting-inhg'] = maketimer(0.1, m, func {
91
                    var inhg = getprop('/instrumentation/altimeter/setting-inhg');
92
                    if (inhg != misc.getValue('alt-setting-inhg'))
93
                        misc.getNode('alt-setting-inhg').setValue(inhg);
94
                });
95
            data.timers['alt-setting-inhg'].start();
96
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
97
        if (! contains(data.timers, 'map')) {
98
            data.timers.map = maketimer(1, m, func {
99
                    foreach (var d; keys(flightdeck))
100
                        flightdeck[d].map.update();
101
                    var gspd = getprop('/velocities/groundspeed-kt');
102
                    if (gspd != 0)
103
                        var next = (me.data['range-nm']/(gspd/3600))/(me.display.display.get('view[1]')/2);
104
                    else
105
                        var next = 10;
106
                    if (next > 10)
107
                        next = 10;
108
                    data.timers.map.restart(next);
109
                });
110
            data.timers.map.singleShot = 1;
111
            data.timers.map.start();
112
        }
add TCAS
Sébastien MARQUE authored on 2017-12-21
113
        if (getprop('/instrumentation/tcas/serviceable') != nil) {
114
            m.data.tcas = 0;
115
            if (!contains(data.timers, 'tcas')) {
116
                data.timers.tcas = maketimer ( 1,
117
                    func {
118
                        var tcas_dirty = [];
119
                        var _range = 6;
120
                        var _minLevel = -1;
121
                        foreach (var ac; props.globals.getNode("/ai/models").getChildren("multiplayer")) {
122
                            if (ac.getValue("valid")) {
123
                                var range = ac.getNode("radar/range-nm").getValue();
124
                                if (range != nil) {
125
                                    if (debug.isnan(range) == 0) {
126
                                        if ( (range > 0) and (range <= _range) ) {
127
                                            var nTcasThreat = ac.getNode("tcas/threat-level");
128
                                            if (nTcasThreat != nil) {
129
                                                var level = nTcasThreat.getValue();
130
                                                if (level > _minLevel) {
131
                                                    var lat     = ac.getNode("position/latitude-deg").getValue();
132
                                                    var lon     = ac.getNode("position/longitude-deg").getValue();
133
                                                    var aAlt    = ac.getNode("position/altitude-ft").getValue();
134
                                                    var vs      = ac.getNode("velocities/vertical-speed-fps").getValue();
135
                                                    var alt     = math.floor(((aAlt - data.alt) / 100) + 0.5);
136
                                                    if (debug.isnan(lat) == 0 and
137
                                                        debug.isnan(lon) == 0 and
138
                                                        debug.isnan(vs)  == 0 and
139
                                                        debug.isnan(alt) == 0) {
140
                                                            append(tcas_dirty, {
141
                                                                lat: lat,
142
                                                                lon: lon,
143
                                                                vs: vs,
144
                                                                alt: alt,
145
                                                                level: level,
146
                                                            });
147
                                                    } } } } } } } }
148
                        data.tcas = tcas_dirty;
149
                    }
150
                );
151
                data.timers.tcas.start();
152
            }
153
        }
154
        else {
155
            delete(m.softkeys.bindings.PFD.INSET, 'TRAFFIC');
156
            delete(m.softkeys.bindings.MFD.MAP,   'TRAFFIC');
157
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
158
        m.display.showInitProgress();
159

            
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
160
        setprop(zkv.getPath() ~ '/' ~ m.name ~ '/status', 1);
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
161
        msg(m.name ~ ' switched on!');
commit initial
Sébastien MARQUE authored on 2017-03-07
162
        return m;
163
    },
164
};
165

            
PFD+MFD allumés ensemble
Sébastien MARQUE authored on 2017-03-11
166
var powerOn = func {
global timers started at pow...
Sébastien MARQUE authored on 2017-04-12
167
    foreach (var freq; keys(data.timers))
168
        data.timers[freq].start();
169

            
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
170
    foreach (var name; keys(flightdeck))
171
        if (zkv.getNode(name) != nil)
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
172
#            thread.newthread(func {
improves role/name variables...
Sébastien MARQUE authored on 2017-04-08
173
                flightdeck[name] = deviceClass.new(name);
new var organistaion (and fi...
Sébastien MARQUE authored on 2017-03-26
174
#            });
correction listeners
Sébastien MARQUE authored on 2017-03-12
175
    settimer(setListeners, 5);
commit initial
Sébastien MARQUE authored on 2017-03-07
176
}