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

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

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

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

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

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

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

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

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
145
    cdi = zkv.getNode('cdi', 1);
146
    cdi.getNode('source', 1).setValue('OFF');
147
    cdi.getNode('no-flag', 1).setBoolValue(0);
148
    cdi.getNode('FROM-flag', 1).alias('no-flag');
149
    cdi.getNode('TO-flag', 1).alias('no-flag');
150
    cdi.getNode('course', 1);
151
    cdi.getNode('course-deflection', 1);
152
    cdi.getNode('radial', 1);
153
    cdi.getNode('in-range', 1);
154

            
commit initial
Sébastien MARQUE authored on 2017-03-07
155
    alerts = zkv.getNode('alerts',1);
156
    alerts.getNode('traffic-proximity',1).setIntValue(0);
157
    alerts.getNode('marker-beacon', 1).setIntValue(0);
158
    alerts.getNode('warning', 1).setBoolValue(0);
159
    alerts.getNode('alert', 1).setBoolValue(0);
160
    alerts.getNode('message', 1).setValue('');
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
161
    foreach (var v; ['Vx', 'Vy', 'Vr', 'Vglide', 'Vne']) {
settings now have effect
Sébastien MARQUE authored on 2020-06-12
162
        var speed = alerts.getValue(v) * units.speed.from_kt;
put Vspeeds in common data s...
Sébastien MARQUE authored on 2017-04-11
163
        data[v] = speed != nil ? speed : 9999;
164
    }
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
165
    var aoa = alerts.getValue('stall-aoa');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
166
    data['stall-aoa'] = (aoa == nil or aoa == 0) ? 9999 : aoa;
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
167
    aoa = alerts.getValue('approach-aoa');
nicer AOA display
Sébastien MARQUE authored on 2017-04-16
168
    if (aoa != nil)
169
        data['approach-aoa'] = aoa;
commit initial
Sébastien MARQUE authored on 2017-03-07
170

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

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

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

            
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
199
    eis = zkv.getNode('eis',1);
200
    eis.getNode('fuel-qty-at-start', 1).setValue(
201
        getprop('/consumables/fuel/tank/level-gal_us')
202
      + getprop('/consumables/fuel/tank/level-gal_us'));
203

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

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

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

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

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

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

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

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