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>
|
2003-01-20 12:25:28 +00:00
|
|
|
|
#include "lcd-player-charset.h"
|
2003-01-31 07:26:56 +00:00
|
|
|
|
#include "lang.h"
|
2003-01-20 12:25:28 +00:00
|
|
|
|
#include "debug.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;
|
|
|
|
|
|
|
|
|
|
switch (page) {
|
|
|
|
|
case 0: /* Capitals */
|
2003-01-21 14:26:56 +00:00
|
|
|
|
for (ch = 'A'; ch <= 'Z'; ch++)
|
|
|
|
|
lines[i++] = ch;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
for (ch = 0xc0; ch <= 0xdd; ch++)
|
|
|
|
|
if (lcd_ascii[ch] != NOCHAR_NEW && lcd_ascii[ch] != NOCHAR_OLD)
|
|
|
|
|
lines[i++] = ch;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1: /* Small */
|
2003-01-21 14:26:56 +00:00
|
|
|
|
for (ch = 'a'; ch <= 'z'; ch++)
|
|
|
|
|
lines[i++] = ch;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
for (ch = 0xdf; ch <= 0xff; ch++)
|
|
|
|
|
if (lcd_ascii[ch] != NOCHAR_NEW && lcd_ascii[ch] != NOCHAR_OLD)
|
|
|
|
|
lines[i++] = ch;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2: /* Others */
|
2003-01-21 14:26:56 +00:00
|
|
|
|
for (ch = ' '; ch <= '@'; ch++)
|
|
|
|
|
lines[i++] = ch;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#define MENU_LINE_INPUT 0
|
|
|
|
|
#define MENU_LINE_NEWCHARS 1
|
2003-01-27 14:37:03 +00:00
|
|
|
|
#define MENU_LINE_BACKSPACE 2
|
|
|
|
|
#define MENU_LINE_DELETE 3
|
|
|
|
|
#define MENU_LINE_ACCEPT 4
|
|
|
|
|
#define MENU_LINE_QUIT 5
|
|
|
|
|
#define MENU_LINE_LAST 5
|
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;
|
|
|
|
|
int page=0, x=0;
|
2003-01-20 12:25:28 +00:00
|
|
|
|
int linelen;
|
|
|
|
|
unsigned short* line = kbd_setupkeys(page, &linelen);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
int menu_line=0;
|
|
|
|
|
int cursor_pos=0;
|
|
|
|
|
int button_pressed;
|
|
|
|
|
unsigned char temptext[12];
|
2003-01-26 00:33:06 +00:00
|
|
|
|
int old_cursor_pos=0; /* Windowed cursor movement */
|
|
|
|
|
int left_pos=0;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
2003-03-11 15:05:04 +00:00
|
|
|
|
old_cursor_pos=cursor_pos=strlen(text);
|
|
|
|
|
if (9<cursor_pos)
|
|
|
|
|
left_pos=cursor_pos-9;
|
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
while (!done) {
|
2003-01-21 14:26:56 +00:00
|
|
|
|
int i, p;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
int len = strlen(text);
|
2004-07-09 13:11:16 +00:00
|
|
|
|
int scrpos;
|
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
|
|
scrpos = cursor_pos - left_pos;
|
|
|
|
|
dir = cursor_pos - old_cursor_pos;
|
|
|
|
|
|
|
|
|
|
/* Keep the cursor on screen, with a 2 character scroll margin */
|
|
|
|
|
if(dir < 0) {
|
|
|
|
|
if(scrpos < 2) {
|
|
|
|
|
left_pos = cursor_pos - 2;
|
|
|
|
|
if(left_pos < 0)
|
|
|
|
|
left_pos = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(dir > 0) {
|
|
|
|
|
if(scrpos > 7) {
|
|
|
|
|
left_pos = cursor_pos - 9;
|
|
|
|
|
if(left_pos < 0)
|
|
|
|
|
left_pos = 0;
|
|
|
|
|
if(left_pos > len - 9)
|
|
|
|
|
left_pos = len - 9;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-01-21 14:26:56 +00:00
|
|
|
|
p=0;
|
2003-01-26 00:33:06 +00:00
|
|
|
|
i = left_pos;
|
2003-03-11 15:05:04 +00:00
|
|
|
|
while (p<10 && text[i]) {
|
|
|
|
|
temptext[p++]=text[i++];
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
|
|
|
|
temptext[p]=0;
|
2003-01-29 11:49:13 +00:00
|
|
|
|
lcd_remove_cursor();
|
2003-01-21 14:26:56 +00:00
|
|
|
|
lcd_puts(1, 0, temptext);
|
2003-01-27 14:37:03 +00:00
|
|
|
|
lcd_put_cursor(cursor_pos-left_pos+1, 0, 0x7f);
|
2003-01-26 00:33:06 +00:00
|
|
|
|
old_cursor_pos=cursor_pos;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
|
|
|
|
switch (menu_line) {
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case MENU_LINE_INPUT:
|
|
|
|
|
case MENU_LINE_NEWCHARS:
|
|
|
|
|
/* 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];
|
|
|
|
|
}
|
2003-03-11 15:05:04 +00:00
|
|
|
|
temptext[i+2]=0;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
lcd_puts(1, 1, temptext);
|
|
|
|
|
break;
|
2003-01-27 14:37:03 +00:00
|
|
|
|
case MENU_LINE_BACKSPACE:
|
2003-01-31 07:26:56 +00:00
|
|
|
|
lcd_puts_scroll(1, 1, str(LANG_PLAYER_KEYBOARD_BACKSPACE));
|
2003-01-27 14:37:03 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case MENU_LINE_DELETE:
|
2003-01-31 07:26:56 +00:00
|
|
|
|
lcd_puts_scroll(1, 1, str(LANG_PLAYER_KEYBOARD_DELETE));
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
|
|
|
|
case MENU_LINE_ACCEPT:
|
2003-01-31 07:26:56 +00:00
|
|
|
|
lcd_puts_scroll(1, 1, str(LANG_PLAYER_KEYBOARD_ACCEPT));
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
|
|
|
|
case MENU_LINE_QUIT:
|
2003-01-31 07:26:56 +00:00
|
|
|
|
lcd_puts_scroll(1, 1, str(LANG_PLAYER_KEYBOARD_ABORT));
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
if (menu_line==MENU_LINE_INPUT) {
|
|
|
|
|
lcd_putc(0, 0, KEYBOARD_ARROW);
|
2003-01-21 14:26:56 +00:00
|
|
|
|
lcd_putc(0, 1, ' ');
|
|
|
|
|
} else {
|
|
|
|
|
lcd_putc(0, 0, ' ');
|
2003-01-24 14:51:22 +00:00
|
|
|
|
lcd_putc(0, 1, KEYBOARD_ARROW);
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
|
2003-01-27 14:37:03 +00:00
|
|
|
|
button_pressed=button_get(true);
|
2003-01-24 14:51:22 +00:00
|
|
|
|
switch (menu_line)
|
|
|
|
|
{
|
|
|
|
|
case MENU_LINE_INPUT:
|
|
|
|
|
switch (button_pressed)
|
|
|
|
|
{
|
2004-09-19 21:58:37 +00:00
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
2003-01-24 14:51:22 +00:00
|
|
|
|
if (cursor_pos<len)
|
|
|
|
|
cursor_pos++;
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
|
|
|
|
|
case BUTTON_STOP:
|
|
|
|
|
case BUTTON_STOP | BUTTON_REPEAT:
|
2003-01-24 14:51:22 +00:00
|
|
|
|
if (cursor_pos>0)
|
|
|
|
|
cursor_pos--;
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-01-21 14:26:56 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
|
|
|
|
case MENU_LINE_NEWCHARS:
|
|
|
|
|
switch (button_pressed)
|
|
|
|
|
{
|
2004-09-19 21:58:37 +00:00
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
2003-01-24 14:51:22 +00:00
|
|
|
|
x=(x+1+linelen)%linelen;
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
case BUTTON_STOP:
|
|
|
|
|
case BUTTON_STOP | BUTTON_REPEAT:
|
2003-01-24 14:51:22 +00:00
|
|
|
|
x=(x-1+linelen)%linelen;
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_MENU:
|
|
|
|
|
/* shift */
|
|
|
|
|
if (++page == KEYBOARD_PAGES)
|
|
|
|
|
page = 0;
|
|
|
|
|
line = kbd_setupkeys(page, &linelen);
|
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_ON:
|
|
|
|
|
if (len < buflen) {
|
|
|
|
|
/* ON insert the char */
|
2003-06-02 12:07:11 +00:00
|
|
|
|
for (i=len+1; i>cursor_pos; i--) {
|
2003-01-24 14:51:22 +00:00
|
|
|
|
text[i]=text[i-1];
|
|
|
|
|
}
|
|
|
|
|
text[cursor_pos]=line[x];
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
cursor_pos++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
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
|
|
|
|
|
2003-01-27 14:37:03 +00:00
|
|
|
|
case MENU_LINE_BACKSPACE:
|
|
|
|
|
switch (button_pressed) {
|
|
|
|
|
case BUTTON_ON:
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
if (0 < cursor_pos) {
|
|
|
|
|
for (i=--cursor_pos; i<=len; i++) {
|
|
|
|
|
text[i]=text[i+1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BUTTON_STOP:
|
|
|
|
|
case BUTTON_STOP | BUTTON_REPEAT:
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
for (i=cursor_pos; i<=len; i++) {
|
|
|
|
|
text[i]=text[i+1];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case MENU_LINE_DELETE:
|
|
|
|
|
switch (button_pressed) {
|
|
|
|
|
case BUTTON_ON:
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
for (i=cursor_pos; i<=len; i++) {
|
|
|
|
|
text[i]=text[i+1];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BUTTON_STOP:
|
|
|
|
|
case BUTTON_STOP | BUTTON_REPEAT:
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
if (0 < cursor_pos)
|
|
|
|
|
for (i=--cursor_pos; i<=len; i++) {
|
|
|
|
|
text[i]=text[i+1];
|
|
|
|
|
}
|
|
|
|
|
break;
|
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
|
|
|
|
|
|
|
|
|
case MENU_LINE_ACCEPT:
|
|
|
|
|
switch (button_pressed) {
|
|
|
|
|
case BUTTON_ON:
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
button_pressed=BUTTON_NONE;
|
|
|
|
|
done=true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
|
|
|
|
case MENU_LINE_QUIT:
|
|
|
|
|
switch (button_pressed) {
|
|
|
|
|
case BUTTON_ON:
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
case BUTTON_PLAY | BUTTON_REPEAT:
|
|
|
|
|
return 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-01-15 13:48:54 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handle unhandled events */
|
2003-01-24 14:51:22 +00:00
|
|
|
|
switch (button_pressed) {
|
|
|
|
|
case BUTTON_NONE:
|
|
|
|
|
/* button is already handled */
|
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_MENU | BUTTON_STOP:
|
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
|
if (menu_line<MENU_LINE_LAST)
|
|
|
|
|
menu_line++;
|
2003-01-27 14:37:03 +00:00
|
|
|
|
else
|
|
|
|
|
menu_line=0;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2003-01-21 14:26:56 +00:00
|
|
|
|
|
2003-01-24 14:51:22 +00:00
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
|
if (menu_line>0)
|
|
|
|
|
menu_line--;
|
2003-01-27 14:37:03 +00:00
|
|
|
|
else
|
|
|
|
|
menu_line=MENU_LINE_LAST;
|
2003-01-24 14:51:22 +00:00
|
|
|
|
break;
|
2002-12-04 15:04:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-24 14:51:22 +00:00
|
|
|
|
|
2002-12-04 15:04:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|