Showing 1 changed files with 45 additions and 0 deletions
+45
Nasal/core.nas
... ...
@@ -56,6 +56,17 @@ var setListeners = func {
56 56
     prop = '/autopilot/route-manager/current-wp';
57 57
     data.listeners[prop] = setlistener(prop,
58 58
             func (n) {
59
+                var wp_idx = n.getValue();
60
+                if (wp_idx > 0) {
61
+                    var wp_path = '/autopilot/route-manager/route/wp[' ~ wp_idx ~ ']/';
62
+                    var wp = findNavaidsByID(getprop(wp_path ~ 'latitude-deg'),
63
+                                             getprop(wp_path ~ 'longitude-deg'),
64
+                                             getprop(wp_path ~ 'id'));
65
+                    call(func {return wp[0].frequency}, [], nil, nil, var errors = []);
66
+#                    if (!size(errors)) debuginfo ~ sprintf('; freq: %d', wp[0].frequency);
67
+                    call(func {return wp[0].type}, [], nil, nil, var errors = []);
68
+#                    if (!size(errors)) debuginfo ~ sprintf('; type: %s', wp[0].type);
69
+                }
59 70
                 var delay = maketimer(2, func {
60 71
                     foreach (var c; keys(flightdeck))
61 72
                         flightdeck[c].map.layers.route.onCurrentWaypointChange(
... ...
@@ -70,6 +81,13 @@ var setListeners = func {
70 81
             func foreach (var c; keys(flightdeck))
71 82
                     flightdeck[c].map.layers.route.onCurrentWaypointChange(props.globals.getNode('/autopilot/route-manager/current-wp')),
72 83
                 0, 1);
84
+
85
+    prop = zkv.getPath() ~ '/serviceable';
86
+    data.listeners[prop] = setlistener(prop, zkv1000.powerOff, 0, 0);
87
+
88
+    # the timer isn't necessary anymore
89
+    data.timers.listeners.stop();
90
+    delete(data.timers, 'listeners');
73 91
 }
74 92
 
75 93
 var deviceClass = {
... ...
@@ -167,9 +185,36 @@ var deviceClass = {
167 185
         msg(m.name ~ ' switched on!');
168 186
         return m;
169 187
     },
188
+    off: func {
189
+        foreach (var timer; keys(me.timers)) {
190
+            me.timers[timer].stop();
191
+            delete(me.timers, timer);
192
+        }
193
+        foreach (var member; keys(me)) {
194
+            if (contains(me[member], 'off')) me[class].off();
195
+            delete(me, member);
196
+        }
197
+    },
170 198
 };
171 199
 
200
+var powerOff = func {
201
+    foreach (var timer; keys(data.timers)) {
202
+        data.timers[timer].stop();
203
+        delete(data.timers, timer);
204
+    }
205
+    foreach (var name; keys(flightdeck)) {
206
+        flightdeck[name].off();
207
+        delete(flightdeck, name);
208
+        setprop(zkv.getPath() ~ '/' ~ name ~ '/status', 0);
209
+    }
210
+}
211
+
172 212
 var powerOn = func {
213
+    if (!zkv.getValue('serviceable')) {
214
+        msg('not yet serviceable (check power)!');
215
+        return;
216
+    }
217
+
173 218
     foreach (var freq; keys(data.timers))
174 219
         data.timers[freq].start();
175 220