zkv1000 / Nasal / knobs.nas /
Newer Older
211 lines | 8.738kb
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
10
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-fms-method', 1);
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 {
15
                    setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 3);
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);
23
        var digit = getprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit');
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 {
49
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-fms-method', 1);
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 {
54
                    setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 3);
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);
62
        setprop('/instrumentation/zkv1000/radios/xpdr-tuning-digit', 1);
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) {
77
                    if (c == size(object.choices) - 1) val = object.choices[0];
78
                    else val = object.choices[c + 1];
79

            
80
                    me.device.windows.window[me.device.windows.selected]
81
                        .setText(val);
82
                    object.text = val;
83
                    break;
add window management
Sébastien MARQUE authored on 2017-03-28
84
                }
in menus some items can be a...
Sébastien MARQUE authored on 2017-04-10
85
            if (find(object.type, 'immediate'))
86
                me.device.buttons.ENT();
add window management
Sébastien MARQUE authored on 2017-03-28
87
        }
add the availibility to modi...
Sébastien MARQUE authored on 2017-04-02
88
        elsif (contains(object, 'format')) {
89
            var v = substr(val, find('%', object.format));
90
            for (var c = 0; c < size(v); c +=1 )
91
                if ((v[c] < `0` or v[c] > `9`)
92
                        and v[c] != `.` and v[c] != ` `
93
                        and v[c] != `-` and v[c] != `+`) {
94
                    v = string.trim(substr(v, 0, c));
95
                    break;
96
                }
97
            v += d * (contains(object, 'factor') ? object.factor : 1);
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

            
113
            ss += d;
114

            
115
            if (ss > 59) {
116
                ss -= 60;
117
                mm += 1;
118
                if (mm > 59) {
119
                    mm = 0;
120
                    hh += 1;
121
                }
122
            }
123
            elsif (ss < 0) {
124
                if (mm > 0) {
125
                    ss += 60;
126
                    mm -= 1;
127
                }
128
                elsif (mm == 0 and hh > 0) {
129
                    ss += 60;
130
                    mm = 59;
131
                    hh -= 1;
132
                }
133
                elsif (mm == 0 and hh == 0)
134
                    ss = 0;
135
            }
forgot to commit this in 14a...
Sébastien MARQUE authored on 2017-04-02
136
            val = sprintf('%02i:%02i:%02i', hh, mm, ss);
add window management
Sébastien MARQUE authored on 2017-03-28
137
            me.device.windows.window[me.device.windows.selected]
forgot to commit this in 14a...
Sébastien MARQUE authored on 2017-04-02
138
                .setText(val);
139
            object.text = val;
add window management
Sébastien MARQUE authored on 2017-03-28
140
        }
141
    },
142

            
143
    NavigateMenu : func (d) {
scrolling available
Sébastien MARQUE authored on 2017-04-02
144
        # d: direction for searching the next selection (-1 or +1)
145
        # i : index of the object (not the canvas object)
146
        # state.scroll.offset : offset between canvas object pointed by i
147
        #                       and object in state hash,
148
        # selected : the canvas object id selected
149
        # id: the id of the window
add window management
Sébastien MARQUE authored on 2017-03-28
150
        var (id, selected) = split('-', me.device.windows.selected);
151
        var state = me.device.windows.state[id];
scrolling available
Sébastien MARQUE authored on 2017-04-02
152
        selected += state.scroll.offset;
153
        # foreach object, beginning at the selected object, offset applied
154
        for (var i = selected + d; i >= 0 and i < size(state.objects); i += d) {
155
            if (i > state.scroll.end
156
                    and d > 0
157
                    and state.scroll.lower < state.scroll.last) {
158
                me._navigatemenu_scrolldown(state, id, i);
159
            }
160
            elsif (i - state.scroll.offset < state.scroll.begin
161
                    and d < 0
162
                    and state.scroll.upper > 0) {
163
                me._navigatemenu_scrollup(state, id, i);
164
            }
165
            if (find('editable', state.objects[i].type) > -1) {
166
                state.objects[selected].type = string.replace(state.objects[selected].type,
add window management
Sébastien MARQUE authored on 2017-03-28
167
                        'selected', 'editable');
168
                me.device.windows.window[me.device.windows.selected]
169
                    .setDrawMode(0x01)
170
                    .setColor(0,1,1);
scrolling available
Sébastien MARQUE authored on 2017-04-02
171
                state.objects[i].type = string.replace(state.objects[i].type,
172
                        'editable', 'selected');
173
                me.device.windows.window[id ~ '-' ~ (i - state.scroll.offset)]
add window management
Sébastien MARQUE authored on 2017-03-28
174
                    .setDrawMode(0x05)
175
                    .setColorFill(0,1,1)
176
                    .setColor(0,0,0);
scrolling available
Sébastien MARQUE authored on 2017-04-02
177
                me.device.windows.selected = id ~ '-' ~ (i - state.scroll.offset);
add window management
Sébastien MARQUE authored on 2017-03-28
178
                break;
179
            }
180
        }
181
    },
182

            
scrolling available
Sébastien MARQUE authored on 2017-04-02
183
    _navigatemenu_scrolldown : func (state, id, i) {
184
        state.scroll.upper = state.objects[i].scrollgroup - state.scroll.lines + 1;
185
        state.scroll.lower = state.objects[i].scrollgroup;
186
        state.scroll.offset = state.scroll.upper * state.scroll.columns;
187

            
188
        # foreach canvas object in the scrolling area
189
        for (var l = state.scroll.begin; l <= state.scroll.end; l += 1) {
190
            var t = state.objects[l + state.scroll.offset].text;
191
            me.device.windows.window[id ~ '-' ~ l]
192
                .setText(t);
193
        }
194
    },
195

            
196
    _navigatemenu_scrollup : func (state, id, i) {
197
        state.scroll.upper = state.objects[i].scrollgroup;
198
        state.scroll.lower = state.objects[i].scrollgroup + state.scroll.lines - 1;
199
        state.scroll.offset = state.scroll.upper * state.scroll.columns;
200

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

            
commit initial
Sébastien MARQUE authored on 2017-03-07
209
    FmsInner : void,
210
    FmsOuter : void
211
};