diff options
Diffstat (limited to 'apps/player')
-rw-r--r-- | apps/player/keyboard.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c new file mode 100644 index 0000000000..be0e43b8a9 --- /dev/null +++ b/apps/player/keyboard.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Björn Stenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "lcd.h" | ||
20 | #include "button.h" | ||
21 | #include "kernel.h" | ||
22 | #include "version.h" | ||
23 | #include "debug_menu.h" | ||
24 | #include "sprintf.h" | ||
25 | #include <string.h> | ||
26 | |||
27 | #define KEYBOARD_PAGES 4 | ||
28 | |||
29 | static char* kbd_setupkeys(int page) | ||
30 | { | ||
31 | static char* lines[] = { | ||
32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
33 | "abcdefghijklmnopqrstuvwxyz", | ||
34 | "01234567890!@#$%&/(){}[]<>", | ||
35 | "+-*_.,:;!?'" | ||
36 | }; | ||
37 | |||
38 | return lines[page]; | ||
39 | } | ||
40 | |||
41 | int kbd_input(char* text, int buflen) | ||
42 | { | ||
43 | bool done = false; | ||
44 | int page=0, x=0; | ||
45 | char* line = kbd_setupkeys(page); | ||
46 | int linelen = strlen(line); | ||
47 | |||
48 | while(!done) | ||
49 | { | ||
50 | int i; | ||
51 | int len = strlen(text); | ||
52 | |||
53 | lcd_clear_display(); | ||
54 | |||
55 | /* draw chars */ | ||
56 | for (i=0; i < 11; i++) | ||
57 | lcd_putc(i, 1, line[i+x]); | ||
58 | |||
59 | /* write out the text */ | ||
60 | if (len <= 11) { | ||
61 | /* if we have enough room */ | ||
62 | lcd_puts(0, 0, text); | ||
63 | } | ||
64 | else { | ||
65 | /* if we don't have enough room, write out the last bit only */ | ||
66 | lcd_putc(0, 0, '<'); | ||
67 | lcd_puts(1, 0, text + len - 10); | ||
68 | } | ||
69 | lcd_update(); | ||
70 | |||
71 | switch ( button_get(true) ) { | ||
72 | |||
73 | case BUTTON_MENU: | ||
74 | /* Page */ | ||
75 | if (++page == KEYBOARD_PAGES) | ||
76 | page = 0; | ||
77 | line = kbd_setupkeys(page); | ||
78 | linelen = strlen(line); | ||
79 | break; | ||
80 | |||
81 | case BUTTON_RIGHT: | ||
82 | if (x < linelen - 1) | ||
83 | x++; | ||
84 | else | ||
85 | x = 0; | ||
86 | break; | ||
87 | |||
88 | case BUTTON_LEFT: | ||
89 | if (x) | ||
90 | x--; | ||
91 | else | ||
92 | x = linelen - 1; | ||
93 | break; | ||
94 | |||
95 | case BUTTON_STOP: | ||
96 | /* backspace */ | ||
97 | if (len) | ||
98 | text[len-1] = 0; | ||
99 | break; | ||
100 | |||
101 | case BUTTON_ON: | ||
102 | /* F2 accepts what was entered and continues */ | ||
103 | done = true; | ||
104 | break; | ||
105 | |||
106 | case BUTTON_PLAY: | ||
107 | /* PLAY inserts the selected char */ | ||
108 | if (len<buflen) | ||
109 | { | ||
110 | text[len] = line[x]; | ||
111 | text[len+1] = 0; | ||
112 | } | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||