1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Felix Arends
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "lcd-charcells.h"
22 #include "lcd-remote.h"
26 #include "backlight.h"
31 static intptr_t button_data
; /* data value from last message dequeued */
34 static int mouse_coords
= 0;
36 /* how long until repeat kicks in */
37 #define REPEAT_START 6
39 /* the speed repeat starts at */
40 #define REPEAT_INTERVAL_START 4
42 /* speed repeat finishes at */
43 #define REPEAT_INTERVAL_FINISH 2
45 #if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
46 int _remote_type
=REMOTETYPE_H100_LCD
;
54 struct event_queue button_queue
;
56 static int btn
= 0; /* Hopefully keeps track of currently pressed keys... */
59 static bool filter_first_keypress
;
61 void set_backlight_filter_keypress(bool value
)
63 filter_first_keypress
= value
;
65 #ifdef HAVE_REMOTE_LCD
66 static bool remote_filter_first_keypress
;
68 void set_remote_backlight_filter_keypress(bool value
)
70 remote_filter_first_keypress
= value
;
75 #ifdef HAS_BUTTON_HOLD
76 bool hold_button_state
= false;
77 bool button_hold(void) {
78 return hold_button_state
;
82 #ifdef HAS_REMOTE_BUTTON_HOLD
83 bool remote_hold_button_state
= false;
84 bool remote_button_hold(void) {
85 return remote_hold_button_state
;
90 void button_event(int key
, bool pressed
)
96 static int repeat_speed
= REPEAT_INTERVAL_START
;
97 static int repeat_count
= 0;
98 static bool repeat
= false;
99 static bool post
= false;
100 #ifdef HAVE_BACKLIGHT
101 static bool skip_release
= false;
102 #ifdef HAVE_REMOTE_LCD
103 static bool skip_remote_release
= false;
106 static bool usb_connected
= false;
107 if (usb_connected
&& key
!= SDLK_u
)
113 case BUTTON_TOUCHPAD
:
114 new_btn
= BUTTON_TOUCHPAD
;
121 usb_connected
= !usb_connected
;
123 queue_post(&button_queue
, SYS_USB_CONNECTED
, 0);
125 queue_post(&button_queue
, SYS_USB_DISCONNECTED
, 0);
129 #ifdef HAS_BUTTON_HOLD
133 hold_button_state
= !hold_button_state
;
134 DEBUGF("Hold button is %s\n", hold_button_state
?"ON":"OFF");
139 #ifdef HAS_REMOTE_BUTTON_HOLD
143 remote_hold_button_state
= !remote_hold_button_state
;
144 DEBUGF("Remote hold button is %s\n",
145 remote_hold_button_state
?"ON":"OFF");
150 #if CONFIG_KEYPAD == GIGABEAT_PAD
153 new_btn
= BUTTON_LEFT
;
157 new_btn
= BUTTON_RIGHT
;
165 new_btn
= BUTTON_DOWN
;
169 new_btn
= BUTTON_POWER
;
172 new_btn
= BUTTON_POWER
;
181 new_btn
= BUTTON_SELECT
;
185 new_btn
= BUTTON_MENU
;
188 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
191 new_btn
= BUTTON_LEFT
;
195 new_btn
= BUTTON_RIGHT
;
203 new_btn
= BUTTON_DOWN
;
207 new_btn
= BUTTON_PLAY
;
210 new_btn
= BUTTON_POWER
;
215 new_btn
= BUTTON_POWER
;
219 new_btn
= BUTTON_REC
;
223 new_btn
= BUTTON_SELECT
;
226 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
227 || (CONFIG_KEYPAD == IPOD_4G_PAD)
230 new_btn
= BUTTON_LEFT
;
234 new_btn
= BUTTON_RIGHT
;
238 new_btn
= BUTTON_SCROLL_BACK
;
242 new_btn
= BUTTON_SCROLL_FWD
;
246 new_btn
= BUTTON_PLAY
;
250 new_btn
= BUTTON_SELECT
;
254 new_btn
= BUTTON_MENU
;
257 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
260 new_btn
= BUTTON_LEFT
;
264 new_btn
= BUTTON_RIGHT
;
268 new_btn
= BUTTON_SCROLL_UP
;
272 new_btn
= BUTTON_SCROLL_DOWN
;
276 new_btn
= BUTTON_POWER
;
279 new_btn
= BUTTON_POWER
;
283 new_btn
= BUTTON_REW
;
285 case SDLK_KP_MULTIPLY
:
291 new_btn
= BUTTON_PLAY
;
294 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
299 case REMOTETYPE_UNPLUGGED
:
300 _remote_type
=REMOTETYPE_H100_LCD
;
301 DEBUGF("Changed remote type to H100\n");
303 case REMOTETYPE_H100_LCD
:
304 _remote_type
=REMOTETYPE_H300_LCD
;
305 DEBUGF("Changed remote type to H300\n");
307 case REMOTETYPE_H300_LCD
:
308 _remote_type
=REMOTETYPE_H300_NONLCD
;
309 DEBUGF("Changed remote type to H300 NON-LCD\n");
311 case REMOTETYPE_H300_NONLCD
:
312 _remote_type
=REMOTETYPE_UNPLUGGED
;
313 DEBUGF("Changed remote type to none\n");
319 new_btn
= BUTTON_LEFT
;
323 new_btn
= BUTTON_RIGHT
;
331 new_btn
= BUTTON_DOWN
;
340 new_btn
= BUTTON_OFF
;
344 new_btn
= BUTTON_REC
;
348 new_btn
= BUTTON_SELECT
;
352 new_btn
= BUTTON_MODE
;
355 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
358 new_btn
= BUTTON_LEFT
;
362 new_btn
= BUTTON_RIGHT
;
370 new_btn
= BUTTON_DOWN
;
374 new_btn
= BUTTON_PLAY
;
383 new_btn
= BUTTON_SELECT
;
387 new_btn
= BUTTON_MODE
;
390 #elif CONFIG_KEYPAD == ONDIO_PAD
393 new_btn
= BUTTON_LEFT
;
397 new_btn
= BUTTON_RIGHT
;
405 new_btn
= BUTTON_DOWN
;
410 new_btn
= BUTTON_OFF
;
414 new_btn
= BUTTON_MENU
;
417 #elif CONFIG_KEYPAD == PLAYER_PAD
420 new_btn
= BUTTON_LEFT
;
424 new_btn
= BUTTON_RIGHT
;
428 new_btn
= BUTTON_PLAY
;
432 new_btn
= BUTTON_STOP
;
440 new_btn
= BUTTON_MENU
;
443 #elif CONFIG_KEYPAD == RECORDER_PAD
446 new_btn
= BUTTON_LEFT
;
450 new_btn
= BUTTON_RIGHT
;
458 new_btn
= BUTTON_DOWN
;
467 new_btn
= BUTTON_OFF
;
473 case SDLK_KP_MULTIPLY
:
483 new_btn
= BUTTON_PLAY
;
486 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
489 new_btn
= BUTTON_LEFT
;
493 new_btn
= BUTTON_RIGHT
;
501 new_btn
= BUTTON_DOWN
;
510 new_btn
= BUTTON_OFF
;
516 case SDLK_KP_MULTIPLY
:
526 new_btn
= BUTTON_SELECT
;
529 #elif CONFIG_KEYPAD == SANSA_E200_PAD
532 new_btn
= BUTTON_LEFT
;
536 new_btn
= BUTTON_RIGHT
;
540 new_btn
= BUTTON_SCROLL_UP
;
544 new_btn
= BUTTON_SCROLL_DOWN
;
550 new_btn
= BUTTON_DOWN
;
553 new_btn
= BUTTON_POWER
;
556 new_btn
= BUTTON_REC
;
560 new_btn
= BUTTON_SELECT
;
563 #elif CONFIG_KEYPAD == SANSA_C200_PAD
566 new_btn
= BUTTON_LEFT
;
570 new_btn
= BUTTON_RIGHT
;
578 new_btn
= BUTTON_DOWN
;
581 new_btn
= BUTTON_POWER
;
584 new_btn
= BUTTON_REC
;
589 new_btn
= BUTTON_SELECT
;
592 new_btn
= BUTTON_VOL_DOWN
;
595 new_btn
= BUTTON_VOL_UP
;
598 #elif CONFIG_KEYPAD == MROBE500_PAD
601 new_btn
= BUTTON_LEFT
;
605 new_btn
= BUTTON_RIGHT
;
609 new_btn
= BUTTON_RC_PLAY
;
613 new_btn
= BUTTON_RC_DOWN
;
617 new_btn
= BUTTON_POWER
;
620 new_btn
= BUTTON_POWER
;
625 new_btn
= BUTTON_RC_VOL_UP
;
629 new_btn
= BUTTON_RC_HEART
;
633 new_btn
= BUTTON_RC_MODE
;
636 #error No keymap defined!
637 #endif /* CONFIG_KEYPAD */
642 queue_broadcast(SYS_SCREENDUMP
, 0);
653 /* Lots of stuff copied from real button.c. Not good, I think... */
655 /* Find out if a key has been released */
656 diff
= btn
^ lastbtn
;
657 if(diff
&& (btn
& diff
) == 0)
659 #ifdef HAVE_BACKLIGHT
660 #ifdef HAVE_REMOTE_LCD
661 if(diff
& BUTTON_REMOTE
)
662 if(!skip_remote_release
)
663 queue_post(&button_queue
, BUTTON_REL
| diff
, data
);
665 skip_remote_release
= false;
669 queue_post(&button_queue
, BUTTON_REL
| diff
, data
);
671 skip_release
= false;
673 queue_post(&button_queue
, BUTTON_REL
| diff
, data
);
681 /* normal keypress */
682 if ( btn
!= lastbtn
)
686 repeat_speed
= REPEAT_INTERVAL_START
;
698 /* yes we have repeat */
700 if (repeat_speed
< REPEAT_INTERVAL_FINISH
)
701 repeat_speed
= REPEAT_INTERVAL_FINISH
;
702 count
= repeat_speed
;
709 if (count
++ > REPEAT_START
)
715 count
= REPEAT_INTERVAL_START
;
723 if (queue_empty(&button_queue
))
725 queue_post(&button_queue
, BUTTON_REPEAT
| btn
, data
);
726 #ifdef HAVE_BACKLIGHT
727 #ifdef HAVE_REMOTE_LCD
728 if(btn
& BUTTON_REMOTE
)
730 if(skip_remote_release
)
731 skip_remote_release
= false;
736 skip_release
= false;
743 #ifdef HAVE_BACKLIGHT
744 #ifdef HAVE_REMOTE_LCD
745 if (btn
& BUTTON_REMOTE
) {
746 if (!remote_filter_first_keypress
|| is_remote_backlight_on())
747 queue_post(&button_queue
, btn
, data
);
749 skip_remote_release
= true;
753 if (!filter_first_keypress
|| is_backlight_on())
754 queue_post(&button_queue
, btn
, data
);
757 #else /* no backlight, nothing to skip */
758 queue_post(&button_queue
, btn
, data
);
763 #ifdef HAVE_REMOTE_LCD
764 if(btn
& BUTTON_REMOTE
)
765 remote_backlight_on();
778 lastbtn
= btn
& ~(BUTTON_REL
| BUTTON_REPEAT
);
781 /* Again copied from real button.c... */
783 int button_queue_count( void )
785 return queue_count(&button_queue
);
788 long button_get(bool block
)
790 struct queue_event ev
;
792 if ( block
|| !queue_empty(&button_queue
) ) {
793 queue_wait(&button_queue
, &ev
);
794 button_data
= ev
.data
;
800 long button_get_w_tmo(int ticks
)
802 struct queue_event ev
;
803 queue_wait_w_tmo(&button_queue
, &ev
, ticks
);
804 if (ev
.id
== SYS_TIMEOUT
)
807 button_data
= ev
.data
;
812 intptr_t button_get_data(void)
817 /* Needed by the accelerating wheel driver for Sansa e200 */
823 extern bool debug_wps
;
824 void mouse_tick_task(void)
826 static int last_check
= 0;
828 if (TIME_BEFORE(current_tick
, last_check
+(HZ
/10)))
830 last_check
= current_tick
;
831 if (SDL_GetMouseState(&x
, &y
) & SDL_BUTTON(SDL_BUTTON_LEFT
))
833 mouse_coords
= (x
<<16)|y
;
834 button_event(BUTTON_TOUCHPAD
, true);
836 printf("Mouse at: (%d, %d)\n", x
, y
);
838 else if (lastbtn
== BUTTON_TOUCHPAD
)
840 button_event(BUTTON_TOUCHPAD
, false);
845 void button_init(void)
848 tick_add_task(mouse_tick_task
);
852 int button_status(void)
857 void button_clear_queue(void)
859 queue_clear(&button_queue
);