zkv1000 / zkv1000.nas /
Newer Older
314 lines | 12.038kb
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
    },
add pressure conversion inHg...
Sébastien MARQUE authored on 2023-08-06
59
    pressure: {
60
        from_inhg: 1,
61
        from_hpa: 0.02953,
62
    },
settings now have effect
Sébastien MARQUE authored on 2020-06-12
63
};
64

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
commit initial
Sébastien MARQUE authored on 2017-03-07
292
var zkv1000_init = func {
init listener needed only on...
Sébastien MARQUE authored on 2017-03-13
293
    removelistener(init);
commit initial
Sébastien MARQUE authored on 2017-03-07
294
    init_props();
adds settings storage and re...
Sébastien MARQUE authored on 2020-06-17
295
    load_settings();
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
296
    load_multikey();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
297
    load_nasal();
improve auto-power
Sébastien MARQUE authored on 2020-05-16
298
    msg('loaded');
299
    if (zkv.getValue('auto-power')) {
improve power on and off usi...
Sébastien MARQUE authored on 2023-08-08
300
        if (zkv.getNode('serviceable',1).getAttribute("alias") == 1) {
301
            data.timers.serviceable = maketimer(1, func {
302
                if (zkv.getNode('serviceable').getValue() != 0)
303
                    zkv1000.powerOn();
304
            });
305
            data.timers.serviceable.start();
306
        }
307
        else {
308
            var prop = zkv.getNode('serviceable',1).getPath();
309
            data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0);
310
        }
improve auto-power
Sébastien MARQUE authored on 2020-05-16
311
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
312
}
313

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