2002-12-04 15:04:43 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>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>
|
|
|
|
|
#include "font.h"
|
2003-03-10 15:09:27 +00:00
|
|
|
|
#include "screens.h"
|
2003-11-04 12:36:55 +00:00
|
|
|
|
#include "status.h"
|
2004-05-21 06:29:55 +00:00
|
|
|
|
#include "talk.h"
|
|
|
|
|
#include "settings.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
|
|
|
|
#define KEYBOARD_LINES 4
|
|
|
|
|
#define KEYBOARD_PAGES 3
|
|
|
|
|
|
|
|
|
|
static void kbd_setupkeys(char* line[KEYBOARD_LINES], int page)
|
|
|
|
|
{
|
|
|
|
|
switch (page) {
|
|
|
|
|
case 0:
|
|
|
|
|
line[0] = "ABCDEFG !?\" @#$%+'";
|
|
|
|
|
line[1] = "HIJKLMN 789 &_()-`";
|
|
|
|
|
line[2] = "OPQRSTU 456 <20>|{}/<";
|
|
|
|
|
line[3] = "VWXYZ.,0123 ~=[]*>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
line[0] = "abcdefg <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
line[1] = "hijklmn <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2003-01-15 14:31:05 +00:00
|
|
|
|
line[2] = "opqrstu <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2003-03-10 15:09:27 +00:00
|
|
|
|
line[3] = "vwxyz., <20><><EFBFBD> ";
|
2002-12-04 15:04:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
line[0] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
|
|
|
|
line[1] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
|
|
|
|
line[2] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
|
|
|
|
line[3] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-17 02:10:09 +00:00
|
|
|
|
|
2004-05-21 06:29:55 +00:00
|
|
|
|
/* helper function to spell a char if voice UI is enabled */
|
|
|
|
|
void kbd_spellchar(char c)
|
|
|
|
|
{
|
|
|
|
|
char spell_char[2]; /* store char to pass to talk_spell */
|
|
|
|
|
|
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
{
|
|
|
|
|
spell_char[0] = c;
|
|
|
|
|
spell_char[1] = '\0'; /* mark end of char string */
|
|
|
|
|
|
|
|
|
|
talk_spell(spell_char, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int kbd_input(char* text, int buflen)
|
|
|
|
|
{
|
|
|
|
|
bool done = false;
|
|
|
|
|
int page = 0;
|
|
|
|
|
|
|
|
|
|
int font_w = 0, font_h = 0, i;
|
|
|
|
|
int x = 0, y = 0;
|
|
|
|
|
int main_x, main_y, max_chars, margin;
|
|
|
|
|
int status_y1, status_y2, curpos;
|
|
|
|
|
int len;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
int editpos;
|
2003-11-17 02:10:09 +00:00
|
|
|
|
bool redraw = true;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
char* line[KEYBOARD_LINES];
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-03-10 15:09:27 +00:00
|
|
|
|
char outline[256];
|
2002-12-04 15:04:43 +00:00
|
|
|
|
char c = 0;
|
|
|
|
|
struct font* font = font_get(FONT_SYSFIXED);
|
|
|
|
|
|
2003-01-15 13:48:54 +00:00
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
2002-12-04 15:04:43 +00:00
|
|
|
|
font_w = font->maxwidth;
|
|
|
|
|
font_h = font->height;
|
|
|
|
|
|
|
|
|
|
margin = 3;
|
2003-11-17 02:10:09 +00:00
|
|
|
|
main_y = (KEYBOARD_LINES + 1) * font_h + margin*2;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
main_x = 0;
|
|
|
|
|
status_y1 = LCD_HEIGHT - font_h;
|
|
|
|
|
status_y2 = LCD_HEIGHT;
|
|
|
|
|
|
2003-03-10 15:09:27 +00:00
|
|
|
|
editpos = strlen(text);
|
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
max_chars = LCD_WIDTH / font_w;
|
|
|
|
|
kbd_setupkeys(line, page);
|
|
|
|
|
|
2004-05-21 06:29:55 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, true); /* spell initial text */
|
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
while(!done)
|
|
|
|
|
{
|
|
|
|
|
len = strlen(text);
|
2003-11-17 02:10:09 +00:00
|
|
|
|
|
|
|
|
|
if(redraw)
|
2003-03-10 15:09:27 +00:00
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
|
|
/* draw page */
|
|
|
|
|
for (i=0; i < KEYBOARD_LINES; i++)
|
|
|
|
|
lcd_putsxy(0, 8+i * font_h, line[i]);
|
|
|
|
|
|
|
|
|
|
/* separator */
|
|
|
|
|
lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin);
|
|
|
|
|
|
|
|
|
|
/* write out the text */
|
|
|
|
|
if (editpos < max_chars - 3 )
|
2003-03-10 15:09:27 +00:00
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
strncpy(outline, text, max_chars - 2);
|
|
|
|
|
if (len > max_chars - 2)
|
|
|
|
|
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
|
|
|
|
curpos = (1 + editpos) * font_w;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* not room for all text, cut left, right or both */
|
|
|
|
|
if (editpos == len )
|
2003-03-10 15:09:27 +00:00
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
if ( max_chars - 3 == len)
|
|
|
|
|
{
|
|
|
|
|
strncpy(outline, text, max_chars - 2);
|
|
|
|
|
curpos = (1 + editpos) * font_w;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strncpy(outline, text + editpos - max_chars + 2,
|
|
|
|
|
max_chars - 2);
|
|
|
|
|
if (len > max_chars - 2)
|
|
|
|
|
lcd_putsxy(0, main_y, "<");
|
|
|
|
|
curpos = ( max_chars - 1) * font_w;
|
|
|
|
|
}
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-11-17 02:10:09 +00:00
|
|
|
|
if (len - 1 == editpos)
|
|
|
|
|
{
|
|
|
|
|
strncpy(outline, text + editpos - max_chars + 3,
|
|
|
|
|
max_chars - 2);
|
|
|
|
|
curpos = ( max_chars - 2) * font_w;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strncpy(outline, text + editpos - max_chars + 4,
|
|
|
|
|
max_chars - 2);
|
|
|
|
|
curpos = ( max_chars - 3) * font_w;
|
|
|
|
|
}
|
|
|
|
|
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
|
|
|
|
lcd_putsxy(0, main_y, "<");
|
2003-03-10 15:09:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* Zero terminate the string */
|
|
|
|
|
outline[max_chars - 2] = '\0';
|
|
|
|
|
|
|
|
|
|
lcd_putsxy(font_w,main_y,outline);
|
|
|
|
|
|
|
|
|
|
/* cursor */
|
|
|
|
|
lcd_drawline(curpos, main_y, curpos, main_y + font_h);
|
|
|
|
|
|
|
|
|
|
/* draw the status bar */
|
|
|
|
|
buttonbar_set("Shift", "OK", "Del");
|
|
|
|
|
buttonbar_draw();
|
|
|
|
|
|
|
|
|
|
/* highlight the key that has focus */
|
|
|
|
|
lcd_invertrect(font_w * x, 8 + font_h * y, font_w, font_h);
|
|
|
|
|
|
|
|
|
|
status_draw(true);
|
2003-03-17 23:16:20 +00:00
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
}
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-11-17 02:10:09 +00:00
|
|
|
|
/* The default action is to redraw */
|
|
|
|
|
redraw = true;
|
2003-11-04 13:17:29 +00:00
|
|
|
|
|
2003-11-04 12:36:55 +00:00
|
|
|
|
switch ( button_get_w_tmo(HZ/2) ) {
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-01-15 13:48:54 +00:00
|
|
|
|
case BUTTON_OFF:
|
|
|
|
|
/* abort */
|
|
|
|
|
lcd_setfont(FONT_UI);
|
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_F1:
|
|
|
|
|
/* Page */
|
|
|
|
|
if (++page == KEYBOARD_PAGES)
|
|
|
|
|
page = 0;
|
|
|
|
|
kbd_setupkeys(line, page);
|
2004-05-21 06:29:55 +00:00
|
|
|
|
kbd_spellchar(line[y][x]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
2003-03-10 15:09:27 +00:00
|
|
|
|
if (x < (int)strlen(line[y]) - 1)
|
|
|
|
|
x++;
|
|
|
|
|
else
|
2003-01-15 13:48:54 +00:00
|
|
|
|
x = 0;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
kbd_spellchar(line[y][x]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
|
if (x)
|
|
|
|
|
x--;
|
|
|
|
|
else
|
|
|
|
|
x = strlen(line[y]) - 1;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
kbd_spellchar(line[y][x]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
|
|
|
|
if (y < KEYBOARD_LINES - 1)
|
|
|
|
|
y++;
|
|
|
|
|
else
|
|
|
|
|
y=0;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
kbd_spellchar(line[y][x]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_UP:
|
|
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
|
|
|
|
if (y)
|
|
|
|
|
y--;
|
|
|
|
|
else
|
|
|
|
|
y = KEYBOARD_LINES - 1;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
kbd_spellchar(line[y][x]);
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_F3:
|
2003-01-18 17:47:50 +00:00
|
|
|
|
case BUTTON_F3 | BUTTON_REPEAT:
|
2003-01-15 13:48:54 +00:00
|
|
|
|
/* backspace */
|
2003-03-10 15:09:27 +00:00
|
|
|
|
if (editpos > 0)
|
|
|
|
|
{
|
|
|
|
|
for (i = editpos; i <= (len - 1);i++)
|
|
|
|
|
{
|
|
|
|
|
text[i-1] = text[i];
|
|
|
|
|
}
|
|
|
|
|
text[i-1]='\0';
|
|
|
|
|
editpos--;
|
|
|
|
|
if (editpos < 0)
|
|
|
|
|
editpos=0;
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-03-10 15:09:27 +00:00
|
|
|
|
case BUTTON_F2:
|
|
|
|
|
/* F2 accepts what was entered and continues */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
done = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
/* PLAY inserts the selected char */
|
|
|
|
|
if (len<buflen)
|
|
|
|
|
{
|
|
|
|
|
c = line[y][x];
|
2003-03-10 15:09:27 +00:00
|
|
|
|
if ( editpos == len )
|
|
|
|
|
{
|
|
|
|
|
text[len] = c;
|
|
|
|
|
text[len+1] = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (i = len ; i + 1 > editpos; i--)
|
|
|
|
|
text[i+1] = text[i];
|
|
|
|
|
text[editpos] = c;
|
|
|
|
|
}
|
|
|
|
|
editpos++;
|
2003-01-15 13:48:54 +00:00
|
|
|
|
}
|
2004-05-21 06:29:55 +00:00
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-03-10 15:09:27 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_ON | BUTTON_RIGHT:
|
|
|
|
|
case BUTTON_ON | BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
|
/* moved cursor right */
|
|
|
|
|
editpos++;
|
|
|
|
|
if (editpos > len)
|
|
|
|
|
editpos = len;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
else
|
|
|
|
|
kbd_spellchar(text[editpos]);
|
2003-03-10 15:09:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUTTON_ON | BUTTON_LEFT:
|
|
|
|
|
case BUTTON_ON | BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
|
/* moved cursor left */
|
|
|
|
|
editpos--;
|
|
|
|
|
if (editpos < 0)
|
|
|
|
|
editpos = 0;
|
2004-05-21 06:29:55 +00:00
|
|
|
|
else
|
|
|
|
|
kbd_spellchar(text[editpos]);
|
2003-03-10 15:09:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
|
usb_screen();
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
break;
|
2003-11-04 12:36:55 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_NONE:
|
|
|
|
|
status_draw(false);
|
2003-11-17 02:10:09 +00:00
|
|
|
|
redraw = false;
|
2003-11-04 12:36:55 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
lcd_setfont(FONT_UI);
|
2002-12-04 15:04:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|