zkv1000 / Nasal / softkeys.nas /
Newer Older
255 lines | 11.158kb
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);
add the ability to exec hook...
Sébastien MARQUE authored on 2017-03-16
45
            if (contains(bindings[key], 'hook'))
46
                call(bindings[key].hook, [], me);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
47
            me.device.display.updateSoftKeys();
commit initial
Sébastien MARQUE authored on 2017-03-07
48
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
49
        elsif (contains(bindings, key)) {
50
            call(bindings[key], [], me);
commit initial
Sébastien MARQUE authored on 2017-03-07
51
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
52
        elsif (key == 'BACK') {
53
            pop(me.path);
54
            me.device.display.updateSoftKeys();
commit initial
Sébastien MARQUE authored on 2017-03-07
55
        }
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
56
        else
57
            print(me.device.role ~ '/' ~ key ~ ' : not yet implemented');
58
    },
59

            
60
    bindings : {
61
        PFD : {
62
            INSET: {
63
                OFF: func {
64
                    pop(me.path);
65
                    me.device.display.updateSoftKeys();
66
                },
67
            },
68
            PFD: {
69
                'STD BARO': func {
70
                    pop(me.path);
71
                    me.device.display.updateSoftKeys();
72
                },
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
                },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
113
            },
114
            XPDR: {
adds transponder
Sébastien MARQUE authored on 2017-03-17
115
                STBY : func {
116
                    me.bindings.PFD.XPDR.inactivity.restart(45);
117
                    setprop('/instrumentation/transponder/ident', 0);
118
                    setprop('/instrumentation/transponder/knob-mode', 1);
119
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'STBY');
120
                    me.device.display.updateXPDR();
121
                },
122
                ON : func {
123
                    me.bindings.PFD.XPDR.inactivity.restart(45);
124
                    setprop('/instrumentation/transponder/ident', 1);
125
                    setprop('/instrumentation/transponder/knob-mode', 4);
126
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'ON');
127
                    me.device.display.updateXPDR();
128
                },
129
                ALT : func {
130
                    me.bindings.PFD.XPDR.inactivity.restart(45);
131
                    setprop('/instrumentation/transponder/ident', 1);
132
                    setprop('/instrumentation/transponder/knob-mode', 5);
133
                    setprop('/instrumentation/zkv1000/radio/xpdr-mode', 'ALT');
134
                    me.device.display.updateXPDR();
135
                },
136
                VFR : func {
137
                    me.bindings.PFD.XPDR.inactivity.restart(45);
138
                    setprop('/instrumentation/transponder/id-code', '1200');
139
                    me.device.display.updateXPDR();
140
                },
141
                IDENT : func {
142
                    me.bindings.PFD.XPDR.inactivity.restart(45);
143
                    call(me.bindings.PFD.IDENT, [], me);
144
                },
145
                CODE : {
146
                    '0' : func (n = 0) {
147
                        me.bindings.PFD.XPDR.inactivity.restart(45);
148
                        var tuning = radios.getNode('xpdr-tuning-digit');
149
                        var d = tuning.getValue();
150
                        setprop('/instrumentation/transponder/inputs/digit[' ~ d ~ ']', n);
151
                        d += (d > 0) ? -1 : 3;
152
                        tuning.setValue(d);
153
                        me.device.display.updateXPDR();
154
                    },
155
                    '1' : func {
156
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 1 ], me);
157
                    },
158
                    '2' : func {
159
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 2 ], me);
160
                    },
161
                    '3' : func {
162
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 3 ], me);
163
                    },
164
                    '4' : func {
165
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 4 ], me);
166
                    },
167
                    '5' : func {
168
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 5 ], me);
169
                    },
170
                    '6' : func {
171
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 6 ], me);
172
                    },
173
                    '7' : func {
174
                        call(me.bindings.PFD.XPDR.CODE['0'], [ 7 ], me);
175
                    },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
176
                    IDENT: func {
adds transponder
Sébastien MARQUE authored on 2017-03-17
177
                        me.bindings.PFD.XPDR.inactivity.restart(45);
178
                        call(me.bindings.PFD.IDENT, [], me);
179
                    },
180
                    BKSP: func {
181
                        me.bindings.PFD.XPDR.inactivity.restart(45);
182
                        var tuning = radios.getNode('xpdr-tuning-digit');
183
                        var d = tuning.getValue();
184
                        d += (d < 3) ? 1 : -3;
185
                        tuning.setValue(d);
186
                        me.device.display.updateXPDR();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
187
                    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
188
                    BACK : func (inactive = 0) {
189
                        var code = sprintf('%i', getprop('/instrumentation/zkv1000/radios/xpdr-backup-code'));
190
                        for (var i = 0; i < 4; i += 1)
191
                            setprop('/instrumentation/transponder/inputs/digit[' ~ (3 - i) ~ ']',
192
                                    substr(code, i, 1));
193
                        pop(me.path);
194
                        call(me.bindings.PFD.XPDR.CODE.exit, inactive ? [[]] : [me.path], me);
195
                    },
196
                    exit : func (p) {
197
                        if (contains(me.bindings.PFD.XPDR, 'inactivity')) # does not exists if IDENT pressed from top-level
198
                            me.bindings.PFD.XPDR.inactivity.stop();
199
                        radios.removeChild('xpdr-tuning-digit', 0);
200
                        radios.removeChild('xpdr-backup-code', 0);
201
                        me.path = p;
202
                        me.device.display.updateXPDR();
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
203
                        me.device.display.updateSoftKeys();
204
                    },
adds transponder
Sébastien MARQUE authored on 2017-03-17
205
                    hook : func {
206
                        me.bindings.PFD.XPDR.inactivity.restart(45);
207
                        var tuning = getprop('/instrument/zkv1000/radios/xpdr-tuning-digit');
208
                        if (tuning == nil) {
209
                            radios.getNode('xpdr-tuning-digit', 1).setValue(3);
210
                            radios.getNode('xpdr-backup-code', 1).setValue(getprop('/instrumentation/transponder/id-code'));
211
                            me.device.display.updateXPDR();
212
                        }
213
                    },
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
214
                },
adds transponder
Sébastien MARQUE authored on 2017-03-17
215
                hook : func {
216
                    me.bindings.PFD.XPDR.inactivity = maketimer(45,
217
                        func call(me.bindings.PFD.XPDR.CODE.BACK, [1], me));
218
                    me.bindings.PFD.XPDR.inactivity.singleShot = 1;
219
                    me.bindings.PFD.XPDR.inactivity.start();
220
                },
221
            },
222
            IDENT : func {
223
                if (getprop('/instrumentation/zkv1000/radio/xpdr-mode') == 'STBY')
224
                    return;
225
                setprop('/instrumentation/transponder/ident', 1);
226
                me.bindings.PFD.XPDR.ident = maketimer(18,
227
                        func {
228
                            setprop('/instrumentation/transponder/ident', 0);
229
                            me.device.display.updateXPDR();
230
                        });
231
                me.bindings.PFD.XPDR.ident.singleShot = 1;
232
                me.bindings.PFD.XPDR.ident.start();
233
                call(me.bindings.PFD.XPDR.CODE.exit, [[]], me);
softkeys are available now
Sébastien MARQUE authored on 2017-03-14
234
            },
235
        },
236
        MFD : {
237
            ENGINE: {
238
                FUEL: {
239
                    UNDO: func {
240
                        pop(me.path);
241
                        me.device.display.updateSoftKeys();
242
                    },
243
                    ENTER: func {
244
                        pop(me.path);
245
                        me.device.display.updateSoftKeys();
246
                    },
247
                },
248
                ENGINE: func {
249
                    me.path = [];
250
                    me.device.display.updateSoftKeys();
251
                },
252
            },
253
        },
commit initial
Sébastien MARQUE authored on 2017-03-07
254
    },
255
};