commit initial
|
1 |
### |
2 |
# Not Yet Implemented: just draw a warnig box during 3 seconds |
|
3 |
var nyi = func (x) { gui.popupTip(x ~ ': not yet implemented', 3) } |
|
4 | ||
5 |
### |
|
6 |
# print message in terminal |
|
7 |
var msg = func (str) { print('ZKV1000 >> ', str) } |
|
8 | ||
9 |
### |
|
10 |
# print message in popup |
|
11 |
var msg_popup = func (str...) { gui.popupTip("ZKV1000\n" ~ str, 3) } |
|
12 | ||
13 |
### |
|
14 |
# just do nothing |
|
15 |
var void = func { } |
|
16 | ||
17 |
### |
|
18 |
# returns decimal part arg |
|
19 |
var frac = func (x) { return (x - int(x)) } |
|
20 | ||
21 |
### |
|
22 |
# rounds regarding proximity |
|
23 |
# e.g.: |
|
24 |
# round(1540, 300) gives 1500 |
|
25 |
# round(2370, 400) gives 2400 |
|
26 |
var round = func (x, m = 1) { |
|
27 |
var v = x / m; |
|
28 |
if (frac(v) >= 0.5) v += 1; |
|
29 |
return (int(v) * m); |
|
30 |
} |
|
31 | ||
32 |
### |
|
33 |
# rounds regarless proximity |
|
34 |
# e.g.: |
|
35 |
# round_bis(1540, 300) gives 1500 |
|
36 |
# round_bis(2370, 400) gives 2000 |
|
37 |
var round_bis = func (x, m) { |
|
38 |
var r = round(x, m); |
|
39 |
if (r > x) r -= m; |
|
40 |
return r; |
|
41 |
} |
|
42 | ||
43 |
var alt = vs = vs_abs = ias = tas = pitch = roll = agl = stall = rpm = 0; |
|
44 |
var getData = func { |
|
45 |
alt = math.abs(getprop('/instrumentation/altimeter/indicated-altitude-ft')); |
|
46 |
vs = getprop('/velocities/vertical-speed-fps') * 60; |
|
47 |
ias = getprop('/instrumentation/airspeed-indicator/indicated-speed-kt'); |
|
48 |
pitch = getprop('/orientation/pitch-deg'); |
|
49 |
roll = getprop('/orientation/pitch-deg'); |
|
50 |
agl = getprop('/position/altitude-agl-ft'); |
|
51 |
stall = getprop('/sim/alarms/stall-warning'); |
|
52 |
gear = getprop('/controls/gears/gear'); |
|
53 |
} |
|
54 | ||
55 |
### |
|
56 |
# returns DMS coordinates |
|
57 |
# d is decimal longitude or latitude |
|
58 |
# c should be one of E, W, S or N |
|
59 |
# inspired from FG source: $FGSRC/src/Main/fg_props.cxx |
|
60 |
var DMS = func (d, c) { |
|
61 |
var deg = min = sec = 0.0; |
|
62 |
d = abs(d); |
|
63 |
deg = d + 0.05 / 3600; |
|
64 |
min = (deg - int(deg)) * 60; |
|
65 |
sec = (min - int(min)) * 60 - 0.049; |
|
66 |
return sprintf('%d %02d %04.1f %s', int(deg), int(min), abs(sec), c); |
|
67 |
} |
|
68 | ||
69 |
var timeUTC = func { |
|
70 |
setprop('/instrumentation/zkv1000/infos/time', sprintf('UTC %02i%02i%02i', |
|
71 |
getprop('/sim/time/utc/hour'), |
|
72 |
getprop('/sim/time/utc/minute'), |
|
73 |
getprop('/sim/time/utc/second'))); |
|
74 |
} |
|
75 | ||
76 |
var timeLCL = func { |
|
77 |
var utc_hour = getprop('/sim/time/utc/hour') + (getprop('/sim/time/local-offset') / 3600); |
|
78 |
if (utc_hour > 23) utc_hour -= 24; |
|
79 |
if (utc_hour < 0) utc_hour += 24; |
|
80 |
setprop('/instrumentation/zkv1000/infos/time', sprintf('LCL %02i%02i%02i', |
|
81 |
utc_hour, |
|
82 |
getprop('/sim/time/utc/minute'), |
|
83 |
getprop('/sim/time/utc/second'))); |
|
84 |
} |
|
85 | ||
86 |
var timeRL = func { |
|
87 |
setprop('/instrumentation/zkv1000/infos/time', sprintf('RL %02i%02i%02i', |
|
88 |
getprop('/sim/time/real/hour'), |
|
89 |
getprop('/sim/time/real/minute'), |
|
90 |
getprop('/sim/time/real/second'))); |
|
91 |
} |
|
92 | ||
generic function to format t...
|
93 |
# returns time + d (is seconds) formated HH:MM:SS |
94 |
var HMS = func (hh, mm, ss, d = 0) { |
|
95 |
ss += d; |
|
96 | ||
97 |
if (ss > 59) { |
|
98 |
ss -= 60; |
|
99 |
mm += 1; |
|
100 |
if (mm > 59) { |
|
101 |
mm = 0; |
|
102 |
hh += 1; |
|
103 |
} |
|
104 |
} |
|
105 |
elsif (ss < 0) { |
|
106 |
if (mm > 0) { |
|
107 |
ss += 60; |
|
108 |
mm -= 1; |
|
109 |
} |
|
110 |
elsif (mm == 0 and hh > 0) { |
|
111 |
ss += 60; |
|
112 |
mm = 59; |
|
113 |
hh -= 1; |
|
114 |
} |
|
115 |
elsif (mm == 0 and hh == 0) |
|
116 |
ss = 0; |
|
117 |
} |
|
118 |
return sprintf('%02i:%02i:%02i', hh, mm, ss); |
|
119 |
} |
|
120 | ||
commit initial
|
121 |
### |
122 |
# Loads a fligtplan (route) from a XML file |
|
123 |
# replaces existing route by the new one |
|
124 |
var loadFPLfromFile = func (file) { |
|
125 |
afcs.getNode('route').removeChildren(); |
|
126 |
fgcommand('loadxml', props.Node.new({ |
|
127 |
'filename': file, |
|
128 |
'targetnode': afcs.getNode('route').getPath()}) |
|
129 |
); |
|
130 |
FPLtoRouteManager(); |
|
131 |
msg('route loaded from ' ~ file); |
|
132 |
} |
|
133 | ||
134 |
var wipeRoute = func { |
|
135 |
var command = props.globals.getNode('/instrumentation/gps/command'); |
|
136 |
var v = getprop('/autopilot/route-manager/route/num'); |
|
137 |
setprop('/autopilot/route-manager/active', 0); |
|
138 |
setprop('/instrumentation/gps/scratch/index', 0); |
|
139 |
while (v) { |
|
140 |
v -= 1; |
|
141 |
command.setValue('route-delete'); |
|
142 |
} |
|
143 |
} |
|
144 | ||
145 |
var FPLtoRouteManager = func { |
|
146 |
wipeRoute(); |
|
147 |
lockSearches(); |
|
148 |
var scratch = props.globals.getNode('/instrumentation/gps/scratch'); |
|
149 |
var command = scratch.getNode('../command'); |
|
150 |
foreach (var waypoint; afcs.getNode('route').getChildren()) { |
|
151 |
scratch.getNode('index').setIntValue(-1); |
|
152 |
searchNearestNavaid(waypoint.getNode('type').getValue(), 1, waypoint.getPath()); |
|
153 |
command.setValue('route-insert-after'); |
|
154 |
} |
|
155 |
unlockSearches(); |
|
156 |
} |
|
157 | ||
158 |
#### |
|
159 |
# Search nav facilities |
|
160 |
var searchNearestNavaid = func (type, quantity = 1, path = nil) { |
|
161 |
getprop('/instrumentation/zkv1000/searches-locked') or return; |
|
162 |
scratch = props.globals.getNode('/instrumentation/gps/scratch/'); |
|
163 |
scratch.getNode('max-results', 1).setIntValue(quantity); |
|
164 |
var lat = lon = -9999; |
|
165 |
if (path != nil) { |
|
166 |
if (props.globals.getNode(path) != nil) { |
|
167 |
lon = getprop(path ~ '/longitude-deg'); |
|
168 |
lat = getprop(path ~ '/latitude-deg'); |
|
169 |
} |
|
170 |
} |
|
171 |
scratch.getNode('longitude-deg', 1).setDoubleValue(lon); |
|
172 |
scratch.getNode('latitude-deg', 1).setDoubleValue(lat); |
|
173 |
scratch.getNode('type').setValue(type); |
|
174 |
setprop('/instrumentation/gps/command', 'nearest'); |
|
175 |
} |
|
176 | ||
177 |
var lockSearches = func (v = 1) { |
|
178 |
props.globals.getNode('/instrumentation/zkv1000/searches-locked', 1).setBoolValue(v); |
|
179 |
} |
|
180 | ||
181 |
var unlockSearches = func { |
|
182 |
lockSearches(0); |
|
183 |
} |
|
184 | ||
185 |
#var dialog = func { |
|
186 |
# var d = gui.Widget.new(); |
|
187 |
# d.set({'name': 'ZKV1000 text entry interface', |
|
188 |
# 'layout': 'vbox', |
|
189 |
# 'default-padding' : 0}); |
|
190 |
# d.addChild('text'). |
|
191 |
#} |
|
192 | ||
193 |
var computeAltitudeDiff = void; |
|
194 |
var computeAirspeedDiff = void; |
|
195 |
var FLCcomputation = void; |
|
196 |
var checkRollAcquisition = void; |
|
197 |
var checkPitchAcquisition = void; |
|
198 |
var checkTrafficProximity = void; |
|
199 |
var manageLandingGears = void; |
|
200 |
var checkAbnormalAttitude = void; |
|
201 |
var applyFilter = void; |