zkv1000 / zkv1000.nas /
Newer Older
232 lines | 9.393kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
# Nasal files to be loaded at start
2
# the order could be important as some files need other one to be loaded first
3
files_to_load = [
4
    'lib.nas',     # some useful functions, should stay first loaded
Correction swap NAV tuning
Sébastien MARQUE authored on 2017-03-12
5
    'radios.nas',  # all about radios COMM, NAV, XPDR
commit initial
Sébastien MARQUE authored on 2017-03-07
6
    'knobs.nas',   # handles knobs
7
    'buttons.nas', # handles knobs and buttons
8
    'softkeys.nas',# handles softkeys and menus items
adds route display on map
Sébastien MARQUE authored on 2017-05-11
9
    'maps/route.nas',
separates maps code
Sébastien MARQUE authored on 2017-05-11
10
    'maps/navaids.nas',
11
    'maps/tiles.nas',
add TCAS
Sébastien MARQUE authored on 2017-12-21
12
    'maps/tcas.nas',
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
13
    'map.nas',     # moves the maps
commit initial
Sébastien MARQUE authored on 2017-03-07
14
    'display.nas',
add window management
Sébastien MARQUE authored on 2017-03-28
15
    'menu.nas',    # manage windows
commit initial
Sébastien MARQUE authored on 2017-03-07
16
    'core.nas',    # the scheduler and switch on button
adds AFCS
Sébastien MARQUE authored on 2020-05-06
17
    'afcs.nas',    # Automatic Flight Control System
commit initial
Sébastien MARQUE authored on 2017-03-07
18
];
19
#    'routes.nas',  # manages flightplans and routes
20
#    'display.nas', # display messages and popups
21
#    'infos.nas',   # get informations from environment
22
#    'alerts.nas',  # in flight tests
23
#    'mud.nas',     # displays simple embedded GUI (Multi-Use Display)
24

            
adds the avaibility to have ...
Sébastien MARQUE authored on 2017-04-07
25
var flightdeck = {};
26

            
adds AFCS
Sébastien MARQUE authored on 2020-05-06
27
var autopilot = {};
28

            
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
29
var data = { # set of data common to all devices
30
    roll : 0,
31
    pitch : 0,
32
    vsi : 0,
33
    ias : 0,
34
    alt : 0,
35
    hdg : 0,
36
    wow : 1,
put lat/lon in global data s...
Sébastien MARQUE authored on 2017-04-12
37
    lat : 0,
38
    lon : 0,
adds AOA display
Sébastien MARQUE authored on 2017-04-15
39
    aoa : 0,
adds flight plan catalog loa...
Sébastien MARQUE authored on 2020-06-08
40
    fpSize : 0,
add TCAS
Sébastien MARQUE authored on 2017-12-21
41
    tcas: [],
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
42
    tcas_level: 0,
creates settings management
Sébastien MARQUE authored on 2020-05-16
43
    settings: {
44
        units: {
45
            pressure: 'inhg',
46
            altitude: 'ft',
47
            speed: 'knots',
48
            distance: 'nm',
49
            vertical: 'fpm',
50
        },
51
    },
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
52
    timers : {
53
        '20Hz': maketimer (
54
            0.05,
55
            func {
56
                data.roll = getprop('/orientation/roll-deg');
57
                data.pitch = getprop('orientation/pitch-deg');
58
                data.vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm');
59
                data.ias = getprop('/velocities/airspeed-kt');
60
                data.alt = getprop('/instrumentation/altimeter/indicated-altitude-ft');
61
                data.hdg = getprop('/orientation/heading-deg');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
62
                data.aoa = getprop('/orientation/alpha-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
63
            }
64
        ),
65
        '1Hz': maketimer (
66
            1,
67
            func {
68
                data.wow = getprop('/gear/gear/wow');
put lat/lon in global data s...
Sébastien MARQUE authored on 2017-04-12
69
                data.lat = getprop('/position/latitude-deg');
70
                data.lon = getprop('/position/longitude-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
71
            }
72
        ),
73
    },
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
74
    listeners : {},
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
75
};
76

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
77
var zkv = cdi = radios = alerts = infos = cursors = afcs = eis = misc = nil;
commit initial
Sébastien MARQUE authored on 2017-03-07
78

            
79
var init_props = func {
80
    zkv = props.globals.getNode('/instrumentation/zkv1000',1);
adds the avaibility to have ...
Sébastien MARQUE authored on 2017-04-07
81
    foreach (var d; zkv.getChildren())
82
        if (d.getNode('status') != nil)
83
            flightdeck[d.getName()] = nil;
commit initial
Sébastien MARQUE authored on 2017-03-07
84
    zkv.getNode('emission',1).setDoubleValue(0.5);
85
    zkv.getNode('body-emission',1).setDoubleValue(0.0);
86
    zkv.getNode('body-texture',1).setValue('');
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
87
    zkv.getNode('display-brightness-norm',1).setDoubleValue(0.5);
88
    zkv.getNode('lightmap',1).setIntValue(0);
add possibility to resize th...
Sébastien MARQUE authored on 2020-05-09
89
    if (zkv.getNode('size-factor').getValue() == nil)
90
        zkv.getNode('size-factor',1).setDoubleValue(1.0);
adds flight plan catalog loa...
Sébastien MARQUE authored on 2020-06-08
91
    if (zkv.getValue('flightplans') != nil and io.stat(zkv.getValue('flightplans')) == "dir")
92
        data.flightplans = zkv.getValue('flightplans');
93
    else
94
        data.flightplans = getprop('/sim/fg-home') ~ '/Export';
commit initial
Sébastien MARQUE authored on 2017-03-07
95

            
96
    radios = zkv.getNode('radios', 1);
97
    radios.getNode('nav1-selected',1).setIntValue(0);
98
    radios.getNode('nav1-standby',1).setIntValue(0);
99
    radios.getNode('nav2-selected',1).setIntValue(0);
100
    radios.getNode('nav2-standby',1).setIntValue(0);
101
    radios.getNode('nav-tune',1).setIntValue(0);
102
    radios.getNode('nav-freq-mhz',1).alias('/instrumentation/nav/frequencies/standby-mhz');
103
    radios.getNode('comm1-selected',1).setIntValue(1);
104
    radios.getNode('comm2-selected',1).setIntValue(0);
105
    radios.getNode('comm-tune',1).setIntValue(0);
106
    radios.getNode('comm-freq-mhz',1).alias('/instrumentation/comm/frequencies/standby-mhz');
107
    radios.getNode('xpdr-mode',1).setValue('GND');
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
108
    radios.getNode('brg1-source',1).setValue('OFF');
109
    radios.getNode('brg2-source',1).setValue('OFF');
commit initial
Sébastien MARQUE authored on 2017-03-07
110

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
111
    cdi = zkv.getNode('cdi', 1);
112
    cdi.getNode('source', 1).setValue('OFF');
113
    cdi.getNode('no-flag', 1).setBoolValue(0);
114
    cdi.getNode('FROM-flag', 1).alias('no-flag');
115
    cdi.getNode('TO-flag', 1).alias('no-flag');
116
    cdi.getNode('course', 1);
117
    cdi.getNode('course-deflection', 1);
118
    cdi.getNode('radial', 1);
119
    cdi.getNode('in-range', 1);
120

            
commit initial
Sébastien MARQUE authored on 2017-03-07
121
    alerts = zkv.getNode('alerts',1);
122
    alerts.getNode('traffic-proximity',1).setIntValue(0);
123
    alerts.getNode('marker-beacon', 1).setIntValue(0);
124
    alerts.getNode('warning', 1).setBoolValue(0);
125
    alerts.getNode('alert', 1).setBoolValue(0);
126
    alerts.getNode('message', 1).setValue('');
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
127
    foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide', 'Vne']) {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
128
        var speed = alerts.getValue(v);
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
129
        data[v] = speed != nil ? speed : 9999;
130
    }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
131
    var aoa = alerts.getValue('stall-aoa');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
132
    data['stall-aoa'] = (aoa == nil or aoa == 0) ? 9999 : aoa;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
133
    aoa = alerts.getValue('approach-aoa');
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
134
    if (aoa != nil)
135
        data['approach-aoa'] = aoa;
commit initial
Sébastien MARQUE authored on 2017-03-07
136

            
137
    afcs = zkv.getNode('afcs',1);
138
    afcs.getNode('fd-bars-visible',1).setBoolValue(0);
139
    afcs.getNode('alt-bug-visible',1).setBoolValue(0);
afcs improvements
Sébastien MARQUE authored on 2020-05-17
140
    afcs.getNode('heading-bug-deg',1).setDoubleValue(int(getprop('/orientation/heading-magnetic-deg')));
commit initial
Sébastien MARQUE authored on 2017-03-07
141
    afcs.getNode('target-pitch-deg',1).setDoubleValue(0.0);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
142
    afcs.getNode('selected-alt-ft',1).setIntValue(2000);
commit initial
Sébastien MARQUE authored on 2017-03-07
143
    afcs.getNode('selected-alt-ft-diff',1).setDoubleValue(0.0);
144
    afcs.getNode('selected-ias-kt-diff',1).setDoubleValue(0.0);
145
    afcs.getNode('vertical-speed-fpm',1).setDoubleValue(0.0);
146
    afcs.getNode('roll-armed', 1).setBoolValue(0);
147
    afcs.getNode('pitch-armed', 1).setBoolValue(0);
148
    afcs.getNode('roll-armed-mode-text',1).setValue('');
149
    afcs.getNode('roll-active-mode-text',1).setValue('');
150
    afcs.getNode('roll-armed-mode',1).setIntValue(0);
151
    afcs.getNode('roll-active-mode',1).setIntValue(0);
152
    afcs.getNode('roll-active-mode-blink',1).setBoolValue(0);
153
    afcs.getNode('pit-armed-mode-text',1).setValue('');
154
    afcs.getNode('pit-active-mode-text',1).setValue('');
155
    afcs.getNode('pit-armed-mode',1).setIntValue(0);
156
    afcs.getNode('pit-active-mode',1).setIntValue(0);
157
    afcs.getNode('pit-active-mode-blink',1).setBoolValue(0);
158
    afcs.getNode('route',1);
159

            
adds flight plan catalog loa...
Sébastien MARQUE authored on 2020-06-08
160
    data.flightplans = getprop('/sim/fg-home') ~ '/Export';
161

            
fix setlistener on tied prop...
Sébastien MARQUE authored on 2020-04-27
162
    misc = zkv.getNode('misc',1);
163
    misc.getNode('alt-setting-inhg',1).setDoubleValue(getprop('/instrumentation/altimeter/setting-inhg'));
164

            
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
165
    eis = zkv.getNode('eis',1);
166
    eis.getNode('fuel-qty-at-start', 1).setValue(
167
        getprop('/consumables/fuel/tank/level-gal_us')
168
      + getprop('/consumables/fuel/tank/level-gal_us'));
169

            
moves some map infos in data...
Sébastien MARQUE authored on 2017-04-11
170
    var tiles_defaults = {
171
        # see https://www.wikimedia.org/wiki/Maps
172
        server: 'maps.wikimedia.org',
173
        type:   'osm-intl',
174
        apikey: '',
add options for online tiles
Sébastien MARQUE authored on 2017-05-14
175
        format: 'png',
176
        template: 'https://{server}/{type}/{z}/{x}/{y}.{format}{apikey}',
moves some map infos in data...
Sébastien MARQUE authored on 2017-04-11
177
    };
178
    foreach (var v; keys(tiles_defaults)) {
179
        var val = getprop('/sim/online-tiles-' ~ v);
180
        data['tiles-' ~ v] = val != nil ? val : tiles_defaults[v];
181
    }
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
182

            
commit initial
Sébastien MARQUE authored on 2017-03-07
183
    props.globals.getNode('/instrumentation/transponder/id-code',1).setIntValue(1200);
184
    props.globals.getNode('/instrumentation/transponder/serviceable',1).setBoolValue(1);
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
185
    props.globals.getNode('/autopilot/settings/heading-bug-deg', 1).alias(afcs.getNode('heading-bug-deg').getPath());
afcs improvements
Sébastien MARQUE authored on 2020-05-17
186
    props.globals.getNode('/autopilot/settings/target-alt-ft',1).alias(afcs.getNode('selected-alt-ft').getPath());
commit initial
Sébastien MARQUE authored on 2017-03-07
187
    props.globals.getNode('/autopilot/settings/target-speed-kt',1).setDoubleValue(0.0);
188
    props.globals.getNode('/autopilot/settings/vertical-speed-fpm',1).setDoubleValue(0.0);
189
    props.globals.getNode('/autopilot/internal/target-pitch-deg',1).setDoubleValue(0.0);
190
    props.globals.getNode('/autopilot/internal/flc-altitude-pitch-deg',1).setDoubleValue(0.0);
191
    props.globals.getNode('/autopilot/internal/flc-airspeed-pitch-deg',1).setDoubleValue(0.0);
192
    props.globals.getNode('/autopilot/internal/target-roll-deg',1).setDoubleValue(0.0);
193
    props.globals.getNode('/autopilot/locks/pitch',1).setValue('');
194
    props.globals.getNode('/autopilot/locks/roll',1).setValue('');
195
    props.globals.getNode('/autopilot/locks/passive-mode', 1).setIntValue(1);
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
196

            
allows zkv1000 to be install...
Sébastien MARQUE authored on 2017-05-11
197
    data.zkv1000_reldir = io.dirname(getprop('/nasal/zkv1000/file'));
198
    data.zkv1000_dir = string.normpath(
199
            io.dirname(getprop('/sim/aircraft-dir'))
200
            ~ '/'
201
            ~ string.replace(data.zkv1000_reldir, split('/', data.zkv1000_reldir)[0], '')
202
        ) ~ '/';
commit initial
Sébastien MARQUE authored on 2017-03-07
203
}
204

            
205
var load_nasal = func {
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
206
    var nasal_dir = data.zkv1000_dir ~ 'Nasal/';
commit initial
Sébastien MARQUE authored on 2017-03-07
207
    for (var i = 0; i < size(files_to_load); i += 1)
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
208
        io.load_nasal(nasal_dir ~ files_to_load[i], 'zkv1000');
commit initial
Sébastien MARQUE authored on 2017-03-07
209
    files_to_load = nil;
210
}
211

            
212
var load_multikey = func {
213
    fgcommand('loadxml', props.Node.new({
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
214
        'filename': data.zkv1000_dir ~ 'Systems/multikey.xml',
commit initial
Sébastien MARQUE authored on 2017-03-07
215
        'targetnode': '/input/keyboard/'
216
    }));
217
    multikey.init();
218
}
219

            
220
var zkv1000_init = func {
init listener needed only on...
Sébastien MARQUE authored on 2017-03-13
221
    removelistener(init);
commit initial
Sébastien MARQUE authored on 2017-03-07
222
    init_props();
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
223
    load_multikey();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
224
    load_nasal();
improve auto-power
Sébastien MARQUE authored on 2020-05-16
225
    msg('loaded');
226
    if (zkv.getValue('auto-power')) {
227
        var prop = zkv.getNode('serviceable',1).getPath();
228
        data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0);
229
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
230
}
231

            
init listener needed only on...
Sébastien MARQUE authored on 2017-03-13
232
var init = setlistener('/sim/signals/fdm-initialized', zkv1000_init, 0, 0);