zkv1000 / Nasal / knobs.nas /
Newer Older
232 lines | 10.132kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var knobsClass = {
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
2
    new : func (device) {
commit initial
Sébastien MARQUE authored on 2017-03-07
3
        var m = { parents: [ knobsClass ] };
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
4
        m.device = device;
commit initial
Sébastien MARQUE authored on 2017-03-07
5
        return m;
6
    },
7

            
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
8
    XPDRCodeSetDigits : func (d) {
9
        # disable SoftKey entering method
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
10
        radios.setValue('xpdr-tuning-fms-method', 1);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
11
        if (!contains(me.device.softkeys.bindings.PFD.XPDR.CODE, 'on_change_inactivity')) {
12
            me.device.softkeys.bindings.PFD.XPDR.CODE.inactivity.stop();
13
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity = maketimer(10,
14
                func {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
15
                    radios.setValue('xpdr-tuning-digit', 3);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
16
                    call(me.device.softkeys.bindings.PFD.XPDR.CODE.restore, [], me);
17
                });
18
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.singleShot = 1;
19
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.start();
20
        }
21
        else
22
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.restart(10);
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
23
        var digit = radios.getValue('xpdr-tuning-digit');
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
24
        var code = getprop('/instrumentation/transponder/id-code');
25
        if (digit == 3)
26
            var val = int(code/100) + d;
27
        else
28
            var val = math.mod(code, 100) + d;
29
        if (math.mod(val, 10) == 8) {
30
            if (val > 77)
31
                val = 0;
32
            else
33
                val += 2;
34
        }
35
        elsif (val < 0)
36
            val = 77;
37
        elsif (math.mod(val, 10) == 9)
38
            val -= 2;
39
        if (digit == 3)
40
            setprop('/instrumentation/transponder/id-code',
41
                    sprintf('%i', val * 100 + math.mod(code, 100)));
42
        else
43
            setprop('/instrumentation/transponder/id-code',
44
                    sprintf('%i', int(code/100) * 100 + val));
45
        me.device.display.updateXPDR();
46
    },
47

            
48
    XPDRCodeNextDigits : func {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
49
        radios.setValue('xpdr-tuning-fms-method', 1);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
50
        if (!contains(me.device.softkeys.bindings.PFD.XPDR.CODE, 'on_change_inactivity')) {
51
            me.device.softkeys.bindings.PFD.XPDR.CODE.inactivity.stop();
52
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity = maketimer(10,
53
                func {
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
54
                    radios.setValue('xpdr-tuning-digit', 3);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
55
                    call(me.device.softkeys.bindings.PFD.XPDR.CODE.restore, [], me);
56
                });
57
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.singleShot = 1;
58
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.start();
59
        }
60
        else
61
            me.device.softkeys.bindings.PFD.XPDR.CODE.on_change_inactivity.restart(10);
remove hardcoded properties ...
Sébastien MARQUE authored on 2020-04-27
62
        radios.setValue('xpdr-tuning-digit', 1);
XPDR settings via knob or so...
Sébastien MARQUE authored on 2017-03-22
63
        me.device.display.updateXPDR();
64
    },
65

            
add window management
Sébastien MARQUE authored on 2017-03-28
66
    MenuSettings : func (d) {
67
        var (id, selected) = split('-', me.device.windows.selected);
68
        var state = me.device.windows.state[id];
simplier references
Sébastien MARQUE authored on 2017-04-02
69
        var object = state.objects[selected + state.scroll.offset];
70
        var val = object.text;
71
        if (contains(object, 'choices')) {
some choices may be unidirec...
Sébastien MARQUE authored on 2017-04-02
72
            if ((d > 0 and val[size(val)-1] != `>`)
73
             or (d < 0 and val[0]           != `<`))
74
                return;
simplier references
Sébastien MARQUE authored on 2017-04-02
75
            forindex (var c; object.choices)
76
                if (object.choices[c] == val) {
fix issue #3
Sébastien MARQUE authored on 2017-05-02
77
                    val = object.choices[c + d];
simplier references
Sébastien MARQUE authored on 2017-04-02
78
                    me.device.windows.window[me.device.windows.selected]
79
                        .setText(val);
80
                    object.text = val;
81
                    break;
add window management
Sébastien MARQUE authored on 2017-03-28
82
                }
83
        }
add the availibility to modi...
Sébastien MARQUE authored on 2017-04-02
84
        elsif (contains(object, 'format')) {
85
            var v = substr(val, find('%', object.format));
86
            for (var c = 0; c < size(v); c +=1 )
87
                if ((v[c] < `0` or v[c] > `9`)
88
                        and v[c] != `.` and v[c] != ` `
89
                        and v[c] != `-` and v[c] != `+`) {
90
                    v = string.trim(substr(v, 0, c));
91
                    break;
92
                }
93
            v += d * (contains(object, 'factor') ? object.factor : 1);
add range for formatted valu...
Sébastien MARQUE authored on 2020-04-27
94
            if (contains(object, 'range'))
95
                if ((contains(object.range, 'max') and v > object.range.max)
96
                or  (contains(object.range, 'min') and v < object.range.min))
97
                    return;
add the availibility to modi...
Sébastien MARQUE authored on 2017-04-02
98
            val = sprintf(object.format, v);
99
            me.device.windows.window[me.device.windows.selected]
100
                .setText(val);
101
            object.text = val;
102
        }
simplier references
Sébastien MARQUE authored on 2017-04-02
103
        elsif (find('time', object.type) > -1) {
add window management
Sébastien MARQUE authored on 2017-03-28
104
            var (hh, mm, ss) = split(':', val);
105
            var time = hh * 3600 + mm * 60 + ss;
106
            if (time >= 600) # 10 min
107
                d *= 60;
108
            elsif (time >= 300) # 5 minutes
109
                d *= 30;
110
            elsif (time >= 180) # 3 minutes
111
                d *= 10;
112

            
generic function to format t...
Sébastien MARQUE authored on 2017-04-10
113
            val = HMS(hh, mm, ss, d);
add window management
Sébastien MARQUE authored on 2017-03-28
114

            
115
            me.device.windows.window[me.device.windows.selected]
forgot to commit this in 14a...
Sébastien MARQUE authored on 2017-04-02
116
                .setText(val);
117
            object.text = val;
add window management
Sébastien MARQUE authored on 2017-03-28
118
        }
make immediate callback more...
Sébastien MARQUE authored on 2020-04-27
119
        if (find('immediate', object.type) > -1) {
fix an old hidden bug
Sébastien MARQUE authored on 2020-06-15
120
            if (contains(object, 'callback'))
121
                call(object.callback, [id, selected + state.scroll.offset], me);
make immediate callback more...
Sébastien MARQUE authored on 2020-04-27
122
            else
123
                me.device.buttons.ENT();
124
        }
add window management
Sébastien MARQUE authored on 2017-03-28
125
    },
126

            
127
    NavigateMenu : func (d) {
scrolling available
Sébastien MARQUE authored on 2017-04-02
128
        # d: direction for searching the next selection (-1 or +1)
129
        # i : index of the object (not the canvas object)
130
        # state.scroll.offset : offset between canvas object pointed by i
131
        #                       and object in state hash,
132
        # selected : the canvas object id selected
133
        # id: the id of the window
add window management
Sébastien MARQUE authored on 2017-03-28
134
        var (id, selected) = split('-', me.device.windows.selected);
135
        var state = me.device.windows.state[id];
fix scrolling with multiline...
Sébastien MARQUE authored on 2020-05-22
136
        d *= state.scroll.rows;
scrolling available
Sébastien MARQUE authored on 2017-04-02
137
        selected += state.scroll.offset;
138
        # foreach object, beginning at the selected object, offset applied
139
        for (var i = selected + d; i >= 0 and i < size(state.objects); i += d) {
140
            if (i > state.scroll.end
141
                    and d > 0
142
                    and state.scroll.lower < state.scroll.last) {
143
                me._navigatemenu_scrolldown(state, id, i);
144
            }
145
            elsif (i - state.scroll.offset < state.scroll.begin
146
                    and d < 0
147
                    and state.scroll.upper > 0) {
148
                me._navigatemenu_scrollup(state, id, i);
149
            }
150
            if (find('editable', state.objects[i].type) > -1) {
151
                state.objects[selected].type = string.replace(state.objects[selected].type,
add window management
Sébastien MARQUE authored on 2017-03-28
152
                        'selected', 'editable');
153
                me.device.windows.window[me.device.windows.selected]
withrawal of highlight selec...
Sébastien MARQUE authored on 2020-05-02
154
                    .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
155
                    .setColorFill(0,0,0)
add window management
Sébastien MARQUE authored on 2017-03-28
156
                    .setColor(0,1,1);
scrolling available
Sébastien MARQUE authored on 2017-04-02
157
                state.objects[i].type = string.replace(state.objects[i].type,
158
                        'editable', 'selected');
159
                me.device.windows.window[id ~ '-' ~ (i - state.scroll.offset)]
workaround for non-working s...
Sébastien MARQUE authored on 2020-04-27
160
                    .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
inverted color... the come b...
Sébastien MARQUE authored on 2020-05-15
161
                    .setColorFill(0,1,1)
162
                    .setColor(0,0,0);
scrolling available
Sébastien MARQUE authored on 2017-04-02
163
                me.device.windows.selected = id ~ '-' ~ (i - state.scroll.offset);
add window management
Sébastien MARQUE authored on 2017-03-28
164
                break;
165
            }
166
        }
167
    },
168

            
scrolling available
Sébastien MARQUE authored on 2017-04-02
169
    _navigatemenu_scrolldown : func (state, id, i) {
fix scrolling with multiline...
Sébastien MARQUE authored on 2020-05-22
170
        state.scroll.upper = state.objects[i].scrollgroup - state.scroll.lines + state.scroll.rows;
scrolling available
Sébastien MARQUE authored on 2017-04-02
171
        state.scroll.lower = state.objects[i].scrollgroup;
172
        state.scroll.offset = state.scroll.upper * state.scroll.columns;
fix scrolling with multiline...
Sébastien MARQUE authored on 2020-05-22
173
        if (state.scroll.rows > 1 and i - state.scroll.offset > state.scroll.lines * state.scroll.columns * state.scroll.rows)
174
            state.scroll.offset = i - state.scroll.lines * state.scroll.columns * state.scroll.rows;
scrolling available
Sébastien MARQUE authored on 2017-04-02
175

            
176
        # foreach canvas object in the scrolling area
177
        for (var l = state.scroll.begin; l <= state.scroll.end; l += 1) {
178
            var t = state.objects[l + state.scroll.offset].text;
179
            me.device.windows.window[id ~ '-' ~ l]
180
                .setText(t);
181
        }
182
    },
183

            
184
    _navigatemenu_scrollup : func (state, id, i) {
185
        state.scroll.upper = state.objects[i].scrollgroup;
fix scrolling with multiline...
Sébastien MARQUE authored on 2020-05-22
186
        state.scroll.lower = state.objects[i].scrollgroup + state.scroll.lines - state.scroll.rows;
187
        state.scroll.offset = state.scroll.upper * state.scroll.columns * state.scroll.rows;
188
        if (state.scroll.rows > 1 and i == state.scroll.offset) {
189
            state.scroll.offset -= state.scroll.columns * state.scroll.rows;
190
            if (state.scroll.offset < state.scroll.begin) {
191
                state.scroll.offset = state.scroll.begin;
192
                return;
193
            }
194
        }
scrolling available
Sébastien MARQUE authored on 2017-04-02
195

            
196
        # foreach canvas object in the scrolling area
197
        for (var l = state.scroll.begin; l <= state.scroll.end; l += 1) {
198
            var t = state.objects[l + state.scroll.offset].text;
199
            me.device.windows.window[id ~ '-' ~ l]
200
                .setText(t);
201
        }
202
    },
203

            
adds MFD page selection syst...
Sébastien MARQUE authored on 2017-04-13
204
    MFD_select_page_group : func (d) {
205
        if (contains(me.device.windows.state, 'page selection')) {
206
            if (me.device.display['page selected'] + d < size(me.device.data['page selection'])
207
            and me.device.display['page selected'] + d >= 0) {
finalize MFD menus
Sébastien MARQUE authored on 2017-04-25
208
                me.device.windows.del('page selection');
adds MFD page selection syst...
Sébastien MARQUE authored on 2017-04-13
209
                me.device.display['page selected'] += d;
210
            }
211
            else
212
                return;
213
        }
214
        me.device.windows.draw('page selection',
215
                me.device.data['page selection'][me.device.display['page selected']].geometry,
216
                me.device.data['page selection'][me.device.display['page selected']].objects,
217
            );
218
        me.FmsInner = me.NavigateMenu;
fix bad behaviour
Sébastien MARQUE authored on 2017-06-02
219
        me.device.buttons.ENT = me.device.buttons.ValidateTMRREF;
finalize MFD menus
Sébastien MARQUE authored on 2017-04-25
220
        me.device.buttons.CLR = func {
221
            me.device.display['page selected'] = 0;
222
            me.device.windows.del('page selection');
223
            me.device.buttons.CLR = func;
224
            me.device.buttons.ENT = func;
225
        };
adds MFD page selection syst...
Sébastien MARQUE authored on 2017-04-13
226
    },
227

            
commit initial
Sébastien MARQUE authored on 2017-03-07
228
    FmsInner : void,
slow down FMS knobs
Sébastien MARQUE authored on 2020-04-27
229
    FmsOuter : void,
230
    FmsInner_slowdown: 0,
231
    FmsOuter_slowdown: 0,
commit initial
Sébastien MARQUE authored on 2017-03-07
232
};