2006-02-03 15:19:58 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Felix Arends
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-02-03 15:19:58 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-15 21:02:47 +00:00
|
|
|
#include <math.h>
|
2010-05-16 09:51:46 +00:00
|
|
|
#include <stdlib.h> /* EXIT_SUCCESS */
|
2010-05-15 21:02:47 +00:00
|
|
|
#include "sim-ui-defines.h"
|
2007-03-31 09:58:49 +00:00
|
|
|
#include "lcd-charcells.h"
|
2006-08-15 08:33:38 +00:00
|
|
|
#include "lcd-remote.h"
|
2006-02-03 15:19:58 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "misc.h"
|
2009-09-23 16:59:56 +00:00
|
|
|
#include "button-sdl.h"
|
2010-01-19 22:07:28 +00:00
|
|
|
#include "backlight.h"
|
2010-06-06 09:11:52 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
#include "sim_tasks.h"
|
|
|
|
#include "buttonmap.h"
|
|
|
|
#endif
|
2006-08-15 08:33:38 +00:00
|
|
|
#include "debug.h"
|
2007-07-22 21:17:19 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2009-03-09 23:32:37 +00:00
|
|
|
#include "touchscreen.h"
|
2007-11-03 11:58:31 +00:00
|
|
|
static int mouse_coords = 0;
|
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
/* how long until repeat kicks in */
|
|
|
|
#define REPEAT_START 6
|
|
|
|
|
|
|
|
/* the speed repeat starts at */
|
|
|
|
#define REPEAT_INTERVAL_START 4
|
|
|
|
|
|
|
|
/* speed repeat finishes at */
|
|
|
|
#define REPEAT_INTERVAL_FINISH 2
|
|
|
|
|
2010-01-16 21:41:57 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
#define USB_KEY SDLK_c /* SDLK_u is taken by BUTTON_MIDLEFT */
|
|
|
|
#else
|
|
|
|
#define USB_KEY SDLK_u
|
|
|
|
#endif
|
|
|
|
|
2006-08-15 08:33:38 +00:00
|
|
|
#if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
|
|
|
|
int _remote_type=REMOTETYPE_H100_LCD;
|
|
|
|
|
|
|
|
int remote_type(void)
|
|
|
|
{
|
|
|
|
return _remote_type;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
struct event_queue button_queue;
|
|
|
|
|
|
|
|
static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
|
|
|
|
|
2007-03-05 14:48:31 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
bool hold_button_state = false;
|
|
|
|
bool button_hold(void) {
|
|
|
|
return hold_button_state;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAS_REMOTE_BUTTON_HOLD
|
|
|
|
bool remote_hold_button_state = false;
|
|
|
|
bool remote_button_hold(void) {
|
|
|
|
return remote_hold_button_state;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-15 21:02:47 +00:00
|
|
|
static void button_event(int key, bool pressed);
|
|
|
|
extern bool debug_wps;
|
|
|
|
extern bool mapping;
|
2010-05-17 17:19:31 +00:00
|
|
|
|
2010-05-27 18:46:09 +00:00
|
|
|
bool gui_message_loop(void)
|
2010-05-15 21:02:47 +00:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
static int x,y,xybutton = 0;
|
|
|
|
|
2010-05-17 17:19:31 +00:00
|
|
|
while (SDL_WaitEvent(&event))
|
2010-05-15 21:02:47 +00:00
|
|
|
{
|
2010-05-17 17:19:31 +00:00
|
|
|
sim_enter_irq_handler();
|
2010-05-15 21:02:47 +00:00
|
|
|
switch(event.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
2010-05-17 17:19:31 +00:00
|
|
|
button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN);
|
|
|
|
break;
|
2010-05-15 21:02:47 +00:00
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
switch ( event.button.button ) {
|
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
|
|
|
case SDL_BUTTON_WHEELUP:
|
|
|
|
button_event( SDLK_UP, true );
|
|
|
|
break;
|
|
|
|
case SDL_BUTTON_WHEELDOWN:
|
|
|
|
button_event( SDLK_DOWN, true );
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case SDL_BUTTON_LEFT:
|
|
|
|
case SDL_BUTTON_MIDDLE:
|
|
|
|
if ( mapping && background ) {
|
|
|
|
x = event.button.x;
|
|
|
|
y = event.button.y;
|
|
|
|
}
|
|
|
|
if ( background ) {
|
|
|
|
xybutton = xy2button( event.button.x, event.button.y );
|
|
|
|
if( xybutton )
|
|
|
|
button_event( xybutton, true );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug_wps && event.button.button == 1)
|
|
|
|
{
|
|
|
|
if ( background )
|
|
|
|
#ifdef HAVE_REMOTE
|
|
|
|
if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
|
|
|
|
else
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
|
|
|
|
#else
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
|
|
|
|
#ifdef HAVE_REMOTE
|
|
|
|
else
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
switch ( event.button.button ) {
|
|
|
|
/* The scrollwheel button up events are ignored as they are queued immediately */
|
|
|
|
case SDL_BUTTON_LEFT:
|
|
|
|
case SDL_BUTTON_MIDDLE:
|
|
|
|
if ( mapping && background ) {
|
|
|
|
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x,
|
|
|
|
#define SQUARE(x) ((x)*(x))
|
|
|
|
y, (int)sqrt( SQUARE(x-(int)event.button.x)
|
|
|
|
+ SQUARE(y-(int)event.button.y)) );
|
|
|
|
}
|
|
|
|
if ( background && xybutton ) {
|
|
|
|
button_event( xybutton, false );
|
|
|
|
xybutton = 0;
|
|
|
|
}
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
else {
|
|
|
|
button_event(BUTTON_TOUCHSCREEN, false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
{
|
2010-05-17 17:19:31 +00:00
|
|
|
sim_exit_irq_handler();
|
2010-05-27 18:46:09 +00:00
|
|
|
return false;
|
2010-05-15 21:02:47 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
/*printf("Unhandled event\n"); */
|
|
|
|
break;
|
|
|
|
}
|
2010-05-17 17:19:31 +00:00
|
|
|
sim_exit_irq_handler();
|
2010-05-15 21:02:47 +00:00
|
|
|
}
|
2010-05-27 18:46:09 +00:00
|
|
|
|
|
|
|
return true;
|
2010-05-15 21:02:47 +00:00
|
|
|
}
|
2007-03-05 14:48:31 +00:00
|
|
|
|
2010-05-15 21:02:47 +00:00
|
|
|
static void button_event(int key, bool pressed)
|
2006-02-03 15:19:58 +00:00
|
|
|
{
|
|
|
|
int new_btn = 0;
|
2007-02-21 14:32:41 +00:00
|
|
|
static bool usb_connected = false;
|
2010-01-16 21:41:57 +00:00
|
|
|
if (usb_connected && key != USB_KEY)
|
2007-02-21 14:32:41 +00:00
|
|
|
return;
|
2006-02-03 15:19:58 +00:00
|
|
|
switch (key)
|
|
|
|
{
|
2010-01-16 21:41:57 +00:00
|
|
|
case USB_KEY:
|
2007-02-21 14:32:41 +00:00
|
|
|
if (!pressed)
|
|
|
|
{
|
|
|
|
usb_connected = !usb_connected;
|
|
|
|
if (usb_connected)
|
2007-10-26 23:11:18 +00:00
|
|
|
queue_post(&button_queue, SYS_USB_CONNECTED, 0);
|
2007-02-21 14:32:41 +00:00
|
|
|
else
|
2007-10-26 23:11:18 +00:00
|
|
|
queue_post(&button_queue, SYS_USB_DISCONNECTED, 0);
|
2007-02-21 14:32:41 +00:00
|
|
|
}
|
2007-03-05 22:35:19 +00:00
|
|
|
return;
|
2007-03-05 14:48:31 +00:00
|
|
|
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
case SDLK_h:
|
|
|
|
if(pressed)
|
|
|
|
{
|
|
|
|
hold_button_state = !hold_button_state;
|
|
|
|
DEBUGF("Hold button is %s\n", hold_button_state?"ON":"OFF");
|
|
|
|
}
|
2007-03-05 22:35:19 +00:00
|
|
|
return;
|
2007-03-05 14:48:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAS_REMOTE_BUTTON_HOLD
|
|
|
|
case SDLK_j:
|
|
|
|
if(pressed)
|
|
|
|
{
|
|
|
|
remote_hold_button_state = !remote_hold_button_state;
|
|
|
|
DEBUGF("Remote hold button is %s\n",
|
|
|
|
remote_hold_button_state?"ON":"OFF");
|
|
|
|
}
|
2007-03-05 22:35:19 +00:00
|
|
|
return;
|
2007-03-05 14:48:31 +00:00
|
|
|
#endif
|
2007-01-14 13:48:09 +00:00
|
|
|
|
2010-06-06 10:27:14 +00:00
|
|
|
#if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
|
|
|
|
case SDLK_t:
|
|
|
|
if(pressed)
|
|
|
|
switch(_remote_type)
|
|
|
|
{
|
|
|
|
case REMOTETYPE_UNPLUGGED:
|
|
|
|
_remote_type=REMOTETYPE_H100_LCD;
|
|
|
|
DEBUGF("Changed remote type to H100\n");
|
|
|
|
break;
|
|
|
|
case REMOTETYPE_H100_LCD:
|
|
|
|
_remote_type=REMOTETYPE_H300_LCD;
|
|
|
|
DEBUGF("Changed remote type to H300\n");
|
|
|
|
break;
|
|
|
|
case REMOTETYPE_H300_LCD:
|
|
|
|
_remote_type=REMOTETYPE_H300_NONLCD;
|
|
|
|
DEBUGF("Changed remote type to H300 NON-LCD\n");
|
|
|
|
break;
|
|
|
|
case REMOTETYPE_H300_NONLCD:
|
|
|
|
_remote_type=REMOTETYPE_UNPLUGGED;
|
|
|
|
DEBUGF("Changed remote type to none\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
case SDLK_KP0:
|
|
|
|
case SDLK_F5:
|
|
|
|
if(pressed)
|
|
|
|
{
|
2009-02-20 17:13:08 +00:00
|
|
|
sim_trigger_screendump();
|
2006-02-03 15:19:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-06 10:27:14 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
case SDLK_F4:
|
|
|
|
if(pressed)
|
|
|
|
{
|
|
|
|
touchscreen_set_mode(touchscreen_get_mode() == TOUCHSCREEN_POINT ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT);
|
|
|
|
printf("Touchscreen mode: %s\n", touchscreen_get_mode() == TOUCHSCREEN_POINT ? "TOUCHSCREEN_POINT" : "TOUCHSCREEN_BUTTON");
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-06 09:11:52 +00:00
|
|
|
default:
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2010-06-06 10:27:14 +00:00
|
|
|
new_btn = key_to_touch(key, mouse_coords);
|
2010-06-06 09:11:52 +00:00
|
|
|
if (!new_btn)
|
|
|
|
#endif
|
|
|
|
new_btn = key_to_button(key);
|
|
|
|
break;
|
2006-02-03 15:19:58 +00:00
|
|
|
}
|
2009-10-06 01:26:01 +00:00
|
|
|
/* Call to make up for scrollwheel target implementation. This is
|
|
|
|
* not handled in the main button.c driver, but on the target
|
|
|
|
* implementation (look at button-e200.c for example if you are trying to
|
|
|
|
* figure out why using button_get_data needed a hack before).
|
|
|
|
*/
|
2009-10-31 16:31:42 +00:00
|
|
|
#if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK)
|
2009-10-06 01:26:01 +00:00
|
|
|
if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) &&
|
|
|
|
pressed)
|
|
|
|
{
|
2009-10-31 16:27:09 +00:00
|
|
|
/* Clear these buttons from the data - adding them to the queue is
|
|
|
|
* handled in the scrollwheel drivers for the targets. They do not
|
|
|
|
* store the scroll forward/back buttons in their button data for
|
|
|
|
* the button_read call.
|
|
|
|
*/
|
2010-01-19 22:07:28 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
|
|
|
backlight_on();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_BUTTON_LIGHT
|
|
|
|
buttonlight_on();
|
|
|
|
#endif
|
2009-10-06 01:26:01 +00:00
|
|
|
queue_post(&button_queue, new_btn, 1<<24);
|
2009-10-31 16:31:42 +00:00
|
|
|
new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK);
|
2009-10-06 01:26:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
if (pressed)
|
|
|
|
btn |= new_btn;
|
|
|
|
else
|
|
|
|
btn &= ~new_btn;
|
|
|
|
}
|
2009-10-06 01:26:01 +00:00
|
|
|
#if defined(HAVE_BUTTON_DATA) && defined(HAVE_TOUCHSCREEN)
|
2009-09-23 16:59:56 +00:00
|
|
|
int button_read_device(int* data)
|
2007-10-09 20:42:20 +00:00
|
|
|
{
|
2009-10-06 01:26:01 +00:00
|
|
|
*data = mouse_coords;
|
2009-09-23 16:59:56 +00:00
|
|
|
#else
|
|
|
|
int button_read_device(void)
|
2006-02-03 15:19:58 +00:00
|
|
|
{
|
2009-09-23 16:59:56 +00:00
|
|
|
#endif
|
2009-09-23 17:26:42 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
2009-09-23 16:59:56 +00:00
|
|
|
int hold_button = button_hold();
|
2009-09-23 17:26:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_BACKLIGHT
|
2009-09-23 16:59:56 +00:00
|
|
|
/* light handling */
|
2009-09-23 17:26:42 +00:00
|
|
|
static int hold_button_old = false;
|
2009-09-23 16:59:56 +00:00
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
{
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
backlight_hold_changed(hold_button);
|
2006-02-03 15:19:58 +00:00
|
|
|
}
|
2009-09-23 17:26:42 +00:00
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2009-09-23 16:59:56 +00:00
|
|
|
if (hold_button)
|
|
|
|
return BUTTON_NONE;
|
2010-05-15 21:02:47 +00:00
|
|
|
else
|
2009-09-23 17:26:42 +00:00
|
|
|
#endif
|
2007-07-22 21:17:19 +00:00
|
|
|
|
2009-09-23 16:59:56 +00:00
|
|
|
return btn;
|
2007-07-22 21:17:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2007-11-11 01:50:18 +00:00
|
|
|
extern bool debug_wps;
|
2007-11-03 11:58:31 +00:00
|
|
|
void mouse_tick_task(void)
|
|
|
|
{
|
|
|
|
static int last_check = 0;
|
|
|
|
int x,y;
|
|
|
|
if (TIME_BEFORE(current_tick, last_check+(HZ/10)))
|
|
|
|
return;
|
|
|
|
last_check = current_tick;
|
|
|
|
if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))
|
|
|
|
{
|
2008-05-30 22:55:24 +00:00
|
|
|
if(background)
|
|
|
|
{
|
|
|
|
x -= UI_LCD_POSX;
|
|
|
|
y -= UI_LCD_POSY;
|
|
|
|
|
2009-02-09 00:32:59 +00:00
|
|
|
if(x<0 || y<0 || x>SIM_LCD_WIDTH || y>SIM_LCD_HEIGHT)
|
2008-05-30 22:55:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-03 11:58:31 +00:00
|
|
|
mouse_coords = (x<<16)|y;
|
2008-08-23 09:46:38 +00:00
|
|
|
button_event(BUTTON_TOUCHSCREEN, true);
|
2007-11-11 01:50:18 +00:00
|
|
|
if (debug_wps)
|
|
|
|
printf("Mouse at: (%d, %d)\n", x, y);
|
2007-11-03 11:58:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2010-05-15 21:02:47 +00:00
|
|
|
void button_init_device(void)
|
2006-02-03 15:19:58 +00:00
|
|
|
{
|
2010-05-15 21:02:47 +00:00
|
|
|
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
2009-09-23 16:59:56 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
tick_add_task(mouse_tick_task);
|
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
}
|