summaryrefslogtreecommitdiff
path: root/apps/recorder/keyboard.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2005-12-02 19:41:09 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2005-12-02 19:41:09 +0000
commit9d918c94b5df3468de5da8ebc1dee9d1fdaaf2a8 (patch)
tree28faf716a4c552819e32f9b1b9b1da06debe87e6 /apps/recorder/keyboard.c
parentc99f8bc6e3b2ea16268f56bd55c6f4ede40b6629 (diff)
downloadrockbox-9d918c94b5df3468de5da8ebc1dee9d1fdaaf2a8.tar.gz
rockbox-9d918c94b5df3468de5da8ebc1dee9d1fdaaf2a8.zip
iRiver: Added initial support for standard morse code input to virtual keyboard.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8129 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder/keyboard.c')
-rw-r--r--apps/recorder/keyboard.c172
1 files changed, 159 insertions, 13 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index fc3d1686a4..d17bcaf36b 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -31,6 +31,7 @@
31#include "settings.h" 31#include "settings.h"
32#include "misc.h" 32#include "misc.h"
33#include "buttonbar.h" 33#include "buttonbar.h"
34#include "logf.h"
34 35
35#define KEYBOARD_MARGIN 3 36#define KEYBOARD_MARGIN 3
36 37
@@ -59,6 +60,7 @@
59#define KBD_RIGHT BUTTON_RIGHT 60#define KBD_RIGHT BUTTON_RIGHT
60#define KBD_UP BUTTON_UP 61#define KBD_UP BUTTON_UP
61#define KBD_DOWN BUTTON_DOWN 62#define KBD_DOWN BUTTON_DOWN
63#define HAVE_MORSE_INPUT
62 64
63#elif CONFIG_KEYPAD == RECORDER_PAD 65#elif CONFIG_KEYPAD == RECORDER_PAD
64#define KBD_CURSOR_RIGHT (BUTTON_ON | BUTTON_RIGHT) 66#define KBD_CURSOR_RIGHT (BUTTON_ON | BUTTON_RIGHT)
@@ -145,6 +147,19 @@ static const char * const kbdpages[KEYBOARD_PAGES][KEYBOARD_LINES] = {
145 147
146#endif 148#endif
147 149
150#ifdef HAVE_MORSE_INPUT
151/* FIXME: We should put this to a configuration file. */
152static const char *morse_alphabets =
153 "abcdefghijklmnopqrstuwvxyzåäö1234567890,";
154static const unsigned char morse_codes[] = {
155 0x05,0x18,0x1a,0x0c,0x02,0x12,0x0e,0x10,0x04,0x17,0x0d,0x14,0x07,
156 0x06,0x0f,0x16,0x1d,0x0a,0x08,0x03,0x09,0x11,0x0b,0x19,0x1b,0x1c,
157 0x2d,0x15,0x1e,0x2f,0x27,0x23,0x21,0x20,0x30,0x38,0x3c,0x3f,0x3f,
158 0x73 };
159
160static bool morse_mode = false;
161#endif
162
148/* helper function to spell a char if voice UI is enabled */ 163/* helper function to spell a char if voice UI is enabled */
149static void kbd_spellchar(char c) 164static void kbd_spellchar(char c)
150{ 165{
@@ -160,9 +175,7 @@ static void kbd_spellchar(char c)
160int kbd_input(char* text, int buflen) 175int kbd_input(char* text, int buflen)
161{ 176{
162 bool done = false; 177 bool done = false;
163#if KEYBOARD_PAGES > 1
164 int page = 0; 178 int page = 0;
165#endif
166 int font_w = 0, font_h = 0, i; 179 int font_w = 0, font_h = 0, i;
167 int x = 0, y = 0; 180 int x = 0, y = 0;
168 int main_x, main_y, max_chars; 181 int main_x, main_y, max_chars;
@@ -171,6 +184,12 @@ int kbd_input(char* text, int buflen)
171 int editpos, curpos, leftpos; 184 int editpos, curpos, leftpos;
172 bool redraw = true; 185 bool redraw = true;
173 const char * const *line; 186 const char * const *line;
187#ifdef HAVE_MORSE_INPUT
188 bool morse_reading = false;
189 unsigned char morse_code = 0;
190 int morse_tick = 0, morse_len, j;
191 char buf[2];
192#endif
174#ifdef KBD_MODES 193#ifdef KBD_MODES
175 bool line_edit = false; 194 bool line_edit = false;
176#endif 195#endif
@@ -198,22 +217,59 @@ int kbd_input(char* text, int buflen)
198 line = kbdpages[0]; 217 line = kbdpages[0];
199 218
200 if (global_settings.talk_menu) /* voice UI? */ 219 if (global_settings.talk_menu) /* voice UI? */
201 talk_spell(text, true); /* spell initial text */ 220 talk_spell(text, true); /* spell initial text */
202 221
203 while(!done) 222 while(!done)
204 { 223 {
205 len = strlen(text); 224 len = strlen(text);
206 225
207 if(redraw) 226 if (redraw)
208 { 227 {
209 lcd_clear_display(); 228 lcd_clear_display();
210 229
211 lcd_setfont(FONT_SYSFIXED); 230 lcd_setfont(FONT_SYSFIXED);
212 231
213 /* draw page */ 232#ifdef HAVE_MORSE_INPUT
214 for (i=0; i < KEYBOARD_LINES; i++) 233 if (morse_mode)
215 lcd_putsxy(0, 8+i * font_h, line[i]); 234 {
216 235 x = 0;
236 y = font_h;
237 buf[1] = '\0';
238 /* Draw morse code table with code descriptions. */
239 for (i = 0; morse_alphabets[i] != '\0'; i++)
240 {
241 buf[0] = morse_alphabets[i];
242 lcd_putsxy(x, y, buf);
243
244 for (j = 0; (morse_codes[i] >> j) > 0x01; j++) ;
245 morse_len = j;
246
247 x += font_w + 3;
248 for (j = 0; j < morse_len; j++)
249 {
250 if ((morse_codes[i] >> (morse_len-j-1)) & 0x01)
251 lcd_fillrect(x + j*4, y + 2, 3, 4);
252 else
253 lcd_fillrect(x + j*4, y + 3, 1, 2);
254 }
255
256 x += font_w * 5 - 3;
257 if (x >= LCD_WIDTH - (font_w*6))
258 {
259 x = 0;
260 y += font_h;
261 }
262 }
263 }
264 else
265#endif
266 {
267 /* draw page */
268 for (i=0; i < KEYBOARD_LINES; i++)
269 lcd_putsxy(0, 8+i * font_h, line[i]);
270
271 }
272
217 /* separator */ 273 /* separator */
218 lcd_hline(0, LCD_WIDTH - 1, main_y - KEYBOARD_MARGIN); 274 lcd_hline(0, LCD_WIDTH - 1, main_y - KEYBOARD_MARGIN);
219 275
@@ -229,11 +285,11 @@ int kbd_input(char* text, int buflen)
229 lcd_putsxy(0, main_y, "<"); 285 lcd_putsxy(0, main_y, "<");
230 if (len - leftpos > max_chars) 286 if (len - leftpos > max_chars)
231 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">"); 287 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
232 288
233 /* cursor */ 289 /* cursor */
234 i = (curpos + 1) * font_w; 290 i = (curpos + 1) * font_w;
235 lcd_vline(i, main_y, main_y + font_h); 291 lcd_vline(i, main_y, main_y + font_h);
236 292
237#ifdef HAS_BUTTONBAR 293#ifdef HAS_BUTTONBAR
238 /* draw the status bar */ 294 /* draw the status bar */
239 gui_buttonbar_set(&buttonbar, "Shift", "OK", "Del"); 295 gui_buttonbar_set(&buttonbar, "Shift", "OK", "Del");
@@ -258,6 +314,7 @@ int kbd_input(char* text, int buflen)
258 redraw = true; 314 redraw = true;
259 315
260 button = button_get_w_tmo(HZ/2); 316 button = button_get_w_tmo(HZ/2);
317
261 switch ( button ) { 318 switch ( button ) {
262 319
263 case KBD_ABORT: 320 case KBD_ABORT:
@@ -265,10 +322,26 @@ int kbd_input(char* text, int buflen)
265 return -1; 322 return -1;
266 break; 323 break;
267 324
268#if defined(KBD_PAGE_FLIP) && KEYBOARD_PAGES > 1 325#if defined(KBD_PAGE_FLIP)
269 case KBD_PAGE_FLIP: 326 case KBD_PAGE_FLIP:
327#ifdef HAVE_MORSE_INPUT
328 if (morse_mode)
329 {
330 main_y = (KEYBOARD_LINES + 1) * font_h + (2*KEYBOARD_MARGIN);
331 morse_mode = false;
332 }
333 else
334#endif
270 if (++page == KEYBOARD_PAGES) 335 if (++page == KEYBOARD_PAGES)
336 {
271 page = 0; 337 page = 0;
338#ifdef HAVE_MORSE_INPUT
339 main_y = LCD_HEIGHT - font_h;
340 morse_mode = true;
341 /* FIXME: We should talk something like Morse mode.. */
342 break ;
343#endif
344 }
272 line = kbdpages[page]; 345 line = kbdpages[page];
273 kbd_spellchar(line[y][x]); 346 kbd_spellchar(line[y][x]);
274 break; 347 break;
@@ -276,6 +349,10 @@ int kbd_input(char* text, int buflen)
276 349
277 case KBD_RIGHT: 350 case KBD_RIGHT:
278 case KBD_RIGHT | BUTTON_REPEAT: 351 case KBD_RIGHT | BUTTON_REPEAT:
352#ifdef HAVE_MORSE_INPUT
353 if (morse_mode)
354 break;
355#endif
279#ifdef KBD_MODES 356#ifdef KBD_MODES
280 if (line_edit) /* right doubles as cursor_right in line_edit */ 357 if (line_edit) /* right doubles as cursor_right in line_edit */
281 { 358 {
@@ -306,6 +383,10 @@ int kbd_input(char* text, int buflen)
306 383
307 case KBD_LEFT: 384 case KBD_LEFT:
308 case KBD_LEFT | BUTTON_REPEAT: 385 case KBD_LEFT | BUTTON_REPEAT:
386#ifdef HAVE_MORSE_INPUT
387 if (morse_mode)
388 break;
389#endif
309#ifdef KBD_MODES 390#ifdef KBD_MODES
310 if (line_edit) /* left doubles as cursor_left in line_edit */ 391 if (line_edit) /* left doubles as cursor_left in line_edit */
311 { 392 {
@@ -336,6 +417,10 @@ int kbd_input(char* text, int buflen)
336 417
337 case KBD_DOWN: 418 case KBD_DOWN:
338 case KBD_DOWN | BUTTON_REPEAT: 419 case KBD_DOWN | BUTTON_REPEAT:
420#ifdef HAVE_MORSE_INPUT
421 if (morse_mode)
422 break;
423#endif
339#ifdef KBD_MODES 424#ifdef KBD_MODES
340 if (line_edit) 425 if (line_edit)
341 { 426 {
@@ -360,6 +445,10 @@ int kbd_input(char* text, int buflen)
360 445
361 case KBD_UP: 446 case KBD_UP:
362 case KBD_UP | BUTTON_REPEAT: 447 case KBD_UP | BUTTON_REPEAT:
448#ifdef HAVE_MORSE_INPUT
449 if (morse_mode)
450 break;
451#endif
363#ifdef KBD_MODES 452#ifdef KBD_MODES
364 if (line_edit) 453 if (line_edit)
365 { 454 {
@@ -391,7 +480,32 @@ int kbd_input(char* text, int buflen)
391 done = true; 480 done = true;
392 break; 481 break;
393 482
483#ifdef HAVE_MORSE_INPUT
484 case KBD_SELECT | BUTTON_REL:
485 if (morse_mode && morse_reading)
486 {
487 morse_code <<= 1;
488 if ((current_tick - morse_tick) > HZ/5)
489 morse_code |= 0x01;
490 }
491
492 break;
493#endif
494
394 case KBD_SELECT: 495 case KBD_SELECT:
496#ifdef HAVE_MORSE_INPUT
497 if (morse_mode)
498 {
499 morse_tick = current_tick;
500 if (!morse_reading)
501 {
502 morse_reading = true;
503 morse_code = 1;
504 }
505 break;
506 }
507#endif
508
395 /* inserts the selected char */ 509 /* inserts the selected char */
396#ifdef KBD_SELECT_PRE 510#ifdef KBD_SELECT_PRE
397 if (lastbutton != KBD_SELECT_PRE) 511 if (lastbutton != KBD_SELECT_PRE)
@@ -460,6 +574,38 @@ int kbd_input(char* text, int buflen)
460 case BUTTON_NONE: 574 case BUTTON_NONE:
461 gui_syncstatusbar_draw(&statusbars, false); 575 gui_syncstatusbar_draw(&statusbars, false);
462 redraw = false; 576 redraw = false;
577#ifdef HAVE_MORSE_INPUT
578 if (morse_reading)
579 {
580 logf("Morse: 0x%02x", morse_code);
581 morse_reading = false;
582
583 for (j = 0; morse_alphabets[j] != '\0'; j++)
584 {
585 if (morse_codes[j] == morse_code)
586 break ;
587 }
588
589 if (morse_alphabets[j] == '\0')
590 {
591 logf("Morse code not found");
592 break ;
593 }
594
595 if (len + 1 < buflen)
596 {
597 for (i = len ; i > editpos; i--)
598 text[i] = text[i-1];
599 text[len+1] = 0;
600 text[editpos] = morse_alphabets[j];
601 editpos++;
602 }
603 if (global_settings.talk_menu) /* voice UI? */
604 talk_spell(text, false); /* speak revised text */
605 redraw = true;
606 }
607#endif
608
463 break; 609 break;
464 610
465 default: 611 default: