zkv1000 / Nasal / softkeys.nas /
Newer Older
291 lines | 12.741kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var softkeysClass = {
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
2
    new : func (device, node, role) {
commit initial
Sébastien MARQUE authored on 2017-03-07
3
        var m = { parents: [ softkeysClass ] };
4
        m.node = node;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
5
        m.device = device;
commit initial
Sébastien MARQUE authored on 2017-03-07
6
        m.role = role;
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
7
        m.path = [];
commit initial
Sébastien MARQUE authored on 2017-03-07
8
        return m;
9
    },
10

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
11
    clean : func {
12
        # deletes unsed bindings
fix commit récédent un peu r...
Sébastien MARQUE authored on 2017-03-14
13
        foreach (var b; keys(me.bindings))
14
            if (b != me.role)
15
                delete(me.bindings, b);
commit initial
Sébastien MARQUE authored on 2017-03-07
16
    },
17

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
18
    SoftKey : func (n, a) {
19
        # released key not yet managed
20
        if (a == 1)
21
            return;
22

            
23
        var key = me.device.display.screenElements[sprintf("SoftKey%02i-text",n)].get('text');
24
        if (key == '' or key == nil)
25
            return;
26

            
27
        var path = keyMap[me.role];
28
        foreach(var p; me.path) {
29
            if (contains(path, p))
30
                path = path[p];
31
            else
32
                break;
commit initial
Sébastien MARQUE authored on 2017-03-07
33
        }
34

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
35
        var bindings = me.bindings[me.role];
36
        foreach(var p; me.path) {
37
            if (contains(bindings, p))
38
                bindings = bindings[p];
39
            else
40
                break;
commit initial
Sébastien MARQUE authored on 2017-03-07
41
        }
42

            
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
43
        if (contains(path, key)) {
44
            append(me.path, key);
fix issue with some menus
Sébastien MARQUE authored on 2017-03-20
45
            if (contains(bindings, key))
46
                if (contains(bindings[key], 'hook'))
47
                    call(bindings[key].hook, [], me);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
48
            me.device.display.updateSoftKeys();
commit initial
Sébastien MARQUE authored on 2017-03-07
49
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
50
        elsif (contains(bindings, key)) {
51
            call(bindings[key], [], me);
commit initial
Sébastien MARQUE authored on 2017-03-07
52
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
53
        elsif (key == 'BACK') {
54
            pop(me.path);
55
            me.device.display.updateSoftKeys();
commit initial
Sébastien MARQUE authored on 2017-03-07
56
        }
show the complete path menu ...
Sébastien MARQUE authored on 2017-03-20
57
        else {
58
            var list_path = '';
59
            foreach(var p; me.path) list_path ~= p ~ '/';
60
            print(me.device.role ~ ':' ~ list_path ~ key ~ ' : not yet implemented');
61
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
62
    },
63

            
64
    bindings : {
65
        PFD : {
66
            INSET: {
67
                OFF: func {
68
                    pop(me.path);
69
                    me.device.display.updateSoftKeys();
70
                },
71
            },
72
            PFD: {
adds OAT, TAS, GSPD, WindDat...
Sébastien MARQUE authored on 2017-03-15
73
                'AOA/WIND' : {
74
                    WIND : {
75
                        OPTN1 : func {
76
                            me.device.display._winddata_optn = 1;
77
                            me.device.display.screenElements['WindData'].show();
78
                            me.device.display.screenElements['WindData-OPTN1'].show();
79
                            me.device.display.screenElements['WindData-OPTN1-HDG'].show();
80
                            me.device.display.screenElements['WindData-OPTN2'].hide();
81
                            me.device.display.updateWindData();
82
                        },
83
                        OPTN2 : func {
84
                            me.device.display._winddata_optn = 2;
85
                            me.device.display.screenElements['WindData'].show();
86
                            me.device.display.screenElements['WindData-OPTN1'].hide();
87
                            me.device.display.screenElements['WindData-OPTN2'].show();
88
                            me.device.display.screenElements['WindData-OPTN2-symbol'].show();
89
                            me.device.display.screenElements['WindData-OPTN2-headwind'].show();
90
                            me.device.display.screenElements['WindData-OPTN2-crosswind'].show();
91
                            me.device.display.updateWindData();
92
                        },
93
                        OFF : func {
94
                            me.device.display._winddata_optn = 0;
95
                            me.device.display.screenElements['WindData'].hide();
96
                            me.device.display.screenElements['WindData-OPTN1'].hide();
97
                            me.device.display.screenElements['WindData-OPTN2'].hide();
98
                        },
99
                    },
100
                },
adds BRG1/2 animation
Sébastien MARQUE authored on 2017-03-16
101
                BRG1 : func (brg = 1){
102
                    var source = 'brg' ~ brg ~ '-source';
103
                    var list = ['NAV' ~ brg, 'GPS', 'ADF', 'OFF'];
104
                    var index = std.Vector
105
                                   .new(list)
106
                                   .index(radios.getNode(source).getValue());
107
                    var next = (index == size(list) -1) ?  0 : index + 1;
108
                    radios.getNode(source).setValue(list[next]);
109
                },
110
                BRG2 : func {
111
                    call(me.bindings.PFD.PFD.BRG1, [ 2 ], me);
112
                },
adds BARO settings
Sébastien MARQUE authored on 2017-03-20
113
                'STD BARO' : func {
114
                    setprop('/instrumentation/altimeter/setting-inhg', 29.92);
115
                    me.device.display.updateBARO();
116
                    pop(me.path);
117
                    me.device.display.updateSoftKeys();
118
                },
119
                IN :  func {
120
                    me.device.display._baro_unit = 'inhg';
121
                    me.device.display.updateBARO();
122
                },
123
                HPA : func {
124
                    me.device.display._baro_unit = 'hpa';
125
                    me.device.display.updateBARO();
126
                },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
127
            },
128
            XPDR: {
adds transponder
Sébastien MARQUE authored on 2017-03-17
129
                STBY : func {
130
                    me.bindings.PFD.XPDR.inactivity.restart(45);
131
                    setprop('/instrumentation/transponder/ident', 0);
132
                    setprop('/instrumentation/transponder/knob-mode', 1);
133
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'STBY');
134
                    me.device.display.updateXPDR();
135
                },
136
                ON : func {
137
                    me.bindings.PFD.XPDR.inactivity.restart(45);
138
                    setprop('/instrumentation/transponder/ident', 1);
139
                    setprop('/instrumentation/transponder/knob-mode', 4);
140
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'ON');
141
                    me.device.display.updateXPDR();
142
                },
143
                ALT : func {
144
                    me.bindings.PFD.XPDR.inactivity.restart(45);
145
                    setprop('/instrumentation/transponder/ident', 1);
146
                    setprop('/instrumentation/transponder/knob-mode', 5);
147
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'ALT');
148
                    me.device.display.updateXPDR();
149
                },
150
                VFR : func {
151
                    me.bindings.PFD.XPDR.inactivity.restart(45);
152
                    setprop('/instrumentation/transponder/id-code', '1200');
153
                    me.device.display.updateXPDR();
154
                },
155
                IDENT : func {
156
                    me.bindings.PFD.XPDR.inactivity.restart(45);
157
                    call(me.bindings.PFD.IDENT, [], me);
158
                },
159
                CODE : {
160
                    '0' : func (n = 0) {
161
                        me.bindings.PFD.XPDR.inactivity.restart(45);
162
                        var tuning = radios.getNode('xpdr-tuning-digit');
163
                        var d = tuning.getValue();
164
                        setprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']', n);
165
                        d += (d > 0) ? -1 : 3;
166
                        tuning.setValue(d);
167
                        me.device.display.updateXPDR();
168
                    },
169
                    '1' : func {
170
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 1 ], me);
171
                    },
172
                    '2' : func {
173
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 2 ], me);
174
                    },
175
                    '3' : func {
176
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 3 ], me);
177
                    },
178
                    '4' : func {
179
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 4 ], me);
180
                    },
181
                    '5' : func {
182
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 5 ], me);
183
                    },
184
                    '6' : func {
185
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 6 ], me);
186
                    },
187
                    '7' : func {
188
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 7 ], me);
189
                    },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
190
                    IDENT: func {
adds transponder
Sébastien MARQUE authored on 2017-03-17
191
                        me.bindings.PFD.XPDR.inactivity.restart(45);
192
                        call(me.bindings.PFD.IDENT, [], me);
193
                    },
194
                    BKSP: func {
195
                        me.bindings.PFD.XPDR.inactivity.restart(45);
196
                        var tuning = radios.getNode('xpdr-tuning-digit');
197
                        var d = tuning.getValue();
198
                        d += (d < 3) ? 1 : -3;
199
                        tuning.setValue(d);
200
                        me.device.display.updateXPDR();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
201
                    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
202
                    BACK : func (inactive = 0) {
203
                        var code = sprintf('%i', getprop('/instrumentation/zkv1000/radios/xpdr-backup-code'));
204
                        for (var i = 0; i < 4; i += 1)
205
                            setprop('/instrumentation/transponder/inputs/digit[' ~ (3 - i) ~ ']',
206
                                    substr(code, i, 1));
207
                        pop(me.path);
208
                        call(me.bindings.PFD.XPDR.CODE.exit, inactive ? [[]] : [me.path], me);
209
                    },
210
                    exit : func (p) {
211
                        if (contains(me.bindings.PFD.XPDR, 'inactivity')) # does not exists if IDENT pressed from top-level
212
                            me.bindings.PFD.XPDR.inactivity.stop();
213
                        radios.removeChild('xpdr-tuning-digit', 0);
214
                        radios.removeChild('xpdr-backup-code', 0);
215
                        me.path = p;
216
                        me.device.display.updateXPDR();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
217
                        me.device.display.updateSoftKeys();
218
                    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
219
                    hook : func {
220
                        me.bindings.PFD.XPDR.inactivity.restart(45);
221
                        var tuning = getprop('/instrument/zkv1000/radios/xpdr-tuning-digit');
222
                        if (tuning == nil) {
223
                            radios.getNode('xpdr-tuning-digit', 1).setValue(3);
224
                            radios.getNode('xpdr-backup-code', 1).setValue(getprop('/instrumentation/transponder/id-code'));
225
                            me.device.display.updateXPDR();
226
                        }
227
                    },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
228
                },
adds transponder
Sébastien MARQUE authored on 2017-03-17
229
                hook : func {
230
                    me.bindings.PFD.XPDR.inactivity = maketimer(45,
231
                        func call(me.bindings.PFD.XPDR.CODE.BACK, [1], me));
232
                    me.bindings.PFD.XPDR.inactivity.singleShot = 1;
233
                    me.bindings.PFD.XPDR.inactivity.start();
234
                },
235
            },
236
            IDENT : func {
237
                if (getprop('/instrumentation/zkv1000/radio/xpdr-mode') == 'STBY')
238
                    return;
239
                setprop('/instrumentation/transponder/ident', 1);
240
                me.bindings.PFD.XPDR.ident = maketimer(18,
241
                        func {
242
                            setprop('/instrumentation/transponder/ident', 0);
243
                            me.device.display.updateXPDR();
244
                        });
245
                me.bindings.PFD.XPDR.ident.singleShot = 1;
246
                me.bindings.PFD.XPDR.ident.start();
247
                call(me.bindings.PFD.XPDR.CODE.exit, [[]], me);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
248
            },
adds CDI
Sébastien MARQUE authored on 2017-03-18
249
            CDI : func {
250
                var list = ['OFF'];
251
                if (getprop('/instrumentation/gps/route-distance-nm') != nil)
252
                    append(list, 'GPS');
253
                if (getprop('/instrumentation/nav/in-range') != nil)
254
                    append(list, 'NAV1');
255
                if (getprop('/instrumentation/nav[1]/in-range') != nil)
256
                    append(list, 'NAV2');
257
                var index = std.Vector
258
                               .new(list)
259
                               .index(cdi.getNode('source').getValue());
260
                var next = (index == size(list) -1) ?  0 : index + 1;
261
                cdi.getNode('source').setValue(list[next]);
262
                CDIfromSOURCE(list[next]);
263
                me.device.display.updateCDI();
264
            },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
265
        },
266
        MFD : {
267
            ENGINE: {
268
                FUEL: {
269
                    UNDO: func {
270
                        pop(me.path);
271
                        me.device.display.updateSoftKeys();
272
                    },
273
                    ENTER: func {
274
                        pop(me.path);
275
                        me.device.display.updateSoftKeys();
276
                    },
277
                },
278
                ENGINE: func {
279
                    me.path = [];
280
                    me.device.display.updateSoftKeys();
281
                },
282
            },
add missing exit to MFD/CHKL...
Sébastien MARQUE authored on 2017-03-20
283
            CHKLIST : {
284
                EXIT: func {
285
                    me.path = [];
286
                    me.device.display.updateSoftKeys();
287
                },
288
            },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
289
        },
commit initial
Sébastien MARQUE authored on 2017-03-07
290
    },
291
};