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"
|
2005-02-06 23:23:49 +00:00
|
|
|
|
#include "system.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "debug_menu.h"
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
|
#include <string.h>
|
2003-01-20 12:25:28 +00:00
|
|
|
|
#include "lcd-player-charset.h"
|
2005-02-06 23:23:49 +00:00
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "status.h"
|
|
|
|
|
#include "talk.h"
|
|
|
|
|
#include "misc.h"
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-01-20 12:25:28 +00:00
|
|
|
|
#define KEYBOARD_PAGES 3
|
|
|
|
|
|
2003-12-12 13:34:27 +00:00
|
|
|
|
extern unsigned short *lcd_ascii;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
|
|
|
|
static unsigned short* kbd_setupkeys(int page, int* len)
|
2002-12-04 15:04:43 +00:00
|
|
|
|
{
|
2003-01-21 14:26:56 +00:00
|
|
|
|
static unsigned short lines[128];
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
|
|
|
|
unsigned short ch;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
switch (page)
|
|
|
|
|
{
|
|
|
|
|
case 0: /* Capitals */
|
|
|
|
|
for (ch = 'A'; ch <= 'Z'; ch++)
|
2003-01-20 12:25:28 +00:00
|
|
|
|
lines[i++] = ch;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
for (ch = 0xc0; ch <= 0xdd; ch++)
|
|
|
|
|
if (lcd_ascii[ch] != NOCHAR_NEW && lcd_ascii[ch] != NOCHAR_OLD)
|
|
|
|
|
lines[i++] = ch;
|
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case 1: /* Small */
|
|
|
|
|
for (ch = 'a'; ch <= 'z'; ch++)
|
2003-01-20 12:25:28 +00:00
|
|
|
|
lines[i++] = ch;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
for (ch = 0xdf; ch <= 0xff; ch++)
|
|
|
|
|
if (lcd_ascii[ch] != NOCHAR_NEW && lcd_ascii[ch] != NOCHAR_OLD)
|
|
|
|
|
lines[i++] = ch;
|
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case 2: /* Others */
|
|
|
|
|
for (ch = ' '; ch <= '@'; ch++)
|
|
|
|
|
lines[i++] = ch;
|
|
|
|
|
break;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines[i] = 0;
|
|
|
|
|
*len = i;
|
|
|
|
|
|
|
|
|
|
return lines;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
/* Delimiters for highlighting the character selected for insertion */
|
|
|
|
|
#define KEYBOARD_INSERT_LEFT 0x81
|
|
|
|
|
#define KEYBOARD_INSERT_RIGHT 0x82
|
|
|
|
|
|
|
|
|
|
#define KEYBOARD_CURSOR 0x7f
|
|
|
|
|
#define KEYBOARD_ARROW 0x92
|
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
/* helper function to spell a char if voice UI is enabled */
|
|
|
|
|
static void kbd_spellchar(char c)
|
|
|
|
|
{
|
|
|
|
|
static char spell_char[2] = "\0\0"; /* store char to pass to talk_spell */
|
|
|
|
|
|
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
{
|
|
|
|
|
spell_char[0] = c;
|
|
|
|
|
talk_spell(spell_char, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int kbd_input(char* text, int buflen)
|
|
|
|
|
{
|
|
|
|
|
bool done = false;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
bool redraw = true;
|
|
|
|
|
bool line_edit = false;
|
|
|
|
|
int page = 0, x = 0;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
int linelen;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
int len, i;
|
|
|
|
|
int editpos, curpos, leftpos;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
unsigned short* line = kbd_setupkeys(page, &linelen);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
unsigned char temptext[12];
|
2005-02-06 23:23:49 +00:00
|
|
|
|
char c;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
int button, lastbutton = 0;
|
|
|
|
|
|
|
|
|
|
editpos = strlen(text);
|
|
|
|
|
|
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, true); /* spell initial text */
|
|
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
|
{
|
|
|
|
|
len = strlen(text);
|
|
|
|
|
|
|
|
|
|
if (redraw)
|
|
|
|
|
{
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
|
|
|
|
lcd_putc(0, 0, ' ');
|
|
|
|
|
lcd_putc(0, 1, KEYBOARD_ARROW);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lcd_putc(0, 0, KEYBOARD_ARROW);
|
|
|
|
|
lcd_putc(0, 1, ' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw insert chars */
|
|
|
|
|
temptext[0] = KEYBOARD_INSERT_LEFT;
|
|
|
|
|
temptext[1] = line[x%linelen];
|
|
|
|
|
temptext[2] = KEYBOARD_INSERT_RIGHT;
|
|
|
|
|
for (i = 1; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
temptext[i+2] = line[(i+x)%linelen];
|
|
|
|
|
}
|
|
|
|
|
temptext[i+2] = 0;
|
|
|
|
|
lcd_puts(1, 0, temptext);
|
|
|
|
|
|
|
|
|
|
/* write out the text */
|
2005-02-08 08:24:36 +00:00
|
|
|
|
curpos = MIN(MIN(editpos, 10 - MIN(len - editpos, 3)), 9);
|
2005-02-06 23:23:49 +00:00
|
|
|
|
leftpos = editpos - curpos;
|
|
|
|
|
strncpy(temptext, text + leftpos, 10);
|
|
|
|
|
temptext[10] = 0;
|
|
|
|
|
|
|
|
|
|
if (leftpos)
|
|
|
|
|
temptext[0] = '<';
|
|
|
|
|
if (len - leftpos > 10)
|
|
|
|
|
temptext[9] = '>';
|
|
|
|
|
|
|
|
|
|
lcd_remove_cursor();
|
|
|
|
|
lcd_puts(1, 1, temptext);
|
|
|
|
|
lcd_put_cursor(curpos + 1, 1, KEYBOARD_CURSOR);
|
|
|
|
|
|
|
|
|
|
status_draw(true);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
/* The default action is to redraw */
|
|
|
|
|
redraw = true;
|
|
|
|
|
|
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
|
|
|
|
switch (button)
|
|
|
|
|
{
|
|
|
|
|
case BUTTON_STOP: /* abort */
|
|
|
|
|
return -1;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_MENU: /* page flip */
|
|
|
|
|
if (++page == KEYBOARD_PAGES)
|
|
|
|
|
page = 0;
|
|
|
|
|
line = kbd_setupkeys(page, &linelen);
|
|
|
|
|
if (x > linelen - 1)
|
|
|
|
|
x = linelen - 1;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_ON: /* toggle mode */
|
|
|
|
|
line_edit = !line_edit;
|
|
|
|
|
if (!line_edit)
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
|
if (line_edit)
|
2003-01-24 14:51:22 +00:00
|
|
|
|
{
|
2005-02-06 23:23:49 +00:00
|
|
|
|
if (editpos < len)
|
|
|
|
|
{
|
|
|
|
|
editpos++;
|
|
|
|
|
kbd_spellchar(text[editpos]);
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else
|
2003-01-24 14:51:22 +00:00
|
|
|
|
{
|
2005-02-06 23:23:49 +00:00
|
|
|
|
if (x < linelen - 1)
|
|
|
|
|
x++;
|
|
|
|
|
else
|
|
|
|
|
x = 0;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
|
if (line_edit)
|
|
|
|
|
{
|
|
|
|
|
if (editpos)
|
|
|
|
|
{
|
|
|
|
|
editpos--;
|
|
|
|
|
kbd_spellchar(text[editpos]);
|
|
|
|
|
}
|
2003-01-27 14:37:03 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (x)
|
|
|
|
|
x--;
|
|
|
|
|
else
|
|
|
|
|
x = linelen - 1;
|
|
|
|
|
kbd_spellchar(line[x]);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
/* accepts what was entered and continues */
|
|
|
|
|
done = true;
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
case BUTTON_PLAY | BUTTON_REL:
|
|
|
|
|
if (lastbutton != BUTTON_PLAY)
|
|
|
|
|
break;
|
|
|
|
|
if (line_edit) /* backspace in line_edit */
|
|
|
|
|
{
|
|
|
|
|
if (editpos > 0)
|
|
|
|
|
{
|
|
|
|
|
for (i = editpos; i < len; i++)
|
|
|
|
|
text[i-1] = text[i];
|
|
|
|
|
text[i-1] = '\0';
|
|
|
|
|
editpos--;
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
else /* inserts the selected char */
|
|
|
|
|
{
|
|
|
|
|
if (len < buflen)
|
|
|
|
|
{
|
|
|
|
|
c = line[x];
|
|
|
|
|
if (editpos == len)
|
|
|
|
|
{
|
|
|
|
|
text[len] = c;
|
|
|
|
|
text[len+1] = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (i = len ; i >= editpos; i--)
|
|
|
|
|
text[i+1] = text[i];
|
|
|
|
|
text[editpos] = c;
|
|
|
|
|
}
|
|
|
|
|
editpos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (global_settings.talk_menu) /* voice UI? */
|
|
|
|
|
talk_spell(text, false); /* speak revised text */
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_NONE:
|
2005-02-06 23:23:49 +00:00
|
|
|
|
status_draw(false);
|
|
|
|
|
redraw = false;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2005-02-06 23:23:49 +00:00
|
|
|
|
default:
|
|
|
|
|
default_event_handler(button);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
|
lastbutton = button;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2005-02-06 23:23:49 +00:00
|
|
|
|
|