Moved LCD_WIDHT/HEIGHT from lcd driver to config file.
[kugel-rb.git] / apps / wps.c
blob92b4e008b8daa9aa6f192158b75f77073586b137
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Jerome Kuptz
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 ****************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
23 #include "system.h"
24 #include "file.h"
25 #include "lcd.h"
26 #include "font.h"
27 #include "backlight.h"
28 #include "button.h"
29 #include "kernel.h"
30 #include "tree.h"
31 #include "debug.h"
32 #include "sprintf.h"
33 #include "settings.h"
34 #include "wps.h"
35 #include "wps-display.h"
36 #include "mpeg.h"
37 #include "mp3_playback.h"
38 #include "usb.h"
39 #include "status.h"
40 #include "main_menu.h"
41 #include "ata.h"
42 #include "screens.h"
43 #include "playlist.h"
44 #ifdef HAVE_LCD_BITMAP
45 #include "icons.h"
46 #include "peakmeter.h"
47 #include "action.h"
48 #endif
49 #include "lang.h"
50 #include "bookmark.h"
51 #include "misc.h"
53 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
54 /* 3% of 30min file == 54s step size */
55 #define MIN_FF_REWIND_STEP 500
57 bool keys_locked = false;
58 static bool ff_rewind = false;
59 static bool paused = false;
60 static struct mp3entry* id3 = NULL;
61 static struct mp3entry* nid3 = NULL;
62 static char current_track_path[MAX_PATH+1];
64 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD) || defined(HAVE_ONDIO_KEYPAD)
65 void player_change_volume(int button)
67 bool exit = false;
68 char buffer[32];
70 lcd_stop_scroll();
71 while (!exit)
73 switch (button)
75 case BUTTON_MENU | BUTTON_RIGHT:
76 case BUTTON_MENU | BUTTON_RIGHT | BUTTON_REPEAT:
77 global_settings.volume++;
78 if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
79 global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
80 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
81 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC);
82 settings_save();
83 break;
85 case BUTTON_MENU | BUTTON_LEFT:
86 case BUTTON_MENU | BUTTON_LEFT | BUTTON_REPEAT:
87 global_settings.volume--;
88 if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
89 global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
90 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
91 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC);
92 settings_save();
93 break;
95 case BUTTON_MENU | BUTTON_REL:
96 case BUTTON_MENU | BUTTON_LEFT | BUTTON_REL:
97 case BUTTON_MENU | BUTTON_RIGHT | BUTTON_REL:
98 exit = true;
99 break;
102 snprintf(buffer,sizeof(buffer),"Vol: %d %% ",
103 mpeg_val2phys(SOUND_VOLUME, global_settings.volume));
105 #ifdef HAVE_LCD_CHARCELLS
106 lcd_puts(0, 0, buffer);
107 #else
108 lcd_puts(2, 3, buffer);
109 lcd_update();
110 #endif
111 status_draw(false);
113 if (!exit)
114 button = button_get(true);
116 wps_refresh(id3, nid3, 0, WPS_REFRESH_ALL);
118 #endif
120 void display_keylock_text(bool locked)
122 char* s;
123 lcd_stop_scroll();
124 #ifdef HAVE_LCD_CHARCELLS
125 if(locked)
126 s = str(LANG_KEYLOCK_ON_PLAYER);
127 else
128 s = str(LANG_KEYLOCK_OFF_PLAYER);
129 #else
130 if(locked)
131 s = str(LANG_KEYLOCK_ON_RECORDER);
132 else
133 s = str(LANG_KEYLOCK_OFF_RECORDER);
134 #endif
135 splash(HZ, true, s);
138 void display_mute_text(bool muted)
140 char *s;
141 lcd_stop_scroll();
142 #ifdef HAVE_LCD_CHARCELLS
143 if (muted)
144 s = str(LANG_MUTE_ON_PLAYER);
145 else
146 s = str(LANG_MUTE_OFF_PLAYER);
147 #else
148 if (muted)
149 s = str(LANG_MUTE_ON_RECORDER);
150 else
151 s = str(LANG_MUTE_OFF_RECORDER);
152 #endif
153 splash(HZ, true, s);
156 bool browse_id3(void)
158 int button;
159 int menu_pos = 0;
160 int menu_max = 8;
161 bool exit = false;
162 char scroll_text[MAX_PATH];
164 if (!(mpeg_status() & MPEG_STATUS_PLAY))
165 return false;
167 while (!exit)
169 lcd_clear_display();
171 switch (menu_pos)
173 case 0:
174 lcd_puts(0, 0, str(LANG_ID3_TITLE));
175 lcd_puts_scroll(0, 1, id3->title ? id3->title :
176 (char*)str(LANG_ID3_NO_TITLE));
177 break;
179 case 1:
180 lcd_puts(0, 0, str(LANG_ID3_ARTIST));
181 lcd_puts_scroll(0, 1,
182 id3->artist ? id3->artist :
183 (char*)str(LANG_ID3_NO_ARTIST));
184 break;
186 case 2:
187 lcd_puts(0, 0, str(LANG_ID3_ALBUM));
188 lcd_puts_scroll(0, 1, id3->album ? id3->album :
189 (char*)str(LANG_ID3_NO_ALBUM));
190 break;
192 case 3:
193 lcd_puts(0, 0, str(LANG_ID3_TRACKNUM));
195 if (id3->tracknum) {
196 snprintf(scroll_text,sizeof(scroll_text), "%d",
197 id3->tracknum);
198 lcd_puts_scroll(0, 1, scroll_text);
200 else
201 lcd_puts_scroll(0, 1, str(LANG_ID3_NO_TRACKNUM));
202 break;
204 case 4:
205 lcd_puts(0, 0, str(LANG_ID3_GENRE));
206 lcd_puts_scroll(0, 1,
207 id3_get_genre(id3) ?
208 id3_get_genre(id3) :
209 (char*)str(LANG_ID3_NO_INFO));
210 break;
212 case 5:
213 lcd_puts(0, 0, str(LANG_ID3_YEAR));
214 if (id3->year) {
215 snprintf(scroll_text,sizeof(scroll_text), "%d",
216 id3->year);
217 lcd_puts_scroll(0, 1, scroll_text);
219 else
220 lcd_puts_scroll(0, 1, str(LANG_ID3_NO_INFO));
221 break;
223 case 6:
224 lcd_puts(0, 0, str(LANG_ID3_LENGHT));
225 snprintf(scroll_text,sizeof(scroll_text), "%d:%02d",
226 id3->length / 60000,
227 id3->length % 60000 / 1000 );
228 lcd_puts(0, 1, scroll_text);
229 break;
231 case 7:
232 lcd_puts(0, 0, str(LANG_ID3_PLAYLIST));
233 snprintf(scroll_text,sizeof(scroll_text), "%d/%d",
234 playlist_get_display_index(), playlist_amount());
235 lcd_puts_scroll(0, 1, scroll_text);
236 break;
239 case 8:
240 lcd_puts(0, 0, str(LANG_ID3_BITRATE));
241 snprintf(scroll_text,sizeof(scroll_text), "%d kbps",
242 id3->bitrate);
243 lcd_puts(0, 1, scroll_text);
244 break;
246 case 9:
247 lcd_puts(0, 0, str(LANG_ID3_FRECUENCY));
248 snprintf(scroll_text,sizeof(scroll_text), "%d Hz",
249 id3->frequency);
250 lcd_puts(0, 1, scroll_text);
251 break;
253 case 10:
254 lcd_puts(0, 0, str(LANG_ID3_PATH));
255 lcd_puts_scroll(0, 1, id3->path);
256 break;
258 lcd_update();
260 button = button_get(true);
262 switch(button)
264 case BUTTON_LEFT:
265 #ifdef HAVE_RECORDER_KEYPAD
266 case BUTTON_UP:
267 #endif
268 if (menu_pos > 0)
269 menu_pos--;
270 else
271 menu_pos = menu_max;
272 break;
274 case BUTTON_RIGHT:
275 #ifdef HAVE_RECORDER_KEYPAD
276 case BUTTON_DOWN:
277 #endif
278 if (menu_pos < menu_max)
279 menu_pos++;
280 else
281 menu_pos = 0;
282 break;
284 case BUTTON_REPEAT:
285 break;
287 #ifdef BUTTON_STOP
288 case BUTTON_STOP:
289 #else
290 case BUTTON_OFF:
291 #endif
292 case BUTTON_PLAY:
293 lcd_stop_scroll();
294 /* eat release event */
295 button_get(true);
296 exit = true;
297 break;
299 default:
300 if(default_event_handler(button) == SYS_USB_CONNECTED)
301 return true;
302 break;
305 return false;
308 static bool ffwd_rew(int button)
310 static const int ff_rew_steps[] = {
311 1000, 2000, 3000, 4000,
312 5000, 6000, 8000, 10000,
313 15000, 20000, 25000, 30000,
314 45000, 60000
317 unsigned int step = 0; /* current ff/rewind step */
318 unsigned int max_step = 0; /* maximum ff/rewind step */
319 int ff_rewind_count = 0; /* current ff/rewind count (in ticks) */
320 int direction = 1; /* forward=1 or backward=-1 */
321 long accel_tick = 0; /* next time at which to bump the step size */
322 bool exit = false;
323 bool usb = false;
325 while (!exit) {
326 switch ( button ) {
327 case BUTTON_LEFT | BUTTON_REPEAT:
328 case BUTTON_RIGHT | BUTTON_REPEAT:
329 if (ff_rewind)
331 if (direction == 1)
333 /* fast forwarding, calc max step relative to end */
334 max_step =
335 (id3->length - (id3->elapsed + ff_rewind_count)) *
336 FF_REWIND_MAX_PERCENT / 100;
338 else
340 /* rewinding, calc max step relative to start */
341 max_step = (id3->elapsed + ff_rewind_count) *
342 FF_REWIND_MAX_PERCENT / 100;
345 max_step = MAX(max_step, MIN_FF_REWIND_STEP);
347 if (step > max_step)
348 step = max_step;
350 ff_rewind_count += step * direction;
352 if (global_settings.ff_rewind_accel != 0 &&
353 current_tick >= accel_tick)
355 step *= 2;
356 accel_tick = current_tick +
357 global_settings.ff_rewind_accel*HZ;
360 else
362 if ( (mpeg_status() & MPEG_STATUS_PLAY) &&
363 id3 && id3->length )
365 if (!paused)
366 mpeg_pause();
367 #ifdef HAVE_PLAYER_KEYPAD
368 lcd_stop_scroll();
369 #endif
370 direction = (button & BUTTON_RIGHT) ? 1 : -1;
372 if (direction > 0)
373 status_set_ffmode(STATUS_FASTFORWARD);
374 else
375 status_set_ffmode(STATUS_FASTBACKWARD);
377 ff_rewind = true;
379 step = ff_rew_steps[global_settings.ff_rewind_min_step];
381 accel_tick = current_tick +
382 global_settings.ff_rewind_accel*HZ;
384 else
385 break;
388 if (direction > 0) {
389 if ((id3->elapsed + ff_rewind_count) > id3->length)
390 ff_rewind_count = id3->length - id3->elapsed;
392 else {
393 if ((int)(id3->elapsed + ff_rewind_count) < 0)
394 ff_rewind_count = -id3->elapsed;
397 if(wps_time_countup == false)
398 wps_refresh(id3, nid3, -ff_rewind_count,
399 WPS_REFRESH_PLAYER_PROGRESS |
400 WPS_REFRESH_DYNAMIC);
401 else
402 wps_refresh(id3, nid3, ff_rewind_count,
403 WPS_REFRESH_PLAYER_PROGRESS |
404 WPS_REFRESH_DYNAMIC);
406 break;
408 case BUTTON_LEFT | BUTTON_REL:
409 case BUTTON_RIGHT | BUTTON_REL:
410 mpeg_ff_rewind(id3->elapsed+ff_rewind_count);
411 ff_rewind_count = 0;
412 ff_rewind = false;
413 status_set_ffmode(0);
414 if (!paused)
415 mpeg_resume();
416 #ifdef HAVE_LCD_CHARCELLS
417 wps_display(id3, nid3);
418 #endif
419 exit = true;
420 break;
422 default:
423 if(default_event_handler(button) == SYS_USB_CONNECTED) {
424 status_set_ffmode(0);
425 usb = true;
426 exit = true;
428 break;
430 if (!exit)
431 button = button_get(true);
434 /* let mpeg thread update id3->elapsed before calling wps_refresh */
435 yield();
436 wps_refresh(id3, nid3, 0, WPS_REFRESH_ALL);
437 return usb;
440 static bool update(void)
442 bool track_changed = mpeg_has_changed_track();
443 bool retcode = false;
445 nid3 = mpeg_next_track();
446 if (track_changed)
448 lcd_stop_scroll();
449 id3 = mpeg_current_track();
450 if (wps_display(id3, nid3))
451 retcode = true;
452 else
453 wps_refresh(id3, nid3, 0, WPS_REFRESH_ALL);
455 if (id3)
456 memcpy(current_track_path, id3->path, sizeof(current_track_path));
459 if (id3)
460 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC);
462 status_draw(false);
464 /* save resume data */
465 if ( id3 &&
466 global_settings.resume &&
467 global_settings.resume_offset != id3->offset ) {
468 DEBUGF("R%X,%X (%X)\n", global_settings.resume_offset,
469 id3->offset,id3);
471 if (!playlist_get_resume_info(&global_settings.resume_index))
473 global_settings.resume_offset = id3->offset;
474 settings_save();
477 else if ( !id3 && track_changed ) {
478 global_settings.resume_index = -1;
479 global_settings.resume_offset = -1;
480 settings_save();
483 return retcode;
486 static bool menu(void)
488 static bool muted = false;
489 bool exit = false;
490 int last_button = 0;
492 #ifdef HAVE_LCD_CHARCELLS
493 status_set_param(true);
494 status_draw(false);
495 #endif
497 while (!exit) {
498 int button = button_get(true);
500 /* these are never locked */
501 switch (button)
503 /* key lock */
504 #ifdef HAVE_RECORDER_KEYPAD
505 case BUTTON_F1 | BUTTON_DOWN:
506 #else
507 case BUTTON_MENU | BUTTON_STOP:
508 #endif
509 keys_locked = !keys_locked;
510 display_keylock_text(keys_locked);
511 exit = true;
512 while (button_get(false)); /* clear button queue */
513 break;
515 default:
516 if(default_event_handler(button) == SYS_USB_CONNECTED) {
517 keys_locked = false;
518 return true;
520 break;
523 if (keys_locked) {
524 display_keylock_text(true);
525 break;
528 switch ( button ) {
529 /* go into menu */
530 #ifdef HAVE_RECORDER_KEYPAD
531 case BUTTON_F1 | BUTTON_REL:
532 #else
533 case BUTTON_MENU | BUTTON_REL:
534 #endif
535 exit = true;
536 if ( !last_button && !keys_locked ) {
537 lcd_stop_scroll();
539 if (main_menu())
540 return true;
541 #ifdef HAVE_LCD_BITMAP
542 if(global_settings.statusbar)
543 lcd_setmargins(0, STATUSBAR_HEIGHT);
544 else
545 lcd_setmargins(0, 0);
546 #endif
548 break;
550 /* mute */
551 #ifdef BUTTON_MENU
552 case BUTTON_MENU | BUTTON_PLAY:
553 #else
554 case BUTTON_F1 | BUTTON_PLAY:
555 #endif
556 if ( muted )
557 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
558 else
559 mpeg_sound_set(SOUND_VOLUME, 0);
560 muted = !muted;
561 #ifdef HAVE_LCD_CHARCELLS
562 status_set_param(false);
563 #endif
564 display_mute_text(muted);
565 break;
567 #ifdef BUTTON_MENU
568 /* change volume */
569 case BUTTON_MENU | BUTTON_LEFT:
570 case BUTTON_MENU | BUTTON_LEFT | BUTTON_REPEAT:
571 case BUTTON_MENU | BUTTON_RIGHT:
572 case BUTTON_MENU | BUTTON_RIGHT | BUTTON_REPEAT:
573 player_change_volume(button);
574 exit = true;
575 break;
577 /* show id3 tags */
578 #ifdef BUTTON_ON
579 case BUTTON_MENU | BUTTON_ON:
580 #ifdef HAVE_LCD_CHARCELLS
581 status_set_param(true);
582 status_set_audio(true);
583 #endif
584 #endif
585 #else
586 case BUTTON_F1 | BUTTON_ON:
587 #endif
588 lcd_clear_display();
589 lcd_puts(0, 0, str(LANG_ID3_INFO));
590 lcd_puts(0, 1, str(LANG_ID3_SCREEN));
591 lcd_update();
592 sleep(HZ);
594 if(browse_id3())
595 return true;
596 #ifdef HAVE_PLAYER_KEYPAD
597 status_set_param(false);
598 status_set_audio(true);
599 #endif
600 exit = true;
601 break;
603 last_button = button;
606 #ifdef HAVE_LCD_CHARCELLS
607 status_set_param(false);
608 #endif
610 return false;
613 static void fade(bool fade_in)
615 if (fade_in) {
616 /* fade in */
617 int current_volume = 20;
619 /* zero out the sound */
620 mpeg_sound_set(SOUND_VOLUME, current_volume);
622 sleep(HZ/10); /* let mpeg thread run */
623 mpeg_resume();
625 while (current_volume < global_settings.volume) {
626 current_volume += 2;
627 sleep(1);
628 mpeg_sound_set(SOUND_VOLUME, current_volume);
630 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
632 else {
633 /* fade out */
634 int current_volume = global_settings.volume;
636 while (current_volume > 20) {
637 current_volume -= 2;
638 sleep(1);
639 mpeg_sound_set(SOUND_VOLUME, current_volume);
641 mpeg_pause();
642 sleep(HZ/5); /* let mpeg thread run */
644 /* reset volume to what it was before the fade */
645 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
650 /* demonstrates showing different formats from playtune */
651 int wps_show(void)
653 int button = 0, lastbutton = 0;
654 bool ignore_keyup = true;
655 bool restore = false;
656 bool exit = false;
657 bool update_track = false;
659 id3 = nid3 = NULL;
660 current_track_path[0] = '\0';
662 #ifdef HAVE_LCD_CHARCELLS
663 status_set_audio(true);
664 status_set_param(false);
665 #else
666 if(global_settings.statusbar)
667 lcd_setmargins(0, STATUSBAR_HEIGHT);
668 else
669 lcd_setmargins(0, 0);
670 #endif
672 ff_rewind = false;
674 if(mpeg_status() & MPEG_STATUS_PLAY)
676 id3 = mpeg_current_track();
677 nid3 = mpeg_next_track();
678 if (id3) {
679 if (wps_display(id3, nid3))
680 return 0;
681 wps_refresh(id3, nid3, 0, WPS_REFRESH_ALL);
683 memcpy(current_track_path, id3->path, sizeof(current_track_path));
686 restore = true;
689 while ( 1 )
691 bool mpeg_paused = (mpeg_status() & MPEG_STATUS_PAUSE)?true:false;
693 /* did someone else (i.e power thread) change mpeg pause mode? */
694 if (paused != mpeg_paused) {
695 paused = mpeg_paused;
697 /* if another thread paused mpeg, we are probably in car mode,
698 about to shut down. lets save the settings. */
699 if (paused && global_settings.resume) {
700 settings_save();
701 #ifndef HAVE_RTC
702 ata_flush();
703 #endif
707 #ifdef HAVE_LCD_BITMAP
708 /* when the peak meter is enabled we want to have a
709 few extra updates to make it look smooth. On the
710 other hand we don't want to waste energy if it
711 isn't displayed */
712 if (peak_meter_enabled) {
713 int i;
715 /* In high performance mode we read out the mas as
716 often as we can. There is no sleep for cpu */
717 if (global_settings.peak_meter_performance) {
718 long next_refresh = current_tick;
719 long next_big_refresh = current_tick + HZ / 5;
720 button = BUTTON_NONE;
721 while (!TIME_AFTER(current_tick, next_big_refresh)) {
722 button = button_get(false);
723 if (button != BUTTON_NONE) {
724 break;
726 peak_meter_peek();
727 sleep(1);
729 if (TIME_AFTER(current_tick, next_refresh)) {
730 wps_refresh(id3, nid3, 0, WPS_REFRESH_PEAK_METER);
731 next_refresh = current_tick + HZ / peak_meter_fps;
736 /* In energy saver mode the cpu may sleep a
737 little bit while waiting for buttons */
738 else {
739 for (i = 0; i < 4; i++) {
740 button = button_get_w_tmo(HZ / peak_meter_fps);
741 if (button != 0) {
742 break;
744 wps_refresh(id3, nid3, 0, WPS_REFRESH_PEAK_METER);
749 /* The peak meter is disabled
750 -> no additional screen updates needed */
751 else {
752 button = button_get_w_tmo(HZ/5);
754 #else
755 button = button_get_w_tmo(HZ/5);
756 #endif
758 /* discard first event if it's a button release */
759 if (button && ignore_keyup)
761 ignore_keyup = false;
762 /* Negative events are system events */
763 if (button >= 0 && button & BUTTON_REL )
764 continue;
767 /* ignore non-remote buttons when keys are locked */
768 if (keys_locked &&
769 ! ((button < 0) ||
770 #ifdef HAVE_RECORDER_KEYPAD
771 (button & BUTTON_F1) ||
772 #else
773 (button & BUTTON_MENU) ||
774 #endif
775 (button == BUTTON_NONE)
776 #ifdef BUTTON_REMOTE
777 || (button & BUTTON_REMOTE)
778 #endif
781 while (button_get(false)); /* clear button queue */
782 display_keylock_text(true);
783 restore = true;
784 continue;
787 /* Exit if mpeg has stopped playing. This can happen if using the
788 sleep timer with the charger plugged or if starting a recording
789 from F1 */
790 if (!mpeg_status())
791 exit = true;
793 switch(button)
795 #ifdef BUTTON_ON
796 case BUTTON_ON:
797 #ifdef HAVE_RECORDER_KEYPAD
798 switch (on_screen()) {
799 case 2:
800 /* usb connected? */
801 return SYS_USB_CONNECTED;
803 case 1:
804 /* was on_screen used? */
805 restore = true;
807 /* pause may have been turned off by pitch screen */
808 if (paused && !(mpeg_status() & MPEG_STATUS_PAUSE)) {
809 paused = false;
811 break;
813 case 0:
814 /* otherwise, exit to browser */
815 #else
816 #ifdef HAVE_LCD_CHARCELLS
817 status_set_record(false);
818 status_set_audio(false);
819 #endif
820 #endif
821 lcd_stop_scroll();
823 /* set dir browser to current playing song */
824 if (global_settings.browse_current &&
825 current_track_path[0] != '\0')
826 set_current_file(current_track_path);
828 return 0;
829 #ifdef HAVE_RECORDER_KEYPAD
831 break;
832 #endif
833 #endif /* BUTTON_ON */
834 /* play/pause */
835 case BUTTON_PLAY:
836 #ifdef BUTTON_RC_PLAY
837 case BUTTON_RC_PLAY:
838 #endif
839 if ( paused )
841 paused = false;
842 if ( global_settings.fade_on_stop )
843 fade(1);
844 else
845 mpeg_resume();
847 else
849 paused = true;
850 if ( global_settings.fade_on_stop )
851 fade(0);
852 else
853 mpeg_pause();
854 if (global_settings.resume) {
855 settings_save();
856 #ifndef HAVE_RTC
857 ata_flush();
858 #endif
861 break;
863 /* volume up */
864 #ifdef HAVE_RECORDER_KEYPAD
865 case BUTTON_UP:
866 case BUTTON_UP | BUTTON_REPEAT:
867 #endif
868 #ifdef BUTTON_RC_VOL_UP
869 case BUTTON_RC_VOL_UP:
870 #endif
871 global_settings.volume++;
872 if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
873 global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
874 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
875 status_draw(false);
876 settings_save();
877 break;
879 /* volume down */
880 #ifdef HAVE_RECORDER_KEYPAD
881 case BUTTON_DOWN:
882 case BUTTON_DOWN | BUTTON_REPEAT:
883 #endif
884 #ifdef BUTTON_RC_VOL_DOWN
885 case BUTTON_RC_VOL_DOWN:
886 #endif
887 global_settings.volume--;
888 if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
889 global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
890 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
891 status_draw(false);
892 settings_save();
893 break;
895 /* fast forward / rewind */
896 case BUTTON_LEFT | BUTTON_REPEAT:
897 case BUTTON_RIGHT | BUTTON_REPEAT:
898 ffwd_rew(button);
899 break;
901 /* prev / restart */
902 #ifdef BUTTON_RC_LEFT
903 case BUTTON_RC_LEFT:
904 #endif
905 case BUTTON_LEFT | BUTTON_REL:
906 #ifdef HAVE_RECORDER_KEYPAD
907 if ((button == (BUTTON_LEFT | BUTTON_REL)) &&
908 (lastbutton != BUTTON_LEFT ))
909 break;
910 #endif
911 if (!id3 || (id3->elapsed < 3*1000)) {
912 mpeg_prev();
914 else {
915 if (!paused)
916 mpeg_pause();
918 mpeg_ff_rewind(0);
920 if (!paused)
921 mpeg_resume();
923 break;
925 /* next */
926 #ifdef BUTTON_RC_RIGHT
927 case BUTTON_RC_RIGHT:
928 #endif
929 case BUTTON_RIGHT | BUTTON_REL:
930 #ifdef HAVE_RECORDER_KEYPAD
931 if ((button == (BUTTON_RIGHT | BUTTON_REL)) &&
932 (lastbutton != BUTTON_RIGHT))
933 break;
934 #endif
935 mpeg_next();
936 break;
938 /* menu key functions */
939 #ifdef BUTTON_MENU
940 case BUTTON_MENU:
941 #else
942 case BUTTON_F1:
943 #endif
944 if (menu())
945 return SYS_USB_CONNECTED;
947 update_track = true;
948 restore = true;
949 break;
951 #ifdef HAVE_RECORDER_KEYPAD
952 /* play settings */
953 case BUTTON_F2:
954 if (quick_screen(CONTEXT_WPS, BUTTON_F2))
955 return SYS_USB_CONNECTED;
956 restore = true;
957 break;
959 /* screen settings */
960 case BUTTON_F3:
961 if (quick_screen(CONTEXT_WPS, BUTTON_F3))
962 return SYS_USB_CONNECTED;
963 restore = true;
964 break;
965 #endif
967 /* stop and exit wps */
968 #ifdef BUTTON_OFF
969 case BUTTON_OFF | BUTTON_REL:
970 #else
971 case BUTTON_STOP | BUTTON_REL:
972 if ( lastbutton != BUTTON_STOP )
973 break;
974 #endif
975 #ifdef BUTTON_RC_STOP
976 case BUTTON_RC_STOP:
977 #endif
978 exit = true;
979 break;
981 case BUTTON_NONE: /* Timeout */
982 update_track = true;
983 break;
985 default:
986 if(default_event_handler(button) == SYS_USB_CONNECTED)
987 return SYS_USB_CONNECTED;
988 break;
991 if (update_track)
993 if (update())
995 /* set dir browser to current playing song */
996 if (global_settings.browse_current &&
997 current_track_path[0] != '\0')
998 set_current_file(current_track_path);
1000 return 0;
1002 update_track = false;
1005 if (exit) {
1006 #ifdef HAVE_LCD_CHARCELLS
1007 status_set_record(false);
1008 status_set_audio(false);
1009 #endif
1010 if (global_settings.fade_on_stop)
1011 fade(0);
1013 lcd_stop_scroll();
1014 bookmark_autobookmark();
1015 mpeg_stop();
1017 /* Keys can be locked when exiting, so either unlock here
1018 or implement key locking in tree.c too */
1019 keys_locked=false;
1021 /* set dir browser to current playing song */
1022 if (global_settings.browse_current &&
1023 current_track_path[0] != '\0')
1024 set_current_file(current_track_path);
1026 return 0;
1029 if ( button )
1030 ata_spin();
1032 if (restore) {
1033 restore = false;
1034 if (wps_display(id3, nid3))
1036 /* set dir browser to current playing song */
1037 if (global_settings.browse_current &&
1038 current_track_path[0] != '\0')
1039 set_current_file(current_track_path);
1041 return 0;
1044 if (id3)
1045 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC);
1047 if(button != BUTTON_NONE)
1048 lastbutton = button;
1050 return 0; /* unreachable - just to reduce compiler warnings */