zkv1000 / zkv1000.nas /
Newer Older
296 lines | 11.489kb
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,
makes Vspeeds free and adapt...
Sébastien MARQUE authored on 2020-06-19
73
    Vspeeds : {},
creates settings management
Sébastien MARQUE authored on 2020-05-16
74
    settings: {
75
        units: {
76
            pressure: 'inhg',
77
            altitude: 'ft',
78
            speed: 'knots',
79
            distance: 'nm',
80
            vertical: 'fpm',
81
        },
adds time display setting
Sébastien MARQUE authored on 2020-06-11
82
        time: {
83
            label: 'GMT',
84
            actual: '  GMT >',
85
        },
creates settings management
Sébastien MARQUE authored on 2020-05-16
86
    },
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
87
    timers : {
88
        '20Hz': maketimer (
89
            0.05,
90
            func {
91
                data.roll = getprop('/orientation/roll-deg');
92
                data.pitch = getprop('orientation/pitch-deg');
settings now have effect
Sébastien MARQUE authored on 2020-06-12
93
                data.vsi = getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm') * units.vspeed.from_fpm;
94
                data.ias = getprop('/velocities/airspeed-kt') * units.speed.from_kt;
95
                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
96
                data.hdg = getprop('/orientation/heading-deg');
adds AOA display
Sébastien MARQUE authored on 2017-04-15
97
                data.aoa = getprop('/orientation/alpha-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
98
            }
99
        ),
100
        '1Hz': maketimer (
101
            1,
102
            func {
103
                data.wow = getprop('/gear/gear/wow');
put lat/lon in global data s...
Sébastien MARQUE authored on 2017-04-12
104
                data.lat = getprop('/position/latitude-deg');
105
                data.lon = getprop('/position/longitude-deg');
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
106
            }
107
        ),
108
    },
listeners stored in data str...
Sébastien MARQUE authored on 2017-05-06
109
    listeners : {},
just moves data structure to...
Sébastien MARQUE authored on 2017-04-11
110
};
111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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