zkv1000 / zkv1000.nas /
Newer Older
298 lines | 11.52kb
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
adds alerting system
Sébastien MARQUE authored on 2020-07-09
19
    'annunciations.nas',  # in flight tests
commit initial
Sébastien MARQUE authored on 2017-03-07
20
];
21
#    'routes.nas',  # manages flightplans and routes
22
#    'display.nas', # display messages and popups
23
#    'infos.nas',   # get informations from environment
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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