commit initial
|
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
|
5 |
'radios.nas', # all about radios COMM, NAV, XPDR |
commit initial
|
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
|
9 |
'maps/route.nas', |
separates maps code
|
10 |
'maps/navaids.nas', |
11 |
'maps/tiles.nas', |
|
add TCAS
|
12 |
'maps/tcas.nas', |
topo display is now availabl...
|
13 |
'maps/topo.nas', |
add track display
|
14 |
'maps/track.nas', |
adds Map on MFD
|
15 |
'map.nas', # moves the maps |
commit initial
|
16 |
'display.nas', |
add window management
|
17 |
'menu.nas', # manage windows |
commit initial
|
18 |
'core.nas', # the scheduler and switch on button |
adds AFCS
|
19 |
'afcs.nas', # Automatic Flight Control System |
adds alerting system
|
20 |
'annunciations.nas', # in flight tests |
commit initial
|
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 ...
|
27 |
var flightdeck = {}; |
28 | ||
adds AFCS
|
29 |
var autopilot = {}; |
30 | ||
adds alerting system
|
31 |
var annunciations = {}; |
32 | ||
settings now have effect
|
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...
|
50 |
temperature : { |
51 |
from_C : func (c) return c, |
|
52 |
from_F : func (f) return (f -32) / 1.8, |
|
53 |
}, |
|
adds volume settings
|
54 |
volume: { |
55 |
from_l: 1, |
|
56 |
from_gal: 3.78541178, |
|
57 |
from_m3: 1000, |
|
58 |
}, |
|
add pressure conversion inHg...
|
59 |
pressure: { |
60 |
from_inhg: 1, |
|
61 |
from_hpa: 0.02953, |
|
62 |
}, |
|
settings now have effect
|
63 |
}; |
64 | ||
just moves data structure to...
|
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...
|
72 |
trk : 0, |
just moves data structure to...
|
73 |
wow : 1, |
put lat/lon in global data s...
|
74 |
lat : 0, |
75 |
lon : 0, |
|
adds AOA display
|
76 |
aoa : 0, |
change way of time display
|
77 |
time : '23:59:59', |
adds flight plan catalog loa...
|
78 |
fpSize : 0, |
add TCAS
|
79 |
tcas: [], |
traffic alert and display
|
80 |
tcas_level: 0, |
makes Vspeeds free and adapt...
|
81 |
Vspeeds : {}, |
creates settings management
|
82 |
settings: { |
83 |
units: { |
|
84 |
pressure: 'inhg', |
|
85 |
altitude: 'ft', |
|
86 |
speed: 'knots', |
|
87 |
distance: 'nm', |
|
88 |
vertical: 'fpm', |
|
89 |
}, |
|
adds time display setting
|
90 |
time: { |
91 |
label: 'GMT', |
|
92 |
actual: ' GMT >', |
|
93 |
}, |
|
creates settings management
|
94 |
}, |
just moves data structure to...
|
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
|
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...
|
104 |
data.hdg = getprop('/orientation/heading-deg'); |
add periodicly updated track...
|
105 |
data.trk = data.wow ? data.hdg : getprop('/orientation/track-deg'); |
adds AOA display
|
106 |
data.aoa = getprop('/orientation/alpha-deg'); |
just moves data structure to...
|
107 |
} |
108 |
), |
|
109 |
'1Hz': maketimer ( |
|
110 |
1, |
|
111 |
func { |
|
112 |
data.wow = getprop('/gear/gear/wow'); |
|
put lat/lon in global data s...
|
113 |
data.lat = getprop('/position/latitude-deg'); |
114 |
data.lon = getprop('/position/longitude-deg'); |
|
just moves data structure to...
|
115 |
} |
116 |
), |
|
117 |
}, |
|
listeners stored in data str...
|
118 |
listeners : {}, |
just moves data structure to...
|
119 |
}; |
120 | ||
fix setlistener on tied prop...
|
121 |
var zkv = cdi = radios = alerts = infos = cursors = afcs = eis = misc = nil; |
commit initial
|
122 | |
123 |
var init_props = func { |
|
124 |
zkv = props.globals.getNode('/instrumentation/zkv1000',1); |
|
adds the avaibility to have ...
|
125 |
foreach (var d; zkv.getChildren()) |
126 |
if (d.getNode('status') != nil) |
|
127 |
flightdeck[d.getName()] = nil; |
|
commit initial
|
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...
|
131 |
zkv.getNode('display-brightness-norm',1).setDoubleValue(0.5); |
132 |
zkv.getNode('lightmap',1).setIntValue(0); |
|
add possibility to resize th...
|
133 |
if (zkv.getNode('size-factor').getValue() == nil) |
134 |
zkv.getNode('size-factor',1).setDoubleValue(1.0); |
|
adds flight plan catalog loa...
|
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
|
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
|
152 |
radios.getNode('brg1-source',1).setValue('OFF'); |
153 |
radios.getNode('brg2-source',1).setValue('OFF'); |
|
commit initial
|
154 | |
adds CDI
|
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
|
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...
|
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 ...
|
175 |
var aoa = alerts.getValue('stall-aoa'); |
adds AOA display
|
176 |
data['stall-aoa'] = (aoa == nil or aoa == 0) ? 9999 : aoa; |
remove hardcoded properties ...
|
177 |
aoa = alerts.getValue('approach-aoa'); |
nicer AOA display
|
178 |
if (aoa != nil) |
179 |
data['approach-aoa'] = aoa; |
|
commit initial
|
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...
|
184 |
afcs.getNode('heading-bug-deg',1).setDoubleValue(int(getprop('/orientation/heading-deg'))); |
commit initial
|
185 |
afcs.getNode('target-pitch-deg',1).setDoubleValue(0.0); |
adds OAT, TAS, GSPD, WindDat...
|
186 |
afcs.getNode('selected-alt-ft',1).setIntValue(2000); |
commit initial
|
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...
|
204 |
data.flightplans = getprop('/sim/fg-home') ~ '/Export'; |
205 | ||
fix setlistener on tied prop...
|
206 |
misc = zkv.getNode('misc',1); |
207 |
misc.getNode('alt-setting-inhg',1).setDoubleValue(getprop('/instrumentation/altimeter/setting-inhg')); |
|
208 | ||
animation texts EIS + power ...
|
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...
|
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
|
219 |
format: 'png', |
220 |
template: 'https://{server}/{type}/{z}/{x}/{y}.{format}{apikey}', |
|
moves some map infos in data...
|
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
|
226 | |
commit initial
|
227 |
props.globals.getNode('/instrumentation/transponder/id-code',1).setIntValue(1200); |
228 |
props.globals.getNode('/instrumentation/transponder/serviceable',1).setBoolValue(1); |
|
remove hardcoded properties ...
|
229 |
props.globals.getNode('/autopilot/settings/heading-bug-deg', 1).alias(afcs.getNode('heading-bug-deg').getPath()); |
afcs improvements
|
230 |
props.globals.getNode('/autopilot/settings/target-alt-ft',1).alias(afcs.getNode('selected-alt-ft').getPath()); |
commit initial
|
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 ...
|
240 | |
allows zkv1000 to be install...
|
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
|
247 |
} |
248 | ||
249 |
var load_nasal = func { |
|
path and relpath to zkv1000 ...
|
250 |
var nasal_dir = data.zkv1000_dir ~ 'Nasal/'; |
commit initial
|
251 |
for (var i = 0; i < size(files_to_load); i += 1) |
path and relpath to zkv1000 ...
|
252 |
io.load_nasal(nasal_dir ~ files_to_load[i], 'zkv1000'); |
commit initial
|
253 |
files_to_load = nil; |
254 |
} |
|
255 | ||
256 |
var load_multikey = func { |
|
257 |
fgcommand('loadxml', props.Node.new({ |
|
path and relpath to zkv1000 ...
|
258 |
'filename': data.zkv1000_dir ~ 'Systems/multikey.xml', |
commit initial
|
259 |
'targetnode': '/input/keyboard/' |
260 |
})); |
|
261 |
multikey.init(); |
|
262 |
} |
|
263 | ||
adds settings storage and re...
|
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...
|
288 |
foreach (var V; keys(data.Vspeeds)) |
289 |
data.Vspeeds[V] *= units.speed.from_kt; |
|
adds settings storage and re...
|
290 |
} |
291 | ||
commit initial
|
292 |
var zkv1000_init = func { |
init listener needed only on...
|
293 |
removelistener(init); |
commit initial
|
294 |
init_props(); |
adds settings storage and re...
|
295 |
load_settings(); |
path and relpath to zkv1000 ...
|
296 |
load_multikey(); |
adds AOA display
|
297 |
load_nasal(); |
improve auto-power
|
298 |
msg('loaded'); |
299 |
if (zkv.getValue('auto-power')) { |
|
improve power on and off usi...
|
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
|
311 |
} |
commit initial
|
312 |
} |
313 | ||
init listener needed only on...
|
314 |
var init = setlistener('/sim/signals/fdm-initialized', zkv1000_init, 0, 0); |