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-charcell.h"
22 #include "lcd-remote.h"
26 #include "backlight.h"
30 /* how long until repeat kicks in */
31 #define REPEAT_START 6
33 /* the speed repeat starts at */
34 #define REPEAT_INTERVAL_START 4
36 /* speed repeat finishes at */
37 #define REPEAT_INTERVAL_FINISH 2
39 #if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
40 int _remote_type
=REMOTETYPE_H100_LCD
;
48 struct event_queue button_queue
;
50 static int btn
= 0; /* Hopefully keeps track of currently pressed keys... */
53 static bool filter_first_keypress
;
55 void set_backlight_filter_keypress(bool value
)
57 filter_first_keypress
= value
;
59 #ifdef HAVE_REMOTE_LCD
60 static bool remote_filter_first_keypress
;
62 void set_remote_backlight_filter_keypress(bool value
)
64 remote_filter_first_keypress
= value
;
69 #ifdef HAS_BUTTON_HOLD
70 bool hold_button_state
= false;
71 bool button_hold(void) {
72 return hold_button_state
;
76 #ifdef HAS_REMOTE_BUTTON_HOLD
77 bool remote_hold_button_state
= false;
78 bool remote_button_hold(void) {
79 return remote_hold_button_state
;
83 void button_event(int key
, bool pressed
)
89 static int repeat_speed
= REPEAT_INTERVAL_START
;
90 static int repeat_count
= 0;
91 static bool repeat
= false;
92 static bool post
= false;
94 static bool skip_release
= false;
95 #ifdef HAVE_REMOTE_LCD
96 static bool skip_remote_release
= false;
99 static bool usb_connected
= false;
100 if (usb_connected
&& key
!= SDLK_u
)
108 usb_connected
= !usb_connected
;
110 queue_post(&button_queue
, SYS_USB_CONNECTED
, 0);
112 queue_post(&button_queue
, SYS_USB_DISCONNECTED
, 0);
116 #ifdef HAS_BUTTON_HOLD
120 hold_button_state
= !hold_button_state
;
121 DEBUGF("Hold button is %s\n", hold_button_state
?"ON":"OFF");
126 #ifdef HAS_REMOTE_BUTTON_HOLD
130 remote_hold_button_state
= !remote_hold_button_state
;
131 DEBUGF("Remote hold button is %s\n",
132 remote_hold_button_state
?"ON":"OFF");
137 #if CONFIG_KEYPAD == GIGABEAT_PAD
140 new_btn
= BUTTON_LEFT
;
144 new_btn
= BUTTON_RIGHT
;
152 new_btn
= BUTTON_DOWN
;
156 new_btn
= BUTTON_POWER
;
159 new_btn
= BUTTON_POWER
;
168 new_btn
= BUTTON_SELECT
;
172 new_btn
= BUTTON_MENU
;
175 #elif CONFIG_KEYPAD == IAUDIO_X5_PAD
178 new_btn
= BUTTON_LEFT
;
182 new_btn
= BUTTON_RIGHT
;
190 new_btn
= BUTTON_DOWN
;
194 new_btn
= BUTTON_PLAY
;
197 new_btn
= BUTTON_POWER
;
202 new_btn
= BUTTON_POWER
;
206 new_btn
= BUTTON_REC
;
210 new_btn
= BUTTON_SELECT
;
213 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
216 new_btn
= BUTTON_LEFT
;
220 new_btn
= BUTTON_RIGHT
;
224 new_btn
= BUTTON_SCROLL_BACK
;
228 new_btn
= BUTTON_SCROLL_FWD
;
232 new_btn
= BUTTON_PLAY
;
236 new_btn
= BUTTON_SELECT
;
240 new_btn
= BUTTON_MENU
;
243 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
246 new_btn
= BUTTON_LEFT
;
250 new_btn
= BUTTON_RIGHT
;
254 new_btn
= BUTTON_SCROLL_UP
;
258 new_btn
= BUTTON_SCROLL_DOWN
;
262 new_btn
= BUTTON_POWER
;
265 new_btn
= BUTTON_POWER
;
269 new_btn
= BUTTON_REW
;
271 case SDLK_KP_MULTIPLY
:
277 new_btn
= BUTTON_PLAY
;
280 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
285 case REMOTETYPE_UNPLUGGED
:
286 _remote_type
=REMOTETYPE_H100_LCD
;
287 DEBUGF("Changed remote type to H100\n");
289 case REMOTETYPE_H100_LCD
:
290 _remote_type
=REMOTETYPE_H300_LCD
;
291 DEBUGF("Changed remote type to H300\n");
293 case REMOTETYPE_H300_LCD
:
294 _remote_type
=REMOTETYPE_H300_NONLCD
;
295 DEBUGF("Changed remote type to H300 NON-LCD\n");
297 case REMOTETYPE_H300_NONLCD
:
298 _remote_type
=REMOTETYPE_UNPLUGGED
;
299 DEBUGF("Changed remote type to none\n");
305 new_btn
= BUTTON_LEFT
;
309 new_btn
= BUTTON_RIGHT
;
317 new_btn
= BUTTON_DOWN
;
326 new_btn
= BUTTON_OFF
;
330 new_btn
= BUTTON_REC
;
334 new_btn
= BUTTON_SELECT
;
338 new_btn
= BUTTON_MODE
;
341 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
344 new_btn
= BUTTON_LEFT
;
348 new_btn
= BUTTON_RIGHT
;
356 new_btn
= BUTTON_DOWN
;
360 new_btn
= BUTTON_PLAY
;
369 new_btn
= BUTTON_SELECT
;
373 new_btn
= BUTTON_MODE
;
376 #elif CONFIG_KEYPAD == ONDIO_PAD
379 new_btn
= BUTTON_LEFT
;
383 new_btn
= BUTTON_RIGHT
;
391 new_btn
= BUTTON_DOWN
;
396 new_btn
= BUTTON_OFF
;
400 new_btn
= BUTTON_MENU
;
403 #elif CONFIG_KEYPAD == PLAYER_PAD
406 new_btn
= BUTTON_LEFT
;
410 new_btn
= BUTTON_RIGHT
;
414 new_btn
= BUTTON_PLAY
;
418 new_btn
= BUTTON_STOP
;
426 new_btn
= BUTTON_MENU
;
429 #elif CONFIG_KEYPAD == RECORDER_PAD
432 new_btn
= BUTTON_LEFT
;
436 new_btn
= BUTTON_RIGHT
;
444 new_btn
= BUTTON_DOWN
;
453 new_btn
= BUTTON_OFF
;
459 case SDLK_KP_MULTIPLY
:
469 new_btn
= BUTTON_PLAY
;
472 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
475 new_btn
= BUTTON_LEFT
;
479 new_btn
= BUTTON_RIGHT
;
487 new_btn
= BUTTON_DOWN
;
496 new_btn
= BUTTON_OFF
;
502 case SDLK_KP_MULTIPLY
:
512 new_btn
= BUTTON_SELECT
;
515 #elif CONFIG_KEYPAD == SANSA_E200_PAD
518 new_btn
= BUTTON_LEFT
;
522 new_btn
= BUTTON_RIGHT
;
526 new_btn
= BUTTON_SCROLL_UP
;
530 new_btn
= BUTTON_SCROLL_DOWN
;
536 new_btn
= BUTTON_DOWN
;
539 new_btn
= BUTTON_POWER
;
542 new_btn
= BUTTON_REC
;
546 new_btn
= BUTTON_SELECT
;
549 #endif /* CONFIG_KEYPAD */
565 /* Lots of stuff copied from real button.c. Not good, I think... */
567 /* Find out if a key has been released */
568 diff
= btn
^ lastbtn
;
569 if(diff
&& (btn
& diff
) == 0)
572 #ifdef HAVE_REMOTE_LCD
573 if(diff
& BUTTON_REMOTE
)
574 if(!skip_remote_release
)
575 queue_post(&button_queue
, BUTTON_REL
| diff
, 0);
577 skip_remote_release
= false;
581 queue_post(&button_queue
, BUTTON_REL
| diff
, 0);
583 skip_release
= false;
585 queue_post(&button_queue
, BUTTON_REL
| diff
, 0);
593 /* normal keypress */
594 if ( btn
!= lastbtn
)
598 repeat_speed
= REPEAT_INTERVAL_START
;
610 /* yes we have repeat */
612 if (repeat_speed
< REPEAT_INTERVAL_FINISH
)
613 repeat_speed
= REPEAT_INTERVAL_FINISH
;
614 count
= repeat_speed
;
621 if (count
++ > REPEAT_START
)
627 count
= REPEAT_INTERVAL_START
;
635 if (queue_empty(&button_queue
))
637 queue_post(&button_queue
, BUTTON_REPEAT
| btn
, 0);
639 #ifdef HAVE_REMOTE_LCD
640 if(btn
& BUTTON_REMOTE
)
642 if(skip_remote_release
)
643 skip_remote_release
= false;
648 skip_release
= false;
656 #ifdef HAVE_REMOTE_LCD
657 if (btn
& BUTTON_REMOTE
) {
658 if (!remote_filter_first_keypress
|| is_remote_backlight_on())
659 queue_post(&button_queue
, btn
, 0);
661 skip_remote_release
= true;
665 if (!filter_first_keypress
|| is_backlight_on())
666 queue_post(&button_queue
, btn
, 0);
669 #else /* no backlight, nothing to skip */
670 queue_post(&button_queue
, btn
, 0);
675 #ifdef HAVE_REMOTE_LCD
676 if(btn
& BUTTON_REMOTE
)
677 remote_backlight_on();
690 lastbtn
= btn
& ~(BUTTON_REL
| BUTTON_REPEAT
);
693 /* Again copied from real button.c... */
695 long button_get(bool block
)
699 if ( block
|| !queue_empty(&button_queue
) ) {
700 queue_wait(&button_queue
, &ev
);
706 long button_get_w_tmo(int ticks
)
709 queue_wait_w_tmo(&button_queue
, &ev
, ticks
);
710 return (ev
.id
!= SYS_TIMEOUT
)? ev
.id
: BUTTON_NONE
;
713 void button_init(void)
717 int button_status(void)
722 void button_clear_queue(void)
724 queue_clear(&button_queue
);