-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu_input.c
321 lines (290 loc) · 5.67 KB
/
menu_input.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
/*
* menu_input.c
*
* Created on: 02.06.2012
*****************************************************************************
* MCmega - Firmware for the Motorola MC micro radio
* to use it as an Amateur-Radio transceiver
*
* Copyright (C) 2013,2014 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/>.
*
****************************************************************************
*
*/
//*******************************
// M S T A R T I N P U T
//
// Frequenzeingabe �ber ZIffernfeld starten
//
//
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "regmem.h"
#include "macros.h"
#include "io.h"
#include "display.h"
#include "menu.h"
#include "menu_top.h"
#include "pll_freq.h"
void mde_up(uint8_t currentpos, char loval, char hival);
void mde_down(uint8_t currentpos, char loval, char hival);
void mde_next(uint8_t * currentpos, uint8_t lopos, uint8_t hipos);
void mde_enter(uint8_t currentpos, const uint8_t lopos, const uint8_t hipos);
void m_print(char key);
void m_start_input(char key);
void m_backspace (void);
void m_clr_displ (void);
void m_set_freq (void);
void m_set_freq_x(void);
void m_frq_prnt(void);
static inline void m_non_numeric(char key);
inline void m_start_input(char key)
{
save_dbuf();
lcd_clr(0);
memset(f_in_buf,0,sizeof(f_in_buf)); // clear input buffer;
m_print(key);
m_state = F_IN;
}
inline void m_print(char key)
{
m_reset_timer();
f_in_buf[cpos] = key + 0x30;
pputchar('c', key + 0x30, 0);
}
//**********************************
// M F I N
//
// Frequenzeingabe, Eingabe entgegennehmen
//
void m_f_in(char key)
{
if(key < KC_NON_NUMERIC)
{
if(cpos < 8)
{
m_print(key);
}
}
else
{
m_non_numeric(key);
}
}
static inline void m_non_numeric(char key)
{
switch(key)
{
case KC_EXIT:
{
m_backspace();
break;
}
case KC_D4:
{
m_clr_displ();
break;
}
case KC_D7:
{
m_set_shift();
break;
}
case KC_ENTER:
{
m_set_freq();
break;
}
default:
{
m_none(key);
break;
}
}
}
//
//**********************************
// M B A C K S P A C E
//
// eingegebenes Zeichen l�schen
//
void m_backspace ()
{
m_reset_timer();
lcd_backspace();
f_in_buf[cpos]=0;
}
//**********************************
// M C L R D I S P L
//
// Display und Eingabe l�schen
//
void m_clr_displ ()
{
m_reset_timer();
lcd_clr(0);
f_in_buf[0] = 0;
}
//*******************************
//
// M S E T F R E Q
//
// eingegebene Frequenz setzen
//
void m_set_freq ()
{
uint8_t i;
// append zeros
for(i=cpos;i<6;i++)
{
f_in_buf[i] = '0';
}
f_in_buf[i] = 0;
m_set_freq_x();
}
inline void m_set_freq_x()
{
unsigned long f;
f = atol(f_in_buf);
// convert frequency input in kHz to Hz
f *= 1000;
config.frequency = f;
// send updated frequency to control task
frq_update(&f);
lcd_clr(0);
m_state = M_IDLE;
printf_P(m_ok_str);
vTaskDelay(200);
m_frq_prnt();
}
inline void m_frq_prnt()
{
lcd_cpos(0);
freq_print(&config.frequency);
freq_offset_print();
lcd_fill();
m_timer_en = 0;
pll_timer = 0;
}
//*******************************
//
// M D I G I T E D I T O R
//
// Editiert einen Bereich im Display
//
// Parameter: lopos - Niedrigstes/Erstes Digit
// hipos - H�chstes/Letztes Digit
// Mode : 0 - Dezimal
// 1 - Alphanumerisch
// 2 - Alphabet
// -1 - Init
//
// Ergebnis : Status : 0 - continue editig
// 1 - input ok (f_in_buf)
// -1 - abort
//
#define MDE_FIRST_POS 4
#define MDE_LAST_POS 3
#define MDE_LOWER_LIM 2
#define MDE_UPPER_LIM 1
#define MDE_CUR_POS 0
//
char m_digit_editor(char key, uint8_t lopos, char hipos, int8_t mode)
{
static signed currentpos = 0;
char hival = 0, loval = 0;
char exit = 0;
switch(mode)
{
case 0:
hival = '9';
loval = '0';
break;
// 0 - num
// 1 - alphanum
// 2 - alpha
case 1:
hival = 'z';
loval = '0';
break;
case 2:
hival = 'z';
loval = 'a';
break;
case -1:
{
lcd_cpos(lopos);
currentpos = lopos;
// make character blink
lcd_chr_mode(currentpos, 1);
return 0;
}
}
switch(key)
{
case KC_D1:
if(dbuf[currentpos] >= hival)
dbuf[currentpos]=loval;
else
dbuf[currentpos]++;
lcd_cpos(currentpos);
pputchar('c',dbuf[currentpos] | CHR_BLINK,0);
break;
case KC_D2:
if(dbuf[currentpos] <= loval)
dbuf[currentpos]=hival;
else
dbuf[currentpos]--;
lcd_cpos(currentpos);
pputchar('c',dbuf[currentpos] | CHR_BLINK,0);
break;
case KC_D6:
case KC_D3:
lcd_chr_mode(currentpos,0);
if(currentpos <= lopos)
currentpos = hipos;
else
currentpos++;
lcd_chr_mode(currentpos,1);
break;
case KC_ENTER:
{
uint8_t count;
lcd_chr_mode(currentpos, 0);
count=hipos - lopos + 1;
memcpy(f_in_buf, &dbuf[lopos], count);
f_in_buf[count] = 0;
exit = 1;
break;
}
case KC_EXIT:
lcd_chr_mode(currentpos, 0);
exit=-1;
break;
default:
break;
}
return(exit);
}