2002-04-19 14:12:31 +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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2005-03-18 23:51:52 +00:00
|
|
|
|
#include <stdlib.h>
|
2004-09-16 14:36:08 +00:00
|
|
|
|
#include "config.h"
|
2002-04-19 14:12:31 +00:00
|
|
|
|
#include "button.h"
|
2002-05-28 15:05:16 +00:00
|
|
|
|
#include "kernel.h"
|
2003-04-23 18:49:57 +00:00
|
|
|
|
#include "debug.h"
|
2004-06-30 13:31:14 +00:00
|
|
|
|
#include "misc.h"
|
2002-04-19 14:12:31 +00:00
|
|
|
|
|
|
|
|
|
#include "X11/keysym.h"
|
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
extern int screenhack_handle_events(bool *release);
|
|
|
|
|
|
|
|
|
|
struct event_queue button_queue;
|
|
|
|
|
|
|
|
|
|
static int button_state = 0; /* keeps track of pressed keys */
|
|
|
|
|
static long lastbtn; /* Last valid button status */
|
|
|
|
|
|
|
|
|
|
/* how often we check to see if a button is pressed */
|
|
|
|
|
#define POLL_FREQUENCY HZ/25
|
|
|
|
|
|
|
|
|
|
/* how long until repeat kicks in */
|
|
|
|
|
#define REPEAT_START 8
|
|
|
|
|
|
|
|
|
|
/* the speed repeat starts at */
|
|
|
|
|
#define REPEAT_INTERVAL_START 4
|
|
|
|
|
|
|
|
|
|
/* speed repeat finishes at */
|
|
|
|
|
#define REPEAT_INTERVAL_FINISH 2
|
|
|
|
|
|
|
|
|
|
/* mostly copied from real button.c */
|
|
|
|
|
void button_read (void);
|
|
|
|
|
|
|
|
|
|
void button_tick(void)
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
2005-03-18 23:51:52 +00:00
|
|
|
|
static int tick = 0;
|
|
|
|
|
static int count = 0;
|
|
|
|
|
static int repeat_speed = REPEAT_INTERVAL_START;
|
|
|
|
|
static int repeat_count = 0;
|
|
|
|
|
static bool repeat = false;
|
|
|
|
|
int diff;
|
|
|
|
|
int btn;
|
|
|
|
|
|
|
|
|
|
/* only poll every X ticks */
|
|
|
|
|
if ( ++tick >= POLL_FREQUENCY )
|
|
|
|
|
{
|
|
|
|
|
bool post = false;
|
|
|
|
|
button_read();
|
|
|
|
|
btn = button_state;
|
|
|
|
|
|
|
|
|
|
/* Find out if a key has been released */
|
|
|
|
|
diff = btn ^ lastbtn;
|
|
|
|
|
if(diff && (btn & diff) == 0)
|
|
|
|
|
{
|
|
|
|
|
queue_post(&button_queue, BUTTON_REL | diff, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( btn )
|
|
|
|
|
{
|
|
|
|
|
/* normal keypress */
|
|
|
|
|
if ( btn != lastbtn )
|
|
|
|
|
{
|
|
|
|
|
post = true;
|
|
|
|
|
repeat = false;
|
|
|
|
|
repeat_speed = REPEAT_INTERVAL_START;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else /* repeat? */
|
|
|
|
|
{
|
|
|
|
|
if ( repeat )
|
|
|
|
|
{
|
|
|
|
|
count--;
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
post = true;
|
|
|
|
|
/* yes we have repeat */
|
|
|
|
|
repeat_speed--;
|
|
|
|
|
if (repeat_speed < REPEAT_INTERVAL_FINISH)
|
|
|
|
|
repeat_speed = REPEAT_INTERVAL_FINISH;
|
|
|
|
|
count = repeat_speed;
|
|
|
|
|
|
|
|
|
|
repeat_count++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (count++ > REPEAT_START)
|
|
|
|
|
{
|
|
|
|
|
post = true;
|
|
|
|
|
repeat = true;
|
|
|
|
|
repeat_count = 0;
|
|
|
|
|
/* initial repeat */
|
|
|
|
|
count = REPEAT_INTERVAL_START;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( post )
|
|
|
|
|
{
|
|
|
|
|
if (repeat)
|
|
|
|
|
queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
|
|
|
|
|
else
|
|
|
|
|
queue_post(&button_queue, btn, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
repeat = false;
|
|
|
|
|
count = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
|
|
|
|
|
tick = 0;
|
|
|
|
|
}
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2005-03-18 23:51:52 +00:00
|
|
|
|
* Read X keys and translate to rockbox buttons
|
2002-04-19 14:12:31 +00:00
|
|
|
|
*/
|
2002-06-14 11:00:13 +00:00
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
void button_read (void)
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
2002-08-21 14:13:53 +00:00
|
|
|
|
int k;
|
2005-03-18 23:51:52 +00:00
|
|
|
|
bool release = false; /* is this a release event */
|
|
|
|
|
int ev = screenhack_handle_events(&release);
|
|
|
|
|
|
|
|
|
|
switch (ev)
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Left:
|
|
|
|
|
case XK_Left:
|
|
|
|
|
case XK_KP_4:
|
|
|
|
|
k = BUTTON_LEFT;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Right:
|
|
|
|
|
case XK_Right:
|
|
|
|
|
case XK_KP_6:
|
|
|
|
|
k = BUTTON_RIGHT;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Up:
|
|
|
|
|
case XK_Up:
|
|
|
|
|
case XK_KP_8:
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#ifdef BUTTON_UP
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_UP;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#elif defined BUTTON_PLAY
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_PLAY;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Down:
|
|
|
|
|
case XK_Down:
|
|
|
|
|
case XK_KP_2:
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#ifdef BUTTON_DOWN
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_DOWN;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#elif defined BUTTON_STOP
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_STOP;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#ifdef BUTTON_ON
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Add:
|
|
|
|
|
case XK_Q:
|
|
|
|
|
case XK_q:
|
|
|
|
|
k = BUTTON_ON;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#ifdef BUTTON_OFF
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Enter:
|
|
|
|
|
case XK_A:
|
|
|
|
|
case XK_a:
|
|
|
|
|
k = BUTTON_OFF;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#ifdef BUTTON_F1
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Divide:
|
|
|
|
|
case XK_1:
|
|
|
|
|
k = BUTTON_F1;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Multiply:
|
|
|
|
|
case XK_2:
|
|
|
|
|
k = BUTTON_F2;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Subtract:
|
|
|
|
|
case XK_3:
|
|
|
|
|
k = BUTTON_F3;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#elif defined(BUTTON_REC)
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Divide:
|
|
|
|
|
case XK_1:
|
|
|
|
|
k = BUTTON_REC;
|
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2004-06-30 13:31:14 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Space:
|
|
|
|
|
case XK_KP_5:
|
|
|
|
|
case XK_KP_Begin:
|
|
|
|
|
case XK_space:
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#ifdef BUTTON_PLAY
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_PLAY;
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#elif defined(BUTTON_SELECT)
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_SELECT;
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#endif
|
2004-06-30 13:31:14 +00:00
|
|
|
|
break;
|
2005-01-17 21:14:34 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_5:
|
|
|
|
|
if(!release)
|
|
|
|
|
screen_dump();
|
|
|
|
|
break;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2004-06-30 13:31:14 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
case XK_KP_Separator:
|
|
|
|
|
case XK_KP_Insert:
|
|
|
|
|
case XK_Insert:
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#ifdef BUTTON_MENU
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_MENU;
|
2005-01-17 21:14:34 +00:00
|
|
|
|
#elif defined(BUTTON_MODE)
|
2005-03-18 00:03:22 +00:00
|
|
|
|
k = BUTTON_MODE;
|
2004-09-19 21:58:37 +00:00
|
|
|
|
#endif
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2005-03-18 00:03:22 +00:00
|
|
|
|
default:
|
|
|
|
|
k = 0;
|
2003-04-23 18:49:57 +00:00
|
|
|
|
if(ev)
|
|
|
|
|
DEBUGF("received ev %d\n", ev);
|
2002-08-21 14:13:53 +00:00
|
|
|
|
break;
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
2002-08-21 14:13:53 +00:00
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
if (release)
|
2004-07-23 21:38:43 +00:00
|
|
|
|
button_state &= ~k;
|
2005-03-18 23:51:52 +00:00
|
|
|
|
else
|
|
|
|
|
button_state |= k;
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
/* Again copied from real button.c... */
|
|
|
|
|
|
|
|
|
|
long button_get(bool block)
|
2002-08-07 08:43:55 +00:00
|
|
|
|
{
|
2005-03-18 23:51:52 +00:00
|
|
|
|
struct event ev;
|
2002-08-07 08:43:55 +00:00
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
if ( block || !queue_empty(&button_queue) )
|
|
|
|
|
{
|
|
|
|
|
queue_wait(&button_queue, &ev);
|
|
|
|
|
return ev.id;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
}
|
2005-03-18 23:51:52 +00:00
|
|
|
|
return BUTTON_NONE;
|
2002-08-07 08:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
long button_get_w_tmo(int ticks)
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
2005-03-18 23:51:52 +00:00
|
|
|
|
struct event ev;
|
|
|
|
|
queue_wait_w_tmo(&button_queue, &ev, ticks);
|
|
|
|
|
return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE;
|
|
|
|
|
}
|
2002-10-13 14:16:44 +00:00
|
|
|
|
|
2005-03-18 23:51:52 +00:00
|
|
|
|
void button_init(void)
|
|
|
|
|
{
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
2004-07-21 08:02:23 +00:00
|
|
|
|
|
|
|
|
|
int button_status(void)
|
|
|
|
|
{
|
2005-03-18 23:51:52 +00:00
|
|
|
|
return lastbtn;
|
2004-07-21 08:02:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void button_clear_queue(void)
|
|
|
|
|
{
|
2005-03-18 23:51:52 +00:00
|
|
|
|
queue_clear(&button_queue);
|
2004-07-21 08:02:23 +00:00
|
|
|
|
}
|
2005-03-03 15:55:11 +00:00
|
|
|
|
|
|
|
|
|
#if CONFIG_KEYPAD == IRIVER_H100_PAD
|
|
|
|
|
bool button_hold(void) {
|
|
|
|
|
/* temp fix for hold button on irivers */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|