improve power on and off using listener or timer depend...
...ing of aliased property or not
... | ... |
@@ -105,26 +105,6 @@ var setListeners = func { |
105 | 105 |
flightdeck[c].map.layers.route.onCurrentWaypointChange(props.globals.getNode('/autopilot/route-manager/current-wp')), |
106 | 106 |
0, 1); |
107 | 107 |
|
108 |
- if (zkv.getChild('serviceable') != nil) { |
|
109 |
- prop = zkv.getPath() ~ '/serviceable'; |
|
110 |
- data.listeners[prop] = setlistener(prop, |
|
111 |
- func (n) { |
|
112 |
- var type = n.getType(); |
|
113 |
- if (type == 'BOOL') { |
|
114 |
- if (n.getBoolValue()) |
|
115 |
- zkv1000.powerOn(); |
|
116 |
- else |
|
117 |
- zkv1000.powerOff(); |
|
118 |
- } |
|
119 |
- elsif (type == 'INT' or type == 'LONG' or type == 'FLOAT' or type == 'DOUBLE') { |
|
120 |
- if (n.getValue() > 12) |
|
121 |
- zkv1000.powerOn(); |
|
122 |
- else |
|
123 |
- zkv1000.powerOff(); |
|
124 |
- } |
|
125 |
- }, 0, 0); |
|
126 |
- } |
|
127 |
- |
|
128 | 108 |
# the timer isn't necessary anymore |
129 | 109 |
data.timers.listeners.stop(); |
130 | 110 |
delete(data.timers, 'listeners'); |
... | ... |
@@ -263,8 +243,11 @@ var deviceClass = { |
263 | 243 |
|
264 | 244 |
var powerOff = func { |
265 | 245 |
foreach (var listener; keys(data.listeners)) { |
266 |
- if (listener == '/instrumentation/zkv1000/serviceable') |
|
246 |
+ if (listener == '/instrumentation/zkv1000/serviceable') { |
|
247 |
+ var prop = zkv.getNode('serviceable',1).getPath(); |
|
248 |
+ data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0); |
|
267 | 249 |
continue; |
250 |
+ } |
|
268 | 251 |
removelistener(data.listeners[listener]); |
269 | 252 |
delete(data.listeners, listener); |
270 | 253 |
} |
... | ... |
@@ -273,6 +256,14 @@ var powerOff = func { |
273 | 256 |
data.timers[timer].stop(); |
274 | 257 |
if (timer == '20Hz' or timer == '1Hz') |
275 | 258 |
continue; |
259 |
+ if (timer == 'serviceable') { |
|
260 |
+ data.timers[timer] = maketimer(1, func { |
|
261 |
+ if (zkv.getNode('serviceable').getValue() != 0) |
|
262 |
+ zkv1000.powerOn(); |
|
263 |
+ }); |
|
264 |
+ data.timers.serviceable.restart(); |
|
265 |
+ continue; |
|
266 |
+ } |
|
276 | 267 |
delete(data.timers, timer); |
277 | 268 |
} |
278 | 269 |
|
... | ... |
@@ -292,8 +283,15 @@ var powerOn = func { |
292 | 283 |
} |
293 | 284 |
|
294 | 285 |
if (contains(data.listeners, '/instrumentation/zkv1000/serviceable')) { |
295 |
- removelistener(data.listeners['/instrumentation/zkv1000/serviceable']); |
|
296 |
- delete(data.listeners, '/instrumentation/zkv1000/serviceable'); |
|
286 |
+ var prop = zkv.getNode('serviceable',1).getPath(); |
|
287 |
+ data.listeners[prop] = setlistener(prop, zkv1000.powerOff, 0, 0); |
|
288 |
+ } |
|
289 |
+ if (contains(data.timers, 'serviceable')) { |
|
290 |
+ data.timers.serviceable = maketimer(1, func { |
|
291 |
+ if (zkv.getNode('serviceable').getValue() == 0) |
|
292 |
+ zkv1000.powerOff(); |
|
293 |
+ }); |
|
294 |
+ data.timers.serviceable.start(); |
|
297 | 295 |
} |
298 | 296 |
|
299 | 297 |
foreach (var freq; keys(data.timers)) |
... | ... |
@@ -297,8 +297,17 @@ var zkv1000_init = func { |
297 | 297 |
load_nasal(); |
298 | 298 |
msg('loaded'); |
299 | 299 |
if (zkv.getValue('auto-power')) { |
300 |
- var prop = zkv.getNode('serviceable',1).getPath(); |
|
301 |
- data.listeners[prop] = setlistener(prop, zkv1000.powerOn, 0, 0); |
|
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 |
+ } |
|
302 | 311 |
} |
303 | 312 |
} |
304 | 313 |
|