zkv1000 / Nasal / softkeys.nas /
Newer Older
297 lines | 11.827kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var softkeysClass = {
2
    new : func (node, role) {
3
        var m = { parents: [ softkeysClass ] };
4
        m.node = node;
5
        m.role = role;
6
        m.rootmenu = m.role == 'MFD' ? 16 : 0;
7
        m.goto(m.rootmenu);
8
        return m;
9
    },
10

            
11
    SoftKey : func (n, a) {
12
        printf("%s softkey %i (%s)", me.role, n, a == 1 ? "pushed" : "released");
13
#        me._SoftKey[me.rootlevel + me.level][n](a);
14
    },
15

            
16
    goto: func (l) {
17
        me.level = l;
18
    },
19

            
20
    GPS: func { 
21
        nyi('GPS softkey');
22
        me.goto(me.rootmenu);
23
    },
24

            
25
    CDIOFF: func {
26
        cdi.getNode('visible').setBoolValue(0);
27
        radios.getNode('nav1-selected').setIntValue(0);
28
        radios.getNode('nav2-selected').setIntValue(0);
29
        cdi.getNode('in-range').unalias();
30
        cdi.getNode('course').unalias();
31
        cdi.getNode('course-deflection').unalias();
32
        cdi.getNode('pointer-type').setIntValue(0);
33
        cdi.getNode('from-flag').unalias();
34
        var mode = nil;
35
        mode = getprop('/autopilot/locks/roll');
36
        if (mode == 'NAV' or mode == 'APR')
37
            AFCS.ROLL();
38
        mode = getprop('/autopilot/locks/pitch');
39
        if (mode == 'GS' or mode == 'APR')
40
            AFCS.PIT();
41
        me.goto(me.rootmenu);
42
    },
43

            
44
    VOR: func (n) {
45
        radios.getNode('nav' ~ (2-n) ~ '-selected').setIntValue(0);
46
        radios.getNode('nav' ~ (1+n) ~ '-selected').setIntValue(1);
47
        CDIfromNAV(n);
48
        me.goto(me.rootmenu);
49
    },
50

            
51
    NRST: func {
52
        var title = me.mud.node.getNode('title').getValue();
53
        if (substr(title, 0, 8) == 'NEAREST ') {
54
            me.mud.close();
55
            me.largeFMSknob = void;
56
            me.smallFMSknob = void;
57
        }
58
        else {
59
            lockSearches();
60
            searchNearestNavaid('airport', 10);
61
            showSearchResults(me.mud, 'NEAREST AIRPORTS', 'mag-bearing-deg', 
62
                    func { msg('set HDG to ' ~ arg[0][0]);
63
                        setprop('/instrumentation/zkv1000/afcs/heading-bug-deg', arg[0][0]) 
64
                    }
65
            );
66
            unlockSearches();
67
            me.smallFMSknob = func (dir) { selectSearchType(me.mud, dir) };
68
            me.largeFMSknob = func (dir) { me.mud.select(dir) };
69
        }
70
    },
71

            
72
    INSETOFF: func { 
73
        me.newstatus(1);
74
    },
75

            
76
    TRAFFIC: func {
77
        if (props.globals.getNode('/instrumentation/radar/serviceable') != nil 
78
        and props.globals.getNode('/instrumentation/radar/display-controls/tcas') != nil) {
79
            if (getprop('/instrumentation/radar/serviceable') 
80
            and getprop('/instrumentation/radar/display-controls/tcas')) {
81
                me.newstatus(5);
82
            }
83
        }
84
        else {
85
            msg('unable to find TCAS config, no radar');
86
            me.goto(me.rootmenu);
87
        }
88
    },
89

            
90
    TOPO: func { 
91
        me.newstatus(2);
92
        me.node.getNode('mfd-title').setValue('TOPO');
93
        setprop(me.map_path ~ '/longitude-deg', getprop('/position/longitude-deg'));
94
        setprop(me.map_path ~ '/latitude-deg', getprop('/position/latitude-deg'));
95
        me.map.getNode('latitude-deg').alias('/position/latitude-deg');
96
        me.map.getNode('longitude-deg').alias('/position/longitude-deg');
97
    },
98

            
99
    TERRAIN: func {
100
        me.newstatus(3);
101
        me.node.getNode('mfd-title').setValue('TERR ' ~ mapRanges[getprop(me.map_path ~ '/range-index')]);
102
        me.map.getNode('latitude-deg').unalias();
103
        me.map.getNode('longitude-deg').unalias();
104
        setprop(me.map_path ~ '/longitude-deg', getprop('/position/longitude-deg'));
105
        setprop(me.map_path ~ '/latitude-deg', getprop('/position/latitude-deg'));
106
    },
107

            
108
    STRMSCP: func { 
109
        nyi('STRMSCP softkey');
110
        me.goto(me.rootmenu);
111
    },
112

            
113
    NEXRAD: func { 
114
        nyi('NEXRAD softkey');
115
        me.goto(me.rootmenu);
116
    },
117

            
118
    XMLTNG: func { 
119
        nyi('XMLTNG softkey');
120
        me.goto(me.rootmenu);
121
    },
122

            
123
    DCLTROFF: func { 
124
        nyi('DCLTROFF softkey');
125
        me.goto(me.rootmenu);
126
    },
127

            
128
    DCLTR: func (x) { 
129
        nyi('DCLTR' ~ x ~ ' softkey');
130
        me.goto(me.rootmenu);
131
    },
132

            
133
    DFLTS: func { 
134
        nyi('DEFAULTS softkey');
135
        me.goto(me.rootmenu);
136
    },
137

            
138
    DME: func { 
139
        nyi('DME softkey');
140
        me.goto(me.rootmenu);
141
    },
142

            
143
    STDBARO: func { 
144
        setprop('/instrumentation/altimeter/setting-inhg', 29.92);
145
        me.goto(me.rootmenu);
146
    },
147

            
148
    BRG1: func (x) { 
149
        nyi('BRG1' ~ x ~ ' softkey');
150
        me.goto(me.rootmenu);
151
    },
152

            
153
    BRG2: func (x) { 
154
        nyi('BRG2' ~ x ~ ' softkey');
155
        me.goto(me.rootmenu);
156
    },
157

            
158
    BRGOFF: func (x) { 
159
        nyi('BRGOFF' ~ x ~ ' softkey');
160
        me.goto(me.rootmenu);
161
    },
162

            
163
    HSI360: func { 
164
        me.node.getNode('hsi-360').setBoolValue(1);
165
        me.goto(me.rootmenu);
166
    },
167

            
168
    HSIARC: func { 
169
        me.node.getNode('hsi-360').setBoolValue(0);
170
        me.goto(me.rootmenu);
171
    },
172

            
173
    OPTN: func (x) { 
174
        me.node.getNode('wind-data').setBoolValue(1);
175
        wind_infos = zkv1000['wind_opt' ~ x];
176
        me.goto(me.rootmenu);
177
    },
178

            
179
    WINDOFF: func { 
180
        wind_infos = void;
181
        me.node.getNode('wind-data').setBoolValue(1);
182
        setprop('/instrumentation/zkv1000/infos/wind-line', '');
183
        setprop('/instrumentation/zkv1000/infos/wind-line[1]', '');
184
        me.goto(me.rootmenu);
185
    },
186

            
187
    METERS: func { 
188
        nyi('METERS softkey');
189
        me.goto(me.rootmenu);
190
    },
191

            
192
    IN: func { 
193
        nyi('IN softkey');
194
        me.goto(me.rootmenu);
195
    },
196

            
197
    HPA: func { 
198
        nyi('HPA softkey');
199
        me.goto(me.rootmenu);
200
    },
201

            
202
    ON: func { 
203
        setprop('/instrumentation/zkv1000/radios/xpdr-mode', 'ON');
204
        setprop('/instrumentation/transponder/serviceable', 1);
205
        me.goto(me.rootmenu);
206
    },
207

            
208
    ALT: func { 
209
        setprop('/instrumentation/zkv1000/radios/xpdr-mode', 'ALT');
210
        setprop('/instrumentation/transponder/serviceable', 1);
211
        me.goto(me.rootmenu);
212
    },
213

            
214
    GND: func {
215
        setprop('/instrumentation/zkv1000/radios/xpdr-mode', 'GND');
216
        setprop('/instrumentation/transponder/serviceable', 1);
217
        me.goto(me.rootmenu);
218
    },
219

            
220
    VFR: func { 
221
        XPDR_old = getprop('/instrumentation/transponder/id-code');
222
        setprop('/instrumentation/zkv1000/radios/xpdr-mode', 'VFR');
223
        setprop('/instrumentation/transponder/serviceable', 0);
224
        me.goto(me.rootmenu);
225
    },
226

            
227
    XPDR: func (x) {
228
        if (x <= 7) {
229
            if (XPDR_n == 3) {
230
                XPDR_old = getprop('/instrumentation/transponder/id-code');
231
            }
232
            elsif (XPDR_n < 0) {
233
                me.goto(10);
234
                XPDR_n = 3;
235
                return;
236
            }
237
            else {
238
                setprop('/instrumentation/transponder/id-code', x * math.pow(10, XPDR_n));
239
                XPDR_n -= 1;
240
            }
241
        }
242
        else {
243
            if (x == 9) setprop('/instrumentation/transponder/id-code', XPDR_old);
244
            XPDR_n = 3;
245
            me.goto(me.rootmenu);
246
        }
247
    },
248

            
249
    CODE: func {
250
        getprop('/instrumentation/zkv1000/radios/xpdr-mode') == 'STBY' or return;
251
        me.largeFMSknob = func (x) { 
252
            XPDR_change_cursor_position(x); 
253
            settimer(func { me.ENTsoftkey(1) }, 10); 
254
        }
255
        me.smallFMSknob = func (x) { 
256
            XPDR_enter_digits(x);
257
            settimer(func { me.ENTsoftkey(1) }, 10); 
258
        }
259
        me.goto(11);
260
    },
261

            
262
    TMRREF: func (ref) { 
263
        time = zkv1000['time' ~ ref];
264
        me.goto(me.rootmenu);
265
    },
266

            
267
    CHRON: func {
268
        fgcommand('dialog-show', props.Node.new({
269
            'dialog-name': 'stopwatch-dialog',
270
        }));
271
        me.goto(me.rootmenu);
272
    },
273

            
274
    set_softkeyActionTable: func {
275
        me.softkeyActionTable = [
276
            [void,               func{me.goto(2)},void,             func{me.goto(4)},  void,              func{me.goto(1)},  ADFDME,            func{me.goto(10)},IDENT,            func{me.goto(17)}, func{me.NRST()}],
277
            [void,               func{me.VOR(0)}, func{me.VOR(1)},  func{me.GPS()},    void,              void,              func{me.CDIOFF()}, void,             void,             void,              func{me.goto(me.rootmenu)}],
278
            [func{me.INSETOFF()},func{me.goto(3)},void,             func{me.TRAFFIC()},func{me.TOPO()},   func{me.TERRAIN()},func{me.STRMSCP()},func{me.NEXRAD()},func{me.XMLTNG()},void,              func{me.goto(me.rootmenu)}],
279
            [func{me.DCLTROFF()},void,            func{me.DCLTR(1)},func{me.DCLTR(2)}, func{me.DCLTR(3)}, void,              void,              void,             void,             void,              func{me.goto(2)}],
280
            [LIGHT,              func{me.DFLTS()},func{me.goto(8)}, func{me.DME()},    func{me.goto(5)},  func{me.goto(7)},  func{me.goto(6)},  void,             func{me.goto(9)}, func{me.STDBARO()},func{me.goto(me.rootmenu)}],
281
            [func{me.BRG1(1)},   func{me.BRG1(2)},func{me.BRG1(3)}, void,              func{me.BRGOFF(1)},void,              void,              void,             void,             void,              func{me.goto(4)}],
282
            [func{me.BRG2(1)},   func{me.BRG2(2)},func{me.BRG2(3)}, void,              func{me.BRGOFF(2)},void,              void,              void,             void,             void,              func{me.goto(4)}],
283
            [void,               void,            void,             void,              void,              func{me.HSI360()}, func{me.HSIARC()}, void,             void,             void,              func{me.goto(4)}],
284
            [void,               void,            func{me.OPTN(1)}, func{me.OPTN(2)},  func{me.OPTN(3)},  void,              func{me.WINDOFF()},void,             void,             void,              func{me.goto(4)}],
285
            [void,               void,            void,             void,              void,              func{me.METERS()}, void,              func{me.IN()},    func{me.HPA()},   void,              func{me.goto(4)}],
286
            [void,               void,            STDBY,            func{me.ON()},     func{me.ALT()},    func{me.GND()},    func{me.VFR()},    func{me.CODE()},  IDENT,            void,              func{me.goto(me.rootmenu)}],
287
            [func{me.XPDR(0)},   func{me.XPDR(1)},func{me.XPDR(2)}, func{me.XPDR(3)},  func{me.XPDR(4)},  func{me.XPDR(5)},  func{me.XPDR(6)},  func{me.XPDR(7)}, func{me.XPDR(8)}, BKSP,              func{me.XPDR(9)}],
288
            [func{me.newstatus(1)},func{me.goto(15)},void,          func{me.goto(14)}, void,              func{me.goto(13)}, void,              CHECKLIST,        void,             void,              void],
289
            [void,               void,            func{me.DCLTR(1)},void,              func{me.DCLTR(2)}, void,              func{me.DCLTR(3)}, void,             void,             void,              func{me.goto(me.rootmenu)}],
290
            [void,               void,            void,             func{me.TRAFFIC()},func{me.TOPO()},   func{me.TERRAIN()},func{me.STRMSCP()},func{me.NEXRAD()},func{me.XMLTNG()},void,              func{me.goto(me.rootmenu)}],
291
            [func{me.goto(me.rootmenu)},void,     LEAN,             void,              void,              void,              func{FUEL(1)},     func{FUEL(2)},    func{FUEL(3)},    void,              void],
292
            [func{me.newstatus(2)},func{me.goto(2)},void,             func{me.goto(4)},  void,              func{me.goto(1)},  ADFDME,            func{me.goto(10)},IDENT,            func{me.goto(17)}, func{me.NRST()}],
293
            [func{me.TMRREF('LCL')},func{me.TMRREF('UTC')},void,    func{me.TMRREF('RL')},void,           func{me.CHRON()},  void,              void,             void,             void,              func{me.goto(me.rootmenu)}],
294
        ];
295
    },
296

            
297
};