summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/player/keyboard.c274
1 files changed, 155 insertions, 119 deletions
diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c
index e164b04861..15349a65fd 100644
--- a/apps/player/keyboard.c
+++ b/apps/player/keyboard.c
@@ -67,6 +67,20 @@ static unsigned short* kbd_setupkeys(int page, int* len)
67 return lines; 67 return lines;
68} 68}
69 69
70/* Delimiters for highlighting the character selected for insertion */
71#define KEYBOARD_INSERT_LEFT 0x81
72#define KEYBOARD_INSERT_RIGHT 0x82
73
74#define KEYBOARD_CURSOR 0x7f
75#define KEYBOARD_ARROW 0x92
76
77#define MENU_LINE_INPUT 0
78#define MENU_LINE_NEWCHARS 1
79#define MENU_LINE_DELETE 2
80#define MENU_LINE_ACCEPT 3
81#define MENU_LINE_QUIT 4
82#define MENU_LINE_LAST 4
83
70int kbd_input(char* text, int buflen) 84int kbd_input(char* text, int buflen)
71{ 85{
72 bool done = false; 86 bool done = false;
@@ -77,16 +91,11 @@ int kbd_input(char* text, int buflen)
77 int cursor_pos=0; 91 int cursor_pos=0;
78 int button_pressed; 92 int button_pressed;
79 unsigned char temptext[12]; 93 unsigned char temptext[12];
80#define MENU_LINE_FILENAME 0 94 bool cursor_on=true; /* Blinking cursor control */
81#define MENU_LINE_NEWCHARS 1
82#define MENU_LINE_DELETE 2
83#define MENU_LINE_ACCEPT 3
84#define MENU_LINE_QUIT 4
85#define MENU_LINE_LAST 4
86 95
87 lcd_clear_display(); 96 lcd_clear_display();
88 97
89 while(!done) { 98 while (!done) {
90 int i, p; 99 int i, p;
91 int len = strlen(text); 100 int len = strlen(text);
92 101
@@ -98,147 +107,174 @@ int kbd_input(char* text, int buflen)
98 } 107 }
99 108
100 while (p<10 && line[i]) { 109 while (p<10 && line[i]) {
101 if (i == cursor_pos) 110 if (i == cursor_pos && cursor_on)
102 temptext[p++]=0x7f; 111 {
103 temptext[p++]=text[i]; 112 temptext[p++]=KEYBOARD_CURSOR;
104 i++; 113 i++;
114 } else {
115 temptext[p++]=text[i++];
116 }
105 } 117 }
106 temptext[p]=0; 118 temptext[p]=0;
107 lcd_puts(1, 0, temptext); 119 lcd_puts(1, 0, temptext);
120 cursor_on = !cursor_on;
108 121
109 switch (menu_line) { 122 switch (menu_line) {
110 case MENU_LINE_FILENAME: 123 case MENU_LINE_INPUT:
111 case MENU_LINE_NEWCHARS: 124 case MENU_LINE_NEWCHARS:
112 /* Draw insert chars */ 125 /* Draw insert chars */
113 temptext[0]=0x81; 126 temptext[0]=KEYBOARD_INSERT_LEFT;
114 temptext[1]=line[x%linelen]; 127 temptext[1]=line[x%linelen];
115 temptext[2]=0x82; 128 temptext[2]=KEYBOARD_INSERT_RIGHT;
116 for (i=1; i < 8; i++) { 129 for (i=1; i < 8; i++) {
117 temptext[i+2]=line[(i+x)%linelen]; 130 temptext[i+2]=line[(i+x)%linelen];
118 } 131 }
119 temptext[p]=0; 132 temptext[p]=0;
120 lcd_puts(1, 1, temptext); 133 lcd_puts(1, 1, temptext);
121 break; 134 break;
122 case MENU_LINE_DELETE: 135 case MENU_LINE_DELETE:
123 lcd_puts_scroll(1, 1, "Delete next char"); 136 lcd_puts_scroll(1, 1, "Delete");
124 break; 137 break;
125 case MENU_LINE_ACCEPT: 138 case MENU_LINE_ACCEPT:
126 lcd_puts_scroll(1, 1, "Accept"); 139 lcd_puts_scroll(1, 1, "Accept");
127 break; 140 break;
128 case MENU_LINE_QUIT: 141 case MENU_LINE_QUIT:
129 lcd_puts_scroll(1, 1, "Cancel"); 142 lcd_puts_scroll(1, 1, "Cancel");
130 break; 143 break;
131 } 144 }
132 if (menu_line==MENU_LINE_FILENAME) { 145 if (menu_line==MENU_LINE_INPUT) {
133 lcd_putc(0, 0, 0x92); 146 lcd_putc(0, 0, KEYBOARD_ARROW);
134 lcd_putc(0, 1, ' '); 147 lcd_putc(0, 1, ' ');
135 } else { 148 } else {
136 lcd_putc(0, 0, ' '); 149 lcd_putc(0, 0, ' ');
137 lcd_putc(0, 1, 0x92); 150 lcd_putc(0, 1, KEYBOARD_ARROW);
138 } 151 }
139 152
140 lcd_update(); 153 lcd_update();
141 154
142 button_pressed=button_get(true); 155 button_pressed=button_get_w_tmo(HZ/2);
143 if (menu_line==MENU_LINE_FILENAME) { 156 switch (menu_line)
144 switch ( button_pressed ) { 157 {
145 case BUTTON_UP: 158 case MENU_LINE_INPUT:
146 case BUTTON_UP | BUTTON_REPEAT: 159 switch (button_pressed)
147 if (cursor_pos<len) 160 {
148 cursor_pos++; 161 case BUTTON_UP:
149 button_pressed=0; 162 case BUTTON_UP | BUTTON_REPEAT:
150 break; 163 if (cursor_pos<len)
151 case BUTTON_DOWN: 164 cursor_pos++;
152 case BUTTON_DOWN | BUTTON_REPEAT: 165 button_pressed=BUTTON_NONE;
153 if (cursor_pos>0) 166 cursor_on=true;
154 cursor_pos--; 167 break;
155 button_pressed=0; 168 case BUTTON_DOWN:
156 break; 169 case BUTTON_DOWN | BUTTON_REPEAT:
157 } 170 if (cursor_pos>0)
158 } else if (menu_line==MENU_LINE_NEWCHARS) { 171 cursor_pos--;
159 switch ( button_pressed ) { 172 button_pressed=BUTTON_NONE;
160 173 cursor_on=true;
161 case BUTTON_UP: 174 break;
162 case BUTTON_UP | BUTTON_REPEAT: 175 }
163 x=(x+1+linelen)%linelen;
164 button_pressed=0;
165 break;
166 case BUTTON_DOWN:
167 case BUTTON_DOWN | BUTTON_REPEAT:
168 x=(x-1+linelen)%linelen;
169 button_pressed=0;
170 break; 176 break;
177
178 case MENU_LINE_NEWCHARS:
179 switch (button_pressed)
180 {
181 case BUTTON_UP:
182 case BUTTON_UP | BUTTON_REPEAT:
183 x=(x+1+linelen)%linelen;
184 button_pressed=BUTTON_NONE;
185 break;
186 case BUTTON_DOWN:
187 case BUTTON_DOWN | BUTTON_REPEAT:
188 x=(x-1+linelen)%linelen;
189 button_pressed=BUTTON_NONE;
190 break;
171 191
172 case BUTTON_MENU: 192 case BUTTON_MENU:
173 /* shift */ 193 /* shift */
174 if (++page == KEYBOARD_PAGES) 194 if (++page == KEYBOARD_PAGES)
175 page = 0; 195 page = 0;
176 line = kbd_setupkeys(page, &linelen); 196 line = kbd_setupkeys(page, &linelen);
177 break; 197 break;
178 198
179 case BUTTON_ON: 199 case BUTTON_ON:
180 if (len < buflen) { 200 if (len < buflen) {
181 /* ON insert the char */ 201 /* ON insert the char */
182 for (i=len; i>cursor_pos; i--) { 202 for (i=len; i>cursor_pos; i--) {
183 text[i]=text[i-1]; 203 text[i]=text[i-1];
184 } 204 }
185 text[cursor_pos]=line[x]; 205 text[cursor_pos]=line[x];
186 button_pressed=0; 206 button_pressed=BUTTON_NONE;
187 cursor_pos++; 207 cursor_pos++;
208 }
209 break;
188 } 210 }
189 break; 211 break;
190 } 212
191 } else if (menu_line==MENU_LINE_DELETE) { 213 case MENU_LINE_DELETE:
192 switch ( button_pressed ) { 214 switch (button_pressed) {
193 case BUTTON_ON: 215 case BUTTON_ON:
194 case BUTTON_PLAY: 216 case BUTTON_PLAY:
195 case BUTTON_PLAY | BUTTON_REPEAT: 217 case BUTTON_PLAY | BUTTON_REPEAT:
196 button_pressed=0; 218 button_pressed=BUTTON_NONE;
197 for (i=cursor_pos; i<=len; i++) { 219 for (i=cursor_pos; i<=len; i++) {
198 text[i]=text[i+1]; 220 text[i]=text[i+1];
221 }
222 break;
223 case BUTTON_STOP:
224 case BUTTON_STOP | BUTTON_REPEAT:
225 button_pressed=BUTTON_NONE;
226 if (0 < cursor_pos)
227 for (i=--cursor_pos; i<=len; i++) {
228 text[i]=text[i+1];
229 }
230 break;
199 } 231 }
200 break; 232 break;
201 } 233
202 } else if (menu_line==MENU_LINE_ACCEPT) { 234 case MENU_LINE_ACCEPT:
203 switch ( button_pressed ) { 235 switch (button_pressed) {
204 case BUTTON_ON: 236 case BUTTON_ON:
205 case BUTTON_PLAY: 237 case BUTTON_PLAY:
206 case BUTTON_PLAY | BUTTON_REPEAT: 238 case BUTTON_PLAY | BUTTON_REPEAT:
207 button_pressed=0; 239 button_pressed=BUTTON_NONE;
208 done=true; 240 done=true;
241 break;
242 }
209 break; 243 break;
210 } 244
211 } else if (menu_line==MENU_LINE_QUIT) { 245 case MENU_LINE_QUIT:
212 switch ( button_pressed ) { 246 switch (button_pressed) {
213 case BUTTON_ON: 247 case BUTTON_ON:
214 case BUTTON_PLAY: 248 case BUTTON_PLAY:
215 case BUTTON_PLAY | BUTTON_REPEAT: 249 case BUTTON_PLAY | BUTTON_REPEAT:
216 return 1; 250 return 1;
251 break;
252 }
217 break; 253 break;
218 }
219 } 254 }
220 255
221 /* Handle unhandled events */ 256 /* Handle unhandled events */
222 switch ( button_pressed ) { 257 switch (button_pressed) {
223 case 0: 258 case BUTTON_NONE:
224 /* button is already handled */ 259 /* button is already handled */
225 break; 260 break;
226 261
227 case BUTTON_MENU | BUTTON_STOP: 262 case BUTTON_MENU | BUTTON_STOP:
228 break; 263 break;
229 264
230 case BUTTON_RIGHT: 265 case BUTTON_RIGHT:
231 case BUTTON_RIGHT | BUTTON_REPEAT: 266 case BUTTON_RIGHT | BUTTON_REPEAT:
232 if (menu_line<MENU_LINE_LAST) 267 if (menu_line<MENU_LINE_LAST)
233 menu_line++; 268 menu_line++;
234 break; 269 break;
235 270
236 case BUTTON_LEFT: 271 case BUTTON_LEFT:
237 case BUTTON_LEFT | BUTTON_REPEAT: 272 case BUTTON_LEFT | BUTTON_REPEAT:
238 if (menu_line>0) 273 if (menu_line>0)
239 menu_line--; 274 menu_line--;
240 break; 275 break;
241 } 276 }
242 } 277 }
278
243 return 0; 279 return 0;
244} 280}