zkv1000 / zkv1000.nas /
Newer Older
257 lines | 9.921kb
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
    },
47
};
48

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

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

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

            
121
    radios = zkv.getNode('radios', 1);
122
    radios.getNode('nav1-selected',1).setIntValue(0);
123
    radios.getNode('nav1-standby',1).setIntValue(0);
124
    radios.getNode('nav2-selected',1).setIntValue(0);
125
    radios.getNode('nav2-standby',1).setIntValue(0);
126
    radios.getNode('nav-tune',1).setIntValue(0);
127
    radios.getNode('nav-freq-mhz',1).alias('/instrumentation/nav/frequencies/standby-mhz');
128
    radios.getNode('comm1-selected',1).setIntValue(1);
129
    radios.getNode('comm2-selected',1).setIntValue(0);
130
    radios.getNode('comm-tune',1).setIntValue(0);
131
    radios.getNode('comm-freq-mhz',1).alias('/instrumentation/comm/frequencies/standby-mhz');
132
    radios.getNode('xpdr-mode',1).setValue('GND');
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
133
    radios.getNode('brg1-source',1).setValue('OFF');
134
    radios.getNode('brg2-source',1).setValue('OFF');
commit initial
Sébastien MARQUE authored on 2017-03-07
135

            
adds CDI
Sébastien MARQUE authored on 2017-03-18
136
    cdi = zkv.getNode('cdi', 1);
137
    cdi.getNode('source', 1).setValue('OFF');
138
    cdi.getNode('no-flag', 1).setBoolValue(0);
139
    cdi.getNode('FROM-flag', 1).alias('no-flag');
140
    cdi.getNode('TO-flag', 1).alias('no-flag');
141
    cdi.getNode('course', 1);
142
    cdi.getNode('course-deflection', 1);
143
    cdi.getNode('radial', 1);
144
    cdi.getNode('in-range', 1);
145

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

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

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

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

            
animation texts EIS + power ...
Sébastien MARQUE authored on 2017-03-19
190
    eis = zkv.getNode('eis',1);
191
    eis.getNode('fuel-qty-at-start', 1).setValue(
192
        getprop('/consumables/fuel/tank/level-gal_us')
193
      + getprop('/consumables/fuel/tank/level-gal_us'));
194

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

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

            
allows zkv1000 to be install...
Sébastien MARQUE authored on 2017-05-11
222
    data.zkv1000_reldir = io.dirname(getprop('/nasal/zkv1000/file'));
223
    data.zkv1000_dir = string.normpath(
224
            io.dirname(getprop('/sim/aircraft-dir'))
225
            ~ '/'
226
            ~ string.replace(data.zkv1000_reldir, split('/', data.zkv1000_reldir)[0], '')
227
        ) ~ '/';
commit initial
Sébastien MARQUE authored on 2017-03-07
228
}
229

            
230
var load_nasal = func {
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
231
    var nasal_dir = data.zkv1000_dir ~ 'Nasal/';
commit initial
Sébastien MARQUE authored on 2017-03-07
232
    for (var i = 0; i < size(files_to_load); i += 1)
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
233
        io.load_nasal(nasal_dir ~ files_to_load[i], 'zkv1000');
commit initial
Sébastien MARQUE authored on 2017-03-07
234
    files_to_load = nil;
235
}
236

            
237
var load_multikey = func {
238
    fgcommand('loadxml', props.Node.new({
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
239
        'filename': data.zkv1000_dir ~ 'Systems/multikey.xml',
commit initial
Sébastien MARQUE authored on 2017-03-07
240
        'targetnode': '/input/keyboard/'
241
    }));
242
    multikey.init();
243
}
244

            
245
var zkv1000_init = func {
init listener needed only on...
Sébastien MARQUE authored on 2017-03-13
246
    removelistener(init);
commit initial
Sébastien MARQUE authored on 2017-03-07
247
    init_props();
path and relpath to zkv1000 ...
Sébastien MARQUE authored on 2017-04-17
248
    load_multikey();
adds AOA display
Sébastien MARQUE authored on 2017-04-15
249
    load_nasal();
improve auto-power
Sébastien MARQUE authored on 2020-05-16
250
    msg('loaded');
251
    if (zkv.getValue('auto-power')) {
252
        var prop = zkv.getNode('serviceable',1).getPath();
253
        data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0);
254
    }
commit initial
Sébastien MARQUE authored on 2017-03-07
255
}
256

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