zkv1000 / zkv1000.nas /
Newer Older
301 lines | 11.639kb
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',
topo display is now availabl...
Sébastien MARQUE authored on 2020-06-14
13
    'maps/topo.nas',
add track display
Sébastien MARQUE authored on 2021-05-13
14
    'maps/track.nas',
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
15
    'map.nas',     # moves the maps
commit initial
Sébastien MARQUE authored on 2017-03-07
16
    'display.nas',
add window management
Sébastien MARQUE authored on 2017-03-28
17
    'menu.nas',    # manage windows
commit initial
Sébastien MARQUE authored on 2017-03-07
18
    'core.nas',    # the scheduler and switch on button
adds AFCS
Sébastien MARQUE authored on 2020-05-06
19
    'afcs.nas',    # Automatic Flight Control System
adds alerting system
Sébastien MARQUE authored on 2020-07-09
20
    'annunciations.nas',  # in flight tests
commit initial
Sébastien MARQUE authored on 2017-03-07
21
];
22
#    'routes.nas',  # manages flightplans and routes
23
#    'display.nas', # display messages and popups
24
#    'infos.nas',   # get informations from environment
25
#    'mud.nas',     # displays simple embedded GUI (Multi-Use Display)
26

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

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

            
adds alerting system
Sébastien MARQUE authored on 2020-07-09
31
var annunciations = {};
32

            
settings now have effect
Sébastien MARQUE authored on 2020-06-12
33
var units = {
34
    speed : {
35
        from_kt  : 1,
36
        from_kmh : MPS2KT * 3.6,
37
    },
38
    altitude : {
39
        from_ft : 1,
40
        from_m  : M2FT,
41
    },
42
    vspeed : {
43
        from_fpm : 1,
44
        from_mpm : M2FT,
45
    },
46
    distance : {
47
        from_m : M2NM / 1000,
48
        from_nm : 1,
49
    },
adds temperature units setti...
Sébastien MARQUE authored on 2020-06-15
50
    temperature : {
51
        from_C : func (c) return c,
52
        from_F : func (f) return (f -32) / 1.8,
53
    },
adds volume settings
Sébastien MARQUE authored on 2020-06-18
54
    volume: {
55
        from_l: 1,
56
        from_gal: 3.78541178,
57
        from_m3: 1000,
58
    },
settings now have effect
Sébastien MARQUE authored on 2020-06-12
59
};
60

            
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
61
var data = { # set of data common to all devices
62
    roll : 0,
63
    pitch : 0,
64
    vsi : 0,
65
    ias : 0,
66
    alt : 0,
67
    hdg : 0,
add periodicly updated track...
Sébastien MARQUE authored on 2021-05-13
68
    trk : 0,
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
69
    wow : 1,
put lat/lon in global data s...
Sébastien MARQUE authored on 2017-04-12
70
    lat : 0,
71
    lon : 0,
adds AOA display
Sébastien MARQUE authored on 2017-04-15
72
    aoa : 0,
change way of time display
Sébastien MARQUE authored on 2020-06-12
73
    time : '23:59:59',
adds flight plan catalog loa...
Sébastien MARQUE authored on 2020-06-08
74
    fpSize : 0,
add TCAS
Sébastien MARQUE authored on 2017-12-21
75
    tcas: [],
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
76
    tcas_level: 0,
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
77
    Vspeeds : {},
creates settings management
Sébastien MARQUE authored on 2020-05-16
78
    settings: {
79
        units: {
80
            pressure: 'inhg',
81
            altitude: 'ft',
82
            speed: 'knots',
83
            distance: 'nm',
84
            vertical: 'fpm',
85
        },
adds time display setting
Sébastien MARQUE authored on 2020-06-11
86
        time: {
87
            label: 'GMT',
88
            actual: '  GMT >',
89
        },
creates settings management
Sébastien MARQUE authored on 2020-05-16
90
    },
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
91
    timers : {
92
        '20Hz': maketimer (
93
            0.05,
94
            func {
95
                data.roll = getprop('/orientation/roll-deg');
96
                data.pitch = getprop('orientation/pitch-deg');
settings now have effect
Sébastien MARQUE authored on 2020-06-12
97
                data.vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm') * units.vspeed.from_fpm;
98
                data.ias = getprop('/velocities/airspeed-kt') * units.speed.from_kt;
99
                data.alt = getprop('/instrumentation/altimeter/indicated-altitude-ft') * units.altitude.from_ft;
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
100
                data.hdg = getprop('/orientation/heading-deg');
add periodicly updated track...
Sébastien MARQUE authored on 2021-05-13
101
                data.trk = data.wow ? data.hdg : getprop('/orientation/track-deg');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
102
                data.aoa = getprop('/orientation/alpha-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
103
            }
104
        ),
105
        '1Hz': maketimer (
106
            1,
107
            func {
108
                data.wow = getprop('/gear/gear/wow');
put lat/lon in global data s...
Sébastien MARQUE authored on 2017-04-12
109
                data.lat = getprop('/position/latitude-deg');
110
                data.lon = getprop('/position/longitude-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
111
            }
112
        ),
113
    },
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
114
    listeners : {},
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
115
};
116

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

            
119
var init_props = func {
120
    zkv = props.globals.getNode('/instrumentation/zkv1000',1);
adds the avaibility to have ...
Sébastien MARQUE authored on 2017-04-07
121
    foreach (var d; zkv.getChildren())
122
        if (d.getNode('status') != nil)
123
            flightdeck[d.getName()] = nil;
commit initial
Sébastien MARQUE authored on 2017-03-07
124
    zkv.getNode('emission',1).setDoubleValue(0.5);
125
    zkv.getNode('body-emission',1).setDoubleValue(0.0);
126
    zkv.getNode('body-texture',1).setValue('');
add brightness and lights co...
Sébastien MARQUE authored on 2020-04-27
127
    zkv.getNode('display-brightness-norm',1).setDoubleValue(0.5);
128
    zkv.getNode('lightmap',1).setIntValue(0);
add possibility to resize th...
Sébastien MARQUE authored on 2020-05-09
129
    if (zkv.getNode('size-factor').getValue() == nil)
130
        zkv.getNode('size-factor',1).setDoubleValue(1.0);
adds flight plan catalog loa...
Sébastien MARQUE authored on 2020-06-08
131
    if (zkv.getValue('flightplans') != nil and io.stat(zkv.getValue('flightplans')) == "dir")
132
        data.flightplans = zkv.getValue('flightplans');
133
    else
134
        data.flightplans = getprop('/sim/fg-home') ~ '/Export';
commit initial
Sébastien MARQUE authored on 2017-03-07
135

            
136
    radios = zkv.getNode('radios', 1);
137
    radios.getNode('nav1-selected',1).setIntValue(0);
138
    radios.getNode('nav1-standby',1).setIntValue(0);
139
    radios.getNode('nav2-selected',1).setIntValue(0);
140
    radios.getNode('nav2-standby',1).setIntValue(0);
141
    radios.getNode('nav-tune',1).setIntValue(0);
142
    radios.getNode('nav-freq-mhz',1).alias('/instrumentation/nav/frequencies/standby-mhz');
143
    radios.getNode('comm1-selected',1).setIntValue(1);
144
    radios.getNode('comm2-selected',1).setIntValue(0);
145
    radios.getNode('comm-tune',1).setIntValue(0);
146
    radios.getNode('comm-freq-mhz',1).alias('/instrumentation/comm/frequencies/standby-mhz');
147
    radios.getNode('xpdr-mode',1).setValue('GND');
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
148
    radios.getNode('brg1-source',1).setValue('OFF');
149
    radios.getNode('brg2-source',1).setValue('OFF');
commit initial
Sébastien MARQUE authored on 2017-03-07
150

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
151
    cdi = zkv.getNode('cdi', 1);
152
    cdi.getNode('source', 1).setValue('OFF');
153
    cdi.getNode('no-flag', 1).setBoolValue(0);
154
    cdi.getNode('FROM-flag', 1).alias('no-flag');
155
    cdi.getNode('TO-flag', 1).alias('no-flag');
156
    cdi.getNode('course', 1);
157
    cdi.getNode('course-deflection', 1);
158
    cdi.getNode('radial', 1);
159
    cdi.getNode('in-range', 1);
160

            
commit initial
Sébastien MARQUE authored on 2017-03-07
161
    alerts = zkv.getNode('alerts',1);
162
    alerts.getNode('traffic-proximity',1).setIntValue(0);
163
    alerts.getNode('marker-beacon', 1).setIntValue(0);
164
    alerts.getNode('warning', 1).setBoolValue(0);
165
    alerts.getNode('alert', 1).setBoolValue(0);
166
    alerts.getNode('message', 1).setValue('');
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
167
    foreach (var v; alerts.getChildren())
168
        if (string.match(v.getName(), 'V[a-z0-9]*'))
169
            data.Vspeeds[v.getName()] = v.getValue();
170

            
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
171
    var aoa = alerts.getValue('stall-aoa');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
172
    data['stall-aoa'] = (aoa == nil or aoa == 0) ? 9999 : aoa;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
173
    aoa = alerts.getValue('approach-aoa');
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
174
    if (aoa != nil)
175
        data['approach-aoa'] = aoa;
commit initial
Sébastien MARQUE authored on 2017-03-07
176

            
177
    afcs = zkv.getNode('afcs',1);
178
    afcs.getNode('fd-bars-visible',1).setBoolValue(0);
179
    afcs.getNode('alt-bug-visible',1).setBoolValue(0);
afcs improvements
Sébastien MARQUE authored on 2020-05-17
180
    afcs.getNode('heading-bug-deg',1).setDoubleValue(int(getprop('/orientation/heading-magnetic-deg')));
commit initial
Sébastien MARQUE authored on 2017-03-07
181
    afcs.getNode('target-pitch-deg',1).setDoubleValue(0.0);
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
182
    afcs.getNode('selected-alt-ft',1).setIntValue(2000);
commit initial
Sébastien MARQUE authored on 2017-03-07
183
    afcs.getNode('selected-alt-ft-diff',1).setDoubleValue(0.0);
184
    afcs.getNode('selected-ias-kt-diff',1).setDoubleValue(0.0);
185
    afcs.getNode('vertical-speed-fpm',1).setDoubleValue(0.0);
186
    afcs.getNode('roll-armed', 1).setBoolValue(0);
187
    afcs.getNode('pitch-armed', 1).setBoolValue(0);
188
    afcs.getNode('roll-armed-mode-text',1).setValue('');
189
    afcs.getNode('roll-active-mode-text',1).setValue('');
190
    afcs.getNode('roll-armed-mode',1).setIntValue(0);
191
    afcs.getNode('roll-active-mode',1).setIntValue(0);
192
    afcs.getNode('roll-active-mode-blink',1).setBoolValue(0);
193
    afcs.getNode('pit-armed-mode-text',1).setValue('');
194
    afcs.getNode('pit-active-mode-text',1).setValue('');
195
    afcs.getNode('pit-armed-mode',1).setIntValue(0);
196
    afcs.getNode('pit-active-mode',1).setIntValue(0);
197
    afcs.getNode('pit-active-mode-blink',1).setBoolValue(0);
198
    afcs.getNode('route',1);
199

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

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

            
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
205
    eis = zkv.getNode('eis',1);
206
    eis.getNode('fuel-qty-at-start', 1).setValue(
207
        getprop('/consumables/fuel/tank/level-gal_us')
208
      + getprop('/consumables/fuel/tank/level-gal_us'));
209

            
moves some map infos in data...
Sébastien MARQUE authored on 2017-04-11
210
    var tiles_defaults = {
211
        # see https://www.wikimedia.org/wiki/Maps
212
        server: 'maps.wikimedia.org',
213
        type:   'osm-intl',
214
        apikey: '',
add options for online tiles
Sébastien MARQUE authored on 2017-05-14
215
        format: 'png',
216
        template: 'https://{server}/{type}/{z}/{x}/{y}.{format}{apikey}',
moves some map infos in data...
Sébastien MARQUE authored on 2017-04-11
217
    };
218
    foreach (var v; keys(tiles_defaults)) {
219
        var val = getprop('/sim/online-tiles-' ~ v);
220
        data['tiles-' ~ v] = val != nil ? val : tiles_defaults[v];
221
    }
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
222

            
commit initial
Sébastien MARQUE authored on 2017-03-07
223
    props.globals.getNode('/instrumentation/transponder/id-code',1).setIntValue(1200);
224
    props.globals.getNode('/instrumentation/transponder/serviceable',1).setBoolValue(1);
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
225
    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
226
    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
227
    props.globals.getNode('/autopilot/settings/target-speed-kt',1).setDoubleValue(0.0);
228
    props.globals.getNode('/autopilot/settings/vertical-speed-fpm',1).setDoubleValue(0.0);
229
    props.globals.getNode('/autopilot/internal/target-pitch-deg',1).setDoubleValue(0.0);
230
    props.globals.getNode('/autopilot/internal/flc-altitude-pitch-deg',1).setDoubleValue(0.0);
231
    props.globals.getNode('/autopilot/internal/flc-airspeed-pitch-deg',1).setDoubleValue(0.0);
232
    props.globals.getNode('/autopilot/internal/target-roll-deg',1).setDoubleValue(0.0);
233
    props.globals.getNode('/autopilot/locks/pitch',1).setValue('');
234
    props.globals.getNode('/autopilot/locks/roll',1).setValue('');
235
    props.globals.getNode('/autopilot/locks/passive-mode', 1).setIntValue(1);
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
236

            
allows zkv1000 to be install...
Sébastien MARQUE authored on 2017-05-11
237
    data.zkv1000_reldir = io.dirname(getprop('/nasal/zkv1000/file'));
238
    data.zkv1000_dir = string.normpath(
239
            io.dirname(getprop('/sim/aircraft-dir'))
240
            ~ '/'
241
            ~ string.replace(data.zkv1000_reldir, split('/', data.zkv1000_reldir)[0], '')
242
        ) ~ '/';
commit initial
Sébastien MARQUE authored on 2017-03-07
243
}
244

            
245
var load_nasal = func {
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
246
    var nasal_dir = data.zkv1000_dir ~ 'Nasal/';
commit initial
Sébastien MARQUE authored on 2017-03-07
247
    for (var i = 0; i < size(files_to_load); i += 1)
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
248
        io.load_nasal(nasal_dir ~ files_to_load[i], 'zkv1000');
commit initial
Sébastien MARQUE authored on 2017-03-07
249
    files_to_load = nil;
250
}
251

            
252
var load_multikey = func {
253
    fgcommand('loadxml', props.Node.new({
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
254
        'filename': data.zkv1000_dir ~ 'Systems/multikey.xml',
commit initial
Sébastien MARQUE authored on 2017-03-07
255
        'targetnode': '/input/keyboard/'
256
    }));
257
    multikey.init();
258
}
259

            
adds settings storage and re...
Sébastien MARQUE authored on 2020-06-17
260
var load_settings = func {
261
    var settings_file = getprop('/sim/fg-home') ~ '/aircraft-data/zkv1000.xml';
262
    if (io.stat(settings_file) != nil) {
263
        fgcommand('loadxml', props.Node.new({ filename: settings_file, targetnode: zkv.getNode('save', 1).getPath() }));
264
        var xmlsettings = zkv.getNode('save/' ~ getprop('/sim/aircraft'));
265
        if (xmlsettings != nil) {
266
            foreach (var domain; keys(units))
267
                foreach (var from; keys(units[domain])) {
268
                    if (xmlsettings.getNode(domain) != nil) {
269
                        var unit_value = xmlsettings.getNode(domain).getValue(from);
270
                        if (unit_value != nil) {
271
                            if (typeof(units[domain][from]) == 'scalar')
272
                                units[domain][from] = unit_value;
273
                            if (typeof(units[domain][from]) == 'func') {
274
                                units[domain][from] = compile(unit_value);
275
                                units[domain][from](0);
276
                            }
277
                        }
278
                    }
279
                }
280
            data.settings.units.pressure = xmlsettings.getNode('pressure').getValue();
281
        }
282
        zkv.getNode('save').remove();
283
    }
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
284
    foreach (var V; keys(data.Vspeeds))
285
        data.Vspeeds[V] *= units.speed.from_kt;
adds settings storage and re...
Sébastien MARQUE authored on 2020-06-17
286
}
287

            
commit initial
Sébastien MARQUE authored on 2017-03-07
288
var zkv1000_init = func {
init listener needed only on...
Sébastien MARQUE authored on 2017-03-13
289
    removelistener(init);
commit initial
Sébastien MARQUE authored on 2017-03-07
290
    init_props();
adds settings storage and re...
Sébastien MARQUE authored on 2020-06-17
291
    load_settings();
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
292
    load_multikey();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
293
    load_nasal();
improve auto-power
Sébastien MARQUE authored on 2020-05-16
294
    msg('loaded');
295
    if (zkv.getValue('auto-power')) {
296
        var prop = zkv.getNode('serviceable',1).getPath();
297
        data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0);
298
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
299
}
300

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