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