adds alerting system
|
1 |
var annunciationsClass = { |
2 |
new: func { |
|
3 |
var m = { parents : [ annunciationsClass ] }; |
|
4 |
m.registered = {}; # triggers identified by message |
|
5 |
m.active = []; # currently active warnings and alerts, sorted by emergency level |
|
6 |
m.devices = []; # PFD displays |
|
7 | ||
8 |
foreach (var d; keys(flightdeck)) |
|
9 |
if (flightdeck[d].role == 'PFD') |
|
10 |
append(m.devices, d); |
|
11 | ||
12 |
foreach (var warnings; alerts.getChildren('warnings')) |
|
13 |
foreach (var warning; warnings.getChildren('warning')) |
|
14 |
m.register(warning); |
|
15 | ||
16 |
data.timers.annunciations = maketimer(1.0, func call(m.activate, [], m)); |
|
17 |
data.timers.annunciations.start(); |
|
18 | ||
19 |
return m; |
|
20 |
}, |
|
21 | ||
22 |
register: func (node) { |
|
23 |
me.registered[node.getValue('message')] = { |
|
24 |
trigger: compile(node.getValue('script')), |
|
25 |
node: node, |
|
26 |
}; |
|
27 |
}, |
|
28 | ||
29 |
del: func (message) { |
|
30 |
if (contains(me.registered, message)) |
|
31 |
delete(me.registered, message); |
|
32 |
if (contains(me.active, message)) |
|
33 |
delete(me.active, message); |
|
34 |
}, |
|
35 | ||
36 |
activate: func { |
|
37 |
size(me.registered) or return; |
|
38 | ||
39 |
var score = {}; |
|
40 | ||
41 |
foreach (var a; keys(me.registered)) |
|
42 |
if (me.registered[a].trigger()) |
|
43 |
score[me.registered[a].node.getValue('message')] = me.registered[a].node.getValue('level'); |
|
44 | ||
45 |
if (size(score) > 1) { |
|
46 |
var sorted_scores = sort(keys(score), func (a, b) { |
|
47 |
if (score[a] <= score[b]) |
|
48 |
return 1; # greatest first |
|
49 |
else |
|
50 |
return -1; |
|
51 |
}); |
|
52 |
} |
|
53 |
else |
|
54 |
var sorted_scores = keys(score); |
|
55 | ||
56 |
me.active = sorted_scores; |
|
57 | ||
58 |
var levels_bg = [ 'lightgrey', 'white', 'red' ]; |
|
59 |
var levels_fg = [ 'black' , 'black', 'yellow' ]; |
|
60 | ||
61 |
if (size(me.active)) { |
|
62 |
var level = score[sorted_scores[0]]; |
|
63 |
if (level > 2) level = 2; |
|
64 | ||
65 |
foreach (var d; me.devices) { |
|
66 |
flightdeck[d].display.screenElements['SoftKey11-bg'] |
|
67 |
.setColorFill(flightdeck[d].display.colors[levels_bg[level]]); |
|
68 |
flightdeck[d].display.screenElements['SoftKey11-text'] |
|
69 |
.setColor(flightdeck[d].display.colors[levels_fg[level]]); |
|
70 |
flightdeck[d].display.updateSoftKeys(); |
|
71 |
} |
|
72 |
} |
|
73 |
else { |
|
74 |
foreach (var d; me.devices) { |
|
75 |
flightdeck[d].display.screenElements['SoftKey11-bg'] |
|
76 |
.setColorFill(flightdeck[d].display.colors.black); |
|
77 |
flightdeck[d].display.screenElements['SoftKey11-text'] |
|
78 |
.setColor(flightdeck[d].display.colors.lightgrey); |
|
79 |
flightdeck[d].display.updateSoftKeys(); |
|
80 |
} |
|
81 |
} |
|
82 |
}, |
|
83 |
}; |