zkv1000 / Nasal / softkeys.nas /
Newer Older
284 lines | 12.568kb
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
    SoftKey : func (n, a) {
12
        # released key not yet managed
13
        if (a == 1)
14
            return;
15

            
16
        var key = me.device.display.screenElements[sprintf("SoftKey%02i-text",n)].get('text');
17
        if (key == '' or key == nil)
18
            return;
19

            
20
        var path = keyMap[me.role];
21
        foreach(var p; me.path) {
22
            if (contains(path, p))
23
                path = path[p];
24
            else
25
                break;
commit initial
Sébastien MARQUE authored on 2017-03-07
26
        }
27

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

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

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