add TCAS
|
1 |
# vim: set foldmethod=marker foldmarker={{{,}}} : |
2 | ||
3 |
var TcasItemClass = { |
|
4 |
# get data from AI and multiplayers {{{ |
|
5 |
new : func(canvasGroup, index) { |
|
6 |
var m = {parents : [TcasItemClass]}; |
|
7 |
m._group = canvasGroup.createChild("group", "TcasItem_" ~ index); |
|
8 | ||
relocate SVG files in Models...
|
9 |
canvas.parsesvg(m._group, data.zkv1000_reldir ~ "Models/tcas.svg"); |
add TCAS
|
10 |
m._can = { |
11 |
Alt : [ |
|
12 |
m._group.getElementById("Alt_above").setVisible(0), |
|
13 |
m._group.getElementById("Alt_below").setVisible(0) |
|
14 |
], |
|
15 |
Arrow : [ |
|
16 |
m._group.getElementById("Arrow_climb").setVisible(0), |
|
17 |
m._group.getElementById("Arrow_descent").setVisible(0) |
|
18 |
] |
|
19 |
}; |
|
20 |
m._can.ThreadLevel = []; |
|
21 | ||
22 |
for (var i=0; i<4; i+=1) |
|
23 |
append(m._can.ThreadLevel, |
|
24 |
m._group.getElementById("Thread_Level_" ~ i).setVisible(0)); |
|
25 | ||
26 |
m._colors = [ '#00ffff', '#00ffff', '#ff7f2a', '#ff0000' ]; |
|
27 | ||
28 |
return m; |
|
29 |
}, |
|
30 | ||
31 |
setData : func(lat, lon, alt, vs, level) { |
|
32 |
me._group.setVisible(1); |
|
33 |
me._group.setGeoPosition(lat, lon); |
|
34 |
|
|
35 |
if (alt == 0) { |
|
36 |
me._can.Alt[0].setVisible(0); |
|
37 |
me._can.Alt[1].setVisible(0); |
|
38 |
} |
|
39 |
else { |
|
40 |
me._can.Alt[alt < 0] |
|
41 |
.setText(sprintf("%+i", alt)) |
|
42 |
.set('fill', me._colors[level]) |
|
43 |
.setVisible(1); |
|
44 | ||
45 |
me._can.Alt[alt > 0].setVisible(0); |
|
46 |
} |
|
47 |
|
|
48 |
if (vs >= -3 and vs <= 3) { |
|
49 |
me._can.Arrow[0].setVisible(0); |
|
50 |
me._can.Arrow[1].setVisible(0); |
|
51 |
} |
|
52 |
else { |
|
53 |
me._can.Arrow[vs < -3] |
|
54 |
.set('fill', me._colors[level]) |
|
55 |
.set('stroke', me._colors[level]) |
|
56 |
.setVisible(1); |
|
57 | ||
58 |
me._can.Arrow[vs > 3].setVisible(0); |
|
59 |
} |
|
60 |
|
|
61 |
me._can.ThreadLevel[0].setVisible(level == 0); |
|
62 |
me._can.ThreadLevel[1].setVisible(level == 1); |
|
63 |
me._can.ThreadLevel[2].setVisible(level == 2); |
|
64 |
me._can.ThreadLevel[3].setVisible(level == 3); |
|
65 |
me._group.set("z-index", level + 1); |
|
66 |
}, |
|
67 |
}; |
|
68 |
# }}} |
|
69 | ||
70 |
var MapTcas = { |
|
71 |
# init TCAS layer and update {{{ |
|
72 |
new : func(device, group) { |
|
73 |
var m = {parents:[MapTcas]}; |
|
fix when TCAS isn't availabl...
|
74 |
m.device = device; |
add TCAS
|
75 |
if (getprop('/instrumentation/tcas/serviceable') == nil) { |
76 |
m.update = func; |
|
77 |
m.setVisible = func; |
|
78 |
} |
|
79 |
else { |
|
80 |
m.visibility = 0; |
|
81 |
m.group = group.createChild('map', 'tcas') |
|
82 |
.setTranslation( |
|
83 |
m.device.role == 'MFD' ? (m.device.data.mapview[0] + m.device.data.mapclip.left)/2 : 120, |
|
84 |
m.device.role == 'MFD' ? 400 : 600) |
|
85 |
.setVisible(m.visibility); |
|
86 |
m._item = []; |
|
87 |
m._itemIndex = 0; |
|
88 |
m._itemCount = 0; |
|
89 |
# /instrumentation/tcas/inputs/mode |
|
90 |
m.MODE = ["Normal","Above","Unlimited","Below"]; |
|
91 |
} |
|
improve the selection of dis...
|
92 |
if (m.device.role == 'PFD') |
93 |
m.device.softkeys.colored.INSETTRAFFIC = 1; |
|
94 |
if (m.device.role == 'MFD') |
|
95 |
m.device.softkeys.colored.MAPTRAFFIC = 1; |
|
add TCAS
|
96 |
return m; |
97 |
}, |
|
98 | ||
99 |
update : func() { |
|
100 |
if (me.device.data.tcas == 0) |
|
101 |
return; |
|
102 |
me.group._node.getNode('ref-lat', 1).setDoubleValue(data.lat); |
|
103 |
me.group._node.getNode('ref-lon', 1).setDoubleValue(data.lon); |
|
104 |
me.group._node |
|
105 |
.getNode('range', 1).setDoubleValue(me.device.data['range-factor']); |
|
106 |
me._itemIndex = 0; |
|
107 |
foreach (var ac; data.tcas) { |
|
108 |
if (me._itemIndex >= me._itemCount) { |
|
109 |
append(me._item, TcasItemClass.new(me.group, me._itemIndex)); |
|
110 |
me._itemCount += 1; |
|
111 |
} |
|
112 |
me._item[me._itemIndex].setData(ac.lat, ac.lon, ac.alt, ac.vs, ac.level); |
|
113 |
me._itemIndex += 1; |
|
114 |
} |
|
115 |
|
|
116 |
for (; me._itemIndex < me._itemCount; me._itemIndex += 1) { |
|
117 |
me._item[me._itemIndex]._group.setVisible(0); |
|
118 |
} |
|
119 |
}, |
|
120 | ||
121 |
setVisible : func (v) { |
|
122 |
me.group.setVisible(v); |
|
123 |
}, |
|
124 |
}; |
|
125 |
# }}} |