forked from semerad/gt3b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_mix.c
288 lines (250 loc) · 6.68 KB
/
menu_mix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
menu_mix - handle menus for mix settings
Copyright (C) 2011 Pavel Semerad
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "menu.h"
#include "config.h"
#include "calc.h"
#include "timer.h"
#include "ppm.h"
#include "lcd.h"
#include "buzzer.h"
#include "input.h"
static void mix_4WS(u8 action) {
u8 val;
if (action == MLA_CHG) {
// change value
switch (menu_set) {
case 0:
// channel number/off
val = cm.channel_4WS;
if (!val) val = 2;
val = (u8)menu_change_val(val, 2, channels, 1, 1);
if (val == 2) cm.channel_4WS = 0;
else cm.channel_4WS = val;
set_menu_channels_mixed();
break;
case 1:
// mix value
menu_4WS_mix = (s8)menu_change_val(menu_4WS_mix, -100, 100,
MIX_FAST, 0);
break;
case 2:
// crab/no-crab
menu_4WS_crab ^= 1;
}
}
else if (action == MLA_NEXT) {
// select next value
if (++menu_set > 2) menu_set = 0;
if (!cm.channel_4WS) menu_set = 0;
}
// show value
lcd_7seg(4);
switch (menu_set) {
case 0:
// channel number/OFF
if (!cm.channel_4WS) lcd_chars("OFF");
else lcd_char_num3(cm.channel_4WS);
lcd_segment(LS_SYM_CHANNEL, LS_ON);
break;
case 1:
// mix value
lcd_char_num3(menu_4WS_mix);
lcd_segment(LS_SYM_PERCENT, LS_ON);
break;
case 2:
// crab/no-crab
lcd_chars("CR");
lcd_char(LCHR3, (u8)(menu_4WS_crab + '0'));
menu_blink &= (u8)~(MCB_CHR1 | MCB_CHR2);
}
}
static void mix_DIG(u8 action) {
u8 val;
if (action == MLA_CHG) {
// change value
switch (menu_set) {
case 0:
// channel number/off
val = cm.channel_DIG;
if (!val) val = 2;
val = (u8)menu_change_val(val, 1, channels, 1, 1);
if (val == 2) cm.channel_DIG = 0;
else cm.channel_DIG = val;
set_menu_channels_mixed();
break;
case 1:
// mix value
menu_DIG_mix = (s8)menu_change_val(menu_DIG_mix, -100, 100,
MIX_FAST, 0);
break;
}
}
else if (action == MLA_NEXT) {
// select next value
if (++menu_set > 1) menu_set = 0;
if (!cm.channel_DIG) menu_set = 0;
}
// show value
lcd_7seg(L7_D);
switch (menu_set) {
case 0:
// channel number/OFF
if (!cm.channel_DIG) lcd_chars("OFF");
else lcd_char_num3(cm.channel_DIG);
lcd_segment(LS_SYM_CHANNEL, LS_ON);
break;
case 1:
// mix value
lcd_char_num3(menu_DIG_mix);
lcd_segment(LS_SYM_PERCENT, LS_ON);
break;
}
}
@inline static void set_channel_MP(u8 mp_id, u8 val) {
switch (mp_id) {
case 0:
cm.channel_MP0 = val;
break;
case 1:
cm.channel_MP1 = val;
break;
case 2:
cm.channel_MP2 = val;
break;
case 3:
cm.channel_MP3 = val;
break;
}
}
static void mix_MultiPosition(u8 action) {
s8 val;
// get mp_id from menu_id, MP starts at menu_id 2
u8 mp_id = (u8)(menu_id - 2);
s8 *multi_position;
u8 channel_MP;
u8 num_MP = config_get_MP(mp_id, &channel_MP, &multi_position);
// check if this MP is allowed at set number of channels
if ((u8)(mp_id + 3) > channels) {
lcd_7seg(L7_P);
lcd_char(LCHR1, (u8)(mp_id + '1'));
lcd_chars2("NA");
menu_blink &= (u8)~MCB_CHR1;
return;
}
if (action == MLA_CHG) {
// change value
if (menu_set == 0) {
// channel number/off
val = channel_MP;
if (!val) val = 2;
else if (val == MP_DIG) val = (s8)(channels + 1);
val = (u8)menu_change_val(val, 2, channels + 1, 1, 1);
if (val == 2) val = 0;
else if (val > channels) val = MP_DIG;
channel_MP = val;
set_channel_MP(mp_id, channel_MP);
}
else {
// position value + END state (END not for first position)
val = multi_position[menu_set - 1];
if (val == MULTI_POSITION_END) val = -101;
val = (s8)menu_change_val(val, menu_set == 1 ? -100 : -101, 100,
CHANNEL_FAST, 0);
if (val == -101) {
// set all from this to END value
memset(&multi_position[menu_set - 1], (u8)MULTI_POSITION_END,
num_MP - (menu_set - 1));
}
else multi_position[menu_set - 1] = val;
}
}
else if (action == MLA_NEXT) {
// select next value
if (channel_MP) {
if (menu_set == 0) menu_set = 1;
else if (multi_position[menu_set - 1] == MULTI_POSITION_END
|| ++menu_set > num_MP) menu_set = 0;
}
// allow forcing channel value
if (menu_set && channel_MP && channel_MP <= channels) {
menu_force_value_channel = channel_MP;
}
else menu_force_value_channel = 0;
}
// show value
lcd_7seg(L7_P);
if (menu_set == 0) {
// show MP id
lcd_char(LCHR1, (u8)(mp_id + '1'));
lcd_char(LCHR2, ' ');
// channel number/OFF
lcd_char(LCHR3, (u8)(channel_MP == MP_DIG ? 'D' : (u8)(channel_MP + '0')));
lcd_segment(LS_SYM_CHANNEL, LS_ON);
menu_blink &= (u8)~(MCB_CHR1 | MCB_CHR2);
}
else {
// position value
val = multi_position[menu_set - 1];
if (val == MULTI_POSITION_END) {
lcd_chars("END");
val = -100;
}
else lcd_char_num3(val);
if (channel_MP == MP_DIG) menu_DIG_mix = val;
else menu_force_value = val * PPM(5);
}
}
static void mix_brake_off(u8 action) {
// change value
if (action == MLA_CHG) cm.brake_off ^= 1;
// show value
lcd_7seg(L7_B);
lcd_chars(cm.brake_off ? "CUT" : "OFF");
}
static void mix_brake_channel(u8 action) {
u8 val = cm.channel_brake;
if (action == MLA_CHG) {
// channel number/off
if (!val) val = 2;
val = (u8)menu_change_val(val, 2, channels, 1, 1);
if (val == 2) val = 0;
cm.channel_brake = val;
set_menu_channels_mixed();
}
// show value
lcd_7seg(8);
lcd_segment(LS_SYM_CHANNEL, LS_ON);
// channel number/OFF
if (!val) lcd_chars("OFF");
else lcd_char_num3(val);
}
static const menu_list_t mix_funcs[] = {
mix_4WS,
mix_DIG,
mix_MultiPosition,
mix_MultiPosition,
mix_MultiPosition,
mix_MultiPosition,
mix_brake_off,
mix_brake_channel,
};
void menu_mix(void) {
lcd_set_blink(LMENU, LB_SPC);
menu_list(mix_funcs, sizeof(mix_funcs) / sizeof(void *), MCF_NONE);
lcd_set_blink(LMENU, LB_OFF);
config_model_save();
apply_model_config();
}