adds AFCS
|
1 |
var APClass = { |
2 |
new : func { |
|
3 |
var m = { parents: [ APClass ] }; |
|
4 | ||
5 |
m.system = 'none'; |
|
6 |
var ap_systems = { # described AP systems to search, if it returns true system is set |
|
autopilot S-TEC 55X integrat...
|
7 |
STEC55X: func contains(stec55x, 'ITAF'), |
adds AFCS
|
8 |
}; |
9 |
foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) { |
|
10 |
call(ap_systems[s], [], nil, nil, var errors = []); |
|
11 |
if (!size(errors)) { |
|
12 |
msg('found autopilot system: ' ~ s); |
|
13 |
m.system = s; |
|
14 |
break; |
|
15 |
} |
|
16 |
} |
|
17 |
ap_systems = nil; |
|
18 | ||
19 |
m.engaged = 0; |
|
20 | ||
21 |
if (! contains(data.timers, 'updateAP')) { |
|
22 |
data.timers.updateAP = maketimer(1, m, m.systems[m.system].updateDisplay); |
|
23 |
data.timers.updateAP.start(); |
|
24 |
} |
|
25 | ||
26 |
if (! contains(data.timers, 'AP_blinking')) { |
|
27 |
data.timers.AP_blinking = maketimer(0, m, m._blinking); |
|
28 |
data.timers.AP_blinking.singleShot = 1; |
|
29 |
} |
|
30 | ||
31 |
if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func') |
|
32 |
m.systems[m.system].hook(); |
|
33 | ||
34 |
return m; |
|
35 |
}, |
|
36 |
softkey: func (side, row, a) { |
|
37 |
if (a == 0 or me._locked) |
|
38 |
return; |
|
39 |
var _system = me.systems[me.system]; |
|
40 |
var _side = _system[side]; |
|
41 |
_side[row](); |
|
42 |
}, |
|
43 |
_locked: 0, # no status modification while blinking, is it really useful ? |
|
44 |
_blinking: func { |
|
45 |
autopilot._locked += 1; |
|
46 |
var _display = flightdeck['PFD'].display; |
|
47 |
var i = math.mod(autopilot._locked, 2); |
|
48 |
var delays = [ 0.7, 0.3 ]; |
|
49 | ||
50 |
_display.screenElements['AP-text'].setVisible(i); |
|
51 |
|
|
52 |
if (autopilot._locked < 11) |
|
53 |
data.timers.AP_blinking.restart(delays[i]); |
|
54 |
else { |
|
55 |
autopilot._locked = 0; |
|
56 |
data.timers.AP_blinking.stop(); |
|
57 |
_display.screenElements['AP-text'] |
|
58 |
.setVisible(1) |
|
59 |
.setText(''); |
|
60 |
} |
|
61 |
}, |
|
62 |
systems : { |
|
63 |
# L: AP FD NAV ALT VS FLC |
|
64 |
# R: YD HDG APR VNV UP DN |
|
65 |
none: { |
|
66 |
updateDisplay: func, |
|
67 |
hook: func, |
|
68 |
L: [ func, func, func, func, func, func ], |
|
69 |
R: [ func, func, func, func, func, func ], |
|
70 |
}, |
|
autopilot S-TEC 55X integrat...
|
71 |
STEC55X: { |
72 |
hook : func, |
|
73 |
updateDisplay: func { |
|
74 |
if (autopilot._locked) |
|
75 |
return; |
|
76 |
var ap_annun = ''; |
|
77 |
if (flightdeck['PFD'].display.screenElements['AP-text'].getText() != '' |
|
78 |
and stec55x.pitch.getValue() == -1 and stec55x.roll.getValue() == -1) { |
|
79 |
autopilot._blinking(); |
|
80 |
return; |
|
81 |
} |
|
82 |
elsif (stec55x.roll.getValue() != -1 or stec55x.pitch.getValue() != -1) |
|
83 |
ap_annun = 'AP'; |
|
84 | ||
85 |
foreach (var mode; ['HDG', 'NAV', 'APR']) |
|
86 |
if (stec55x[mode ~ '_annun'].getValue()) |
|
87 |
ap_annun ~= ' ' ~ mode; |
|
88 | ||
89 |
if (stec55x.ALT_annun.getValue()) |
|
90 |
ap_annun ~= sprintf('ALT %5d ft', math.round(me.data.alt), 10); # even if pressure is hold, we show alt in feet |
|
91 | ||
92 |
if (stec55x.VS_annun.getValue()) |
|
93 |
ap_annun ~= sprintf('VS %s %4d fpm', |
|
94 |
utf8.chstr(stec55x.vs.getValue() > 0 ? 9650 : 9660), |
|
95 |
math.abs(math.round(stec55x.vs.getValue(), 10))); |
|
96 | ||
97 |
}, |
|
98 |
L: [ |
|
99 |
func { |
|
100 |
var ap_master_sw = '/it-stec55x/input/ap-master-sw'; |
|
101 |
setprop(ap_master_sw, !getprop(ap_master_sw)); |
|
102 |
}, |
|
103 |
func { |
|
104 |
var apfd_master_sw = '/it-stec55x/input/apfd-master-sw'; |
|
105 |
setprop(apfd_master_sw, !getprop(apfd_master_sw)); |
|
106 |
}, |
|
107 |
func { |
|
108 |
call(stec55x.button.NAV, [], nil, stec55x); |
|
109 |
}, |
|
110 |
func { |
|
111 |
call(stec55x.button.ALT, [], nil, stec55x); |
|
112 |
}, |
|
113 |
func { |
|
114 |
call(stec55x.button.VS, [], nil, stec55x); |
|
115 |
}, |
|
116 |
func, |
|
117 |
], |
|
118 |
R: [ |
|
119 |
func { |
|
120 |
var yaw_dumper_sw = '/it-stec55x/input/yaw-damper-sw'; |
|
121 |
setprop(yaw_dumper_sw, !getprop(yaw_dumper_sw)); |
|
122 |
}, |
|
123 |
func { |
|
124 |
call(stec55x.button.HDG, [], nil, stec55x); |
|
125 |
}, |
|
126 |
func { |
|
127 |
call(stec55x.button.APR, [], nil, stec55x); |
|
128 |
}, |
|
129 |
func, |
|
130 |
func { # UP (trim) |
|
131 |
fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: -1}); |
|
132 |
fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 0}); |
|
133 |
}, |
|
134 |
func { # DN (trim) |
|
135 |
fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 1}); |
|
136 |
fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 0}); |
|
137 |
}, |
|
138 |
], |
|
139 |
} |
|
adds AFCS
|
140 |
} |
141 |
}; |