zkv1000 / Nasal / softkeys.nas /
Newer Older
272 lines | 12.001kb
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
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
57
        else
58
            print(me.device.role ~ '/' ~ key ~ ' : not yet implemented');
59
    },
60

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