1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Felix Arends
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include <stdlib.h> /* EXIT_SUCCESS */
24 #include "sim-ui-defines.h"
25 #include "lcd-charcells.h"
26 #include "lcd-remote.h"
30 #include "backlight.h"
32 #include "button-sdl.h"
33 #include "backlight.h"
35 #include "sim_tasks.h"
36 #include "buttonmap.h"
40 #ifdef HAVE_TOUCHSCREEN
41 #include "touchscreen.h"
42 static int mouse_coords
= 0;
44 /* how long until repeat kicks in */
45 #define REPEAT_START 6
47 /* the speed repeat starts at */
48 #define REPEAT_INTERVAL_START 4
50 /* speed repeat finishes at */
51 #define REPEAT_INTERVAL_FINISH 2
53 #ifdef HAVE_TOUCHSCREEN
54 #define USB_KEY SDLK_c /* SDLK_u is taken by BUTTON_MIDLEFT */
56 #define USB_KEY SDLK_u
59 #if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
60 int _remote_type
=REMOTETYPE_H100_LCD
;
68 struct event_queue button_queue
;
70 static int btn
= 0; /* Hopefully keeps track of currently pressed keys... */
72 #ifdef HAS_BUTTON_HOLD
73 bool hold_button_state
= false;
74 bool button_hold(void) {
75 return hold_button_state
;
79 #ifdef HAS_REMOTE_BUTTON_HOLD
80 bool remote_hold_button_state
= false;
81 bool remote_button_hold(void) {
82 return remote_hold_button_state
;
85 static void button_event(int key
, bool pressed
);
86 extern bool debug_wps
;
89 #ifdef HAVE_TOUCHSCREEN
90 static void touchscreen_event(int x
, int y
)
97 if(x
>= 0 && y
>= 0 && x
< SIM_LCD_WIDTH
&& y
< SIM_LCD_HEIGHT
) {
98 mouse_coords
= (x
<< 16) | y
;
99 button_event(BUTTON_TOUCHSCREEN
, true);
101 printf("Mouse at: (%d, %d)\n", x
, y
);
106 bool gui_message_loop(void)
109 static int x
,y
,xybutton
= 0;
111 while (SDL_WaitEvent(&event
))
113 sim_enter_irq_handler();
118 button_event(event
.key
.keysym
.sym
, event
.type
== SDL_KEYDOWN
);
120 #ifdef HAVE_TOUCHSCREEN
121 case SDL_MOUSEMOTION
:
122 if (event
.motion
.state
& SDL_BUTTON(1))
123 touchscreen_event(event
.motion
.x
, event
.motion
.y
);
126 case SDL_MOUSEBUTTONDOWN
:
127 switch ( event
.button
.button
) {
128 #ifdef HAVE_SCROLLWHEEL
129 case SDL_BUTTON_WHEELUP
:
130 button_event( SDLK_UP
, true );
132 case SDL_BUTTON_WHEELDOWN
:
133 button_event( SDLK_DOWN
, true );
136 case SDL_BUTTON_LEFT
:
137 case SDL_BUTTON_MIDDLE
:
138 if ( mapping
&& background
) {
143 xybutton
= xy2button( event
.button
.x
, event
.button
.y
);
145 button_event( xybutton
, true );
149 #ifdef HAVE_TOUCHSCREEN
150 touchscreen_event(event
.button
.x
, event
.button
.y
);
158 if (debug_wps
&& event
.button
.button
== 1)
162 if ( event
.button
.y
< UI_REMOTE_POSY
) /* Main Screen */
163 printf("Mouse at: (%d, %d)\n", event
.button
.x
- UI_LCD_POSX
-1 , event
.button
.y
- UI_LCD_POSY
- 1 );
165 printf("Mouse at: (%d, %d)\n", event
.button
.x
- UI_REMOTE_POSX
-1 , event
.button
.y
- UI_REMOTE_POSY
- 1 );
167 printf("Mouse at: (%d, %d)\n", event
.button
.x
- UI_LCD_POSX
-1 , event
.button
.y
- UI_LCD_POSY
- 1 );
170 if ( event
.button
.y
/display_zoom
< LCD_HEIGHT
) /* Main Screen */
171 printf("Mouse at: (%d, %d)\n", event
.button
.x
/display_zoom
, event
.button
.y
/display_zoom
);
174 printf("Mouse at: (%d, %d)\n", event
.button
.x
/display_zoom
, event
.button
.y
/display_zoom
- LCD_HEIGHT
);
178 case SDL_MOUSEBUTTONUP
:
179 switch ( event
.button
.button
) {
180 /* The scrollwheel button up events are ignored as they are queued immediately */
181 case SDL_BUTTON_LEFT
:
182 case SDL_BUTTON_MIDDLE
:
183 if ( mapping
&& background
) {
184 printf(" { SDLK_, %d, %d, %d, \"\" },\n", x
,
185 #define SQUARE(x) ((x)*(x))
186 y
, (int)sqrt( SQUARE(x
-(int)event
.button
.x
)
187 + SQUARE(y
-(int)event
.button
.y
)) );
189 if ( background
&& xybutton
) {
190 button_event( xybutton
, false );
193 #ifdef HAVE_TOUCHSCREEN
195 button_event(BUTTON_TOUCHSCREEN
, false);
206 sim_exit_irq_handler();
210 /*printf("Unhandled event\n"); */
213 sim_exit_irq_handler();
219 static void button_event(int key
, bool pressed
)
222 static bool usb_connected
= false;
223 if (usb_connected
&& key
!= USB_KEY
)
230 usb_connected
= !usb_connected
;
232 queue_post(&button_queue
, SYS_USB_CONNECTED
, 0);
234 queue_post(&button_queue
, SYS_USB_DISCONNECTED
, 0);
238 #ifdef HAS_BUTTON_HOLD
242 hold_button_state
= !hold_button_state
;
243 DEBUGF("Hold button is %s\n", hold_button_state
?"ON":"OFF");
248 #ifdef HAS_REMOTE_BUTTON_HOLD
252 remote_hold_button_state
= !remote_hold_button_state
;
253 DEBUGF("Remote hold button is %s\n",
254 remote_hold_button_state
?"ON":"OFF");
259 #if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
264 case REMOTETYPE_UNPLUGGED
:
265 _remote_type
=REMOTETYPE_H100_LCD
;
266 DEBUGF("Changed remote type to H100\n");
268 case REMOTETYPE_H100_LCD
:
269 _remote_type
=REMOTETYPE_H300_LCD
;
270 DEBUGF("Changed remote type to H300\n");
272 case REMOTETYPE_H300_LCD
:
273 _remote_type
=REMOTETYPE_H300_NONLCD
;
274 DEBUGF("Changed remote type to H300 NON-LCD\n");
276 case REMOTETYPE_H300_NONLCD
:
277 _remote_type
=REMOTETYPE_UNPLUGGED
;
278 DEBUGF("Changed remote type to none\n");
287 sim_trigger_screendump();
291 #ifdef HAVE_TOUCHSCREEN
295 touchscreen_set_mode(touchscreen_get_mode() == TOUCHSCREEN_POINT
? TOUCHSCREEN_BUTTON
: TOUCHSCREEN_POINT
);
296 printf("Touchscreen mode: %s\n", touchscreen_get_mode() == TOUCHSCREEN_POINT
? "TOUCHSCREEN_POINT" : "TOUCHSCREEN_BUTTON");
300 #ifdef HAVE_TOUCHSCREEN
301 new_btn
= key_to_touch(key
, mouse_coords
);
304 new_btn
= key_to_button(key
);
307 /* Call to make up for scrollwheel target implementation. This is
308 * not handled in the main button.c driver, but on the target
309 * implementation (look at button-e200.c for example if you are trying to
310 * figure out why using button_get_data needed a hack before).
312 #if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK)
313 if((new_btn
== BUTTON_SCROLL_FWD
|| new_btn
== BUTTON_SCROLL_BACK
) &&
316 /* Clear these buttons from the data - adding them to the queue is
317 * handled in the scrollwheel drivers for the targets. They do not
318 * store the scroll forward/back buttons in their button data for
319 * the button_read call.
321 #ifdef HAVE_BACKLIGHT
324 #ifdef HAVE_BUTTON_LIGHT
327 queue_post(&button_queue
, new_btn
, 1<<24);
328 new_btn
&= ~(BUTTON_SCROLL_FWD
| BUTTON_SCROLL_BACK
);
337 #if defined(HAVE_BUTTON_DATA) && defined(HAVE_TOUCHSCREEN)
338 int button_read_device(int* data
)
340 *data
= mouse_coords
;
342 int button_read_device(void)
345 #ifdef HAS_BUTTON_HOLD
346 int hold_button
= button_hold();
348 #ifdef HAVE_BACKLIGHT
350 static int hold_button_old
= false;
351 if (hold_button
!= hold_button_old
)
353 hold_button_old
= hold_button
;
354 backlight_hold_changed(hold_button
);
366 void button_init_device(void)
368 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);