-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu_sub.c
501 lines (449 loc) · 8.18 KB
/
menu_sub.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*
* menu_sub.c
*
* Created on: 17.06.2012
*****************************************************************************
* MCmega - Firmware for the Motorola MC micro radio
* to use it as an Amateur-Radio transceiver
*
* Copyright (C) 2013 Felix Erckenbrecht, DG1YFE
*
* ( AVR port of "MC70"
* Copyright (C) 2004 - 2013 Felix Erckenbrecht, DG1YFE)
*
* This file is part of MCmega.
*
* MCmega 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.
*
* MCmega 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 MCmega. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************************
*/
#include <stdint.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <stdio.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "macros.h"
#include "regmem.h"
#include "io.h"
#include "menu.h"
#include "display.h"
#include "eeprom.h"
#include "subs.h"
#include "audio.h"
#include "ui.h"
void m_ctcss_submenu(char key);
// Small Submenus
//
//
//
//
//
//*******************************
// M P O W E R
//
// set high or low power via menu
// Power Umschaltung
//
// ---------
// ONLY EVA9
// ---------
//
//
void m_power()
{
if(config.powerMode)
{
// pwr is low, set to high
rfpwr_set(1);
}
else
{
// pwr is high, set to low
rfpwr_set(0);
}
rfpwr_print();
}
void m_power_submenu(char key)
{
char print = 0;
m_reset_timer();
if(m_state != POWER_SELECT)
{
m_state = POWER_SELECT;
print = 1;
}
else
{
switch(key)
{
case KC_D1:
case KC_D2:
config.powerMode ^= 1;
print = 1;
break;
case KC_ENTER:
// TODO: Revert to initial value on "exit"
case KC_EXIT:
m_timer = 0;
break;
default:
break;
}
}
if(print)
{
lcd_cpos(0);
if(config.powerMode)
{
printf_P(PSTR("pwr lo"));
arrow_set(3, 0);
}
else
{
printf_P(PSTR("pwr hi"));
arrow_set(3, 1);
}
lcd_fill();
}
}
//**************************************
//
//
void m_cfgsave_submenu(char key)
{
static char index;
char print = 1;
m_reset_timer();
if (m_state != CONFIG_SELECT)
{
index = config.configAutosave & CONFIG_SAVE_AUTO;
m_state = CONFIG_SELECT;
}
else
{
switch(key)
{
case KC_D1:
{
index = index > 1 ? 0 : index+1;
break;
}
case KC_D2:
{
index = index ? index-1 : 2;
break;
}
case KC_ENTER:
{
print = 0;
if(!(index & CONFIG_SAVE_NOW))
{
uint8_t buf;
buf = (index & CONFIG_SAVE_AUTO);
cfgUpdate.cfgdata = buf;
cfgUpdate.updateMask = CONFIG_UM_CONFIGAUTOSAVE;
config_sendUpdate();
lcd_cpos(0);
printf_P(m_ok_str);
lcd_fill();
vTaskDelay(500);
m_timer = 0;
}
else
{
char err;
// Store current frequency and shift to EEPROM as power-up default
// TODO: Store config structure to EEPROM
cfgUpdate.updateMask = CONFIG_UM_SAVE_TO_EEPROM;
config_sendUpdate();
lcd_cpos(0);
printf_P(m_ok_str);
lcd_fill();
vTaskDelay(500);
lcd_cpos(0);
printf_P(m_stored_str);
lcd_fill();
vTaskDelay(1000);
m_timer = 0;
}
break;
}
case KC_EXIT:
{
print = 0;
m_timer = 0;
break;
}
}
}
if(print)
{
lcd_cpos(0);
switch(index)
{
case CONFIG_SAVE_MANUAL: // manual
printf_P(PSTR("MANUAL"));
break;
case CONFIG_SAVE_AUTO: // automatic
printf_P(PSTR("AUTO"));
break;
default: // store now
printf_P(PSTR("STORE"));
break;
}
lcd_fill();
}
}
//**************************************
//
//
void m_version_submenu(char key)
{
m_state=SHOW_VERSION;
m_reset_timer();
lcd_cpos(0);
printf_P(version_str);
lcd_fill();
if(key == KC_EXIT)
m_timer=0;
}
//**************************************
//
//
void m_ctcss_tx(char key)
{
m_state = CTCSS_SEL_TX;
m_ctcss_submenu(-1);
}
void m_ctcss_rx(char key)
{
m_state = CTCSS_SEL_RX;
m_ctcss_submenu(-1);
}
void m_ctcss_submenu(char key)
{
char print = 1;
uint8_t ctcss_index;
uint8_t ctcss_index_other;
m_reset_timer();
if(m_state == CTCSS_SEL_TX)
{
ctcss_index = config.ctcssIndexTx;
ctcss_index_other = config.ctcssIndexRx;
}
else
{
ctcss_index = config.ctcssIndexRx;
ctcss_index_other = config.ctcssIndexTx;
}
// avoid "same as RX" / "same as TX" for bith settings
// if it happens (eg invalid config), force current index to "CTCSS off" position
if(!ctcss_index && (ctcss_index == ctcss_index_other)){
ctcss_index = 1;
}
if (key != -1)
{
switch(key)
{
case KC_D1:
{
ctcss_index = ctcss_index < CTCSS_TABMAX-1 ? ctcss_index+1 : 0;
// "same as RX" / "same as TX" can only be selected for TX or RX
// otherwise there will be a paradoxon and the whole universe will cease to exist ;)
if(!ctcss_index && (ctcss_index == ctcss_index_other)){
ctcss_index++;
}
break;
}
case KC_D2:
{
ctcss_index = ctcss_index ? ctcss_index-1 : CTCSS_TABMAX-1;
// "same as RX" / "same as TX" can only be selected for TX or RX
// otherwise there will be a paradoxon and the whole universe will cease to exist ;)
if(!ctcss_index && (ctcss_index == ctcss_index_other)){
ctcss_index=CTCSS_TABMAX-1;
}
break;
}
case KC_ENTER:
{
print = 0;
if(m_state == CTCSS_SEL_TX)
{
uint16_t freq;
if(ctcss_index){
freq = pgm_read_word(&ctcss_tab[ctcss_index]);
}
else{
freq = pgm_read_word(&ctcss_tab[ctcss_index_other]);
}
if(freq)
{
tone_start_pl(freq);
}
else
{
tone_stop_pl();
tone_decoder_stop();
lcd_cpos(0);
printf_P(PSTR("TX CTCSS"));
lcd_fill();
lcd_cpos(0);
vTaskDelay(100);
printf_P(PSTR("OFF"));
lcd_fill();
vTaskDelay(100);
}
}
else
{
// CTCSS_SEL_RX
uint16_t freq;
if(ctcss_index){
freq = pgm_read_word(&ctcss_tab[ctcss_index]);
}
else{
freq = pgm_read_word(&ctcss_tab[ctcss_index_other]);
}
if(freq)
{
tone_decoder_start_freq(freq);
}
else
{
tone_decoder_stop();
lcd_cpos(0);
printf_P(PSTR("RX CTCSS"));
lcd_fill();
lcd_cpos(0);
vTaskDelay(100);
printf_P(PSTR("OFF"));
lcd_fill();
vTaskDelay(100);
}
}
lcd_cpos(0);
printf_P(m_ok_str);
lcd_fill();
m_timer=0;
break;
}
case 0:
{
tone_stop_pl();
tone_decoder_stop();
lcd_cpos(0);
printf_P(PSTR("TONE OFF"));
lcd_fill();
vTaskDelay(200);
}
// no break
case KC_EXIT:
{
print = 0;
m_timer = 0;
break;
}
}
}
if(m_state == CTCSS_SEL_TX)
{
config.ctcssIndexTx = ctcss_index;
}
else
{
config.ctcssIndexRx = ctcss_index;
}
if(print)
{
uint16_t freq;
char c[6];
memset(c,0,sizeof c);
if(ctcss_index){
freq = pgm_read_word(&ctcss_tab[ctcss_index]);
}
else{
freq = pgm_read_word(&ctcss_tab[ctcss_index_other]);
}
itoa(freq,c,10);
lcd_cpos(0);
if(ctcss_index && (freq==0))
{
printf_P(PSTR("OFF"));
}
else
{ if (freq == 0)
{
c[0]=' ';
c[1]='O';
c[2]='F';
c[3]='F';
}
else
if (freq<1000)
{
c[3] = c[2];
c[2] = '_';
}
else
{
c[4] = c[3];
c[3] = '_';
}
if(ctcss_index)
{
printf_P(PSTR("%s Hz"),c);
}
else{
if(m_state == CTCSS_SEL_TX)
printf_P(PSTR("=RX%s"),c);
else
printf_P(PSTR("=TX%s"),c);
}
}
lcd_fill();
}
}
void m_cal_submenu(char key)
{
uint8_t cal;
m_reset_timer();
m_state=CAL;
cal = OSCCAL;
switch(key)
{
case KC_D1:
{
cal++;
break;
}
case KC_D2:
{
cal--;
break;
}
case KC_EXIT:
{
m_timer=0;
break;
}
}
OSCCAL = cal;
lcd_cpos(0);
pputchar('x',cal,0);
lcd_fill();
}