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
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Björn Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include "version.h"
#include "debug_menu.h"
#include "sprintf.h"
#include <string.h>
#define KEYBOARD_PAGES 4
static char* kbd_setupkeys(int page)
{
static char* lines[] = {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz",
"01234567890!@#$%&/(){}[]<>",
" +-*_.,:;!?' "
};
return lines[page];
}
int kbd_input(char* text, int buflen)
{
bool done = false;
int page=0, x=0;
char* line = kbd_setupkeys(page);
int linelen = strlen(line);
while(!done)
{
int i;
int len = strlen(text);
lcd_clear_display();
/* draw chars */
for (i=0; i < 11; i++) {
if (line[i+x])
lcd_putc(i, 1, line[i+x]);
else
break;
}
/* write out the text */
if (len <= 11) {
/* if we have enough room */
lcd_puts(0, 0, text);
}
else {
/* if we don't have enough room, write out the last bit only */
lcd_putc(0, 0, '<');
lcd_puts(1, 0, text + len - 10);
}
lcd_update();
switch ( button_get(true) ) {
case BUTTON_MENU:
/* shift */
if (++page == KEYBOARD_PAGES)
page = 0;
line = kbd_setupkeys(page);
linelen = strlen(line);
break;
case BUTTON_RIGHT:
case BUTTON_RIGHT | BUTTON_REPEAT:
if (x < linelen - 1)
x++;
else
x = 0;
break;
case BUTTON_LEFT:
case BUTTON_LEFT | BUTTON_REPEAT:
if (x)
x--;
else
x = linelen - 1;
break;
case BUTTON_STOP:
/* backspace */
if (len)
text[len-1] = 0;
break;
case BUTTON_ON:
/* ON accepts what was entered and continues */
done = true;
break;
case BUTTON_PLAY:
/* PLAY inserts the selected char */
if (len<buflen)
{
text[len] = line[x];
text[len+1] = 0;
}
break;
}
}
return 0;
}
|