diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-09-26 10:03:56 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-09-26 10:03:56 +0000 |
commit | 537c7546f946d266e55fdbce03558352a3342908 (patch) | |
tree | 9e594c9d40ec54047fa858472f737bc4d7b7d406 | |
parent | 9f960e405f72e1f624797547e1ad8e9584206118 (diff) | |
download | rockbox-537c7546f946d266e55fdbce03558352a3342908.tar.gz rockbox-537c7546f946d266e55fdbce03558352a3342908.zip |
Patch #4899 by Robert Keevil - Automatic pause on iPod when removing the headphones
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11057 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs.c | 1 | ||||
-rw-r--r-- | apps/codecs.h | 1 | ||||
-rw-r--r-- | apps/lang/english.lang | 56 | ||||
-rw-r--r-- | apps/misc.c | 36 | ||||
-rw-r--r-- | apps/settings.c | 6 | ||||
-rw-r--r-- | apps/settings.h | 6 | ||||
-rw-r--r-- | apps/settings_menu.c | 56 | ||||
-rw-r--r-- | apps/tree.c | 15 | ||||
-rw-r--r-- | firmware/drivers/button.c | 28 | ||||
-rw-r--r-- | firmware/export/button.h | 3 | ||||
-rw-r--r-- | firmware/export/config-ipod4g.h | 3 | ||||
-rw-r--r-- | firmware/export/config-ipodcolor.h | 3 | ||||
-rw-r--r-- | firmware/export/config-ipodnano.h | 3 | ||||
-rw-r--r-- | firmware/export/config-ipodvideo.h | 3 | ||||
-rw-r--r-- | firmware/export/kernel.h | 2 |
15 files changed, 220 insertions, 2 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index b4b8c9833a..d9bda6b0a6 100644 --- a/apps/codecs.c +++ b/apps/codecs.c | |||
@@ -218,6 +218,7 @@ struct codec_api ci = { | |||
218 | enc_wavbuf_near_empty, | 218 | enc_wavbuf_near_empty, |
219 | enc_get_wav_data, | 219 | enc_get_wav_data, |
220 | &enc_set_header_callback, | 220 | &enc_set_header_callback, |
221 | 44100, | ||
221 | #endif | 222 | #endif |
222 | 223 | ||
223 | /* new stuff at the end, sort into place next time | 224 | /* new stuff at the end, sort into place next time |
diff --git a/apps/codecs.h b/apps/codecs.h index 96804a889b..7cd48f65e2 100644 --- a/apps/codecs.h +++ b/apps/codecs.h | |||
@@ -303,6 +303,7 @@ struct codec_api { | |||
303 | char* (*enc_get_wav_data)(int size); | 303 | char* (*enc_get_wav_data)(int size); |
304 | void (**enc_set_header_callback)(void *head_buffer, | 304 | void (**enc_set_header_callback)(void *head_buffer, |
305 | int head_size, int num_samples, bool is_file_header); | 305 | int head_size, int num_samples, bool is_file_header); |
306 | int sample_rate; | ||
306 | #endif | 307 | #endif |
307 | 308 | ||
308 | /* new stuff at the end, sort into place next time | 309 | /* new stuff at the end, sort into place next time |
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 9e6a809dac..4dfbff7ad5 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -9806,3 +9806,59 @@ | |||
9806 | *: "" | 9806 | *: "" |
9807 | </voice> | 9807 | </voice> |
9808 | </phrase> | 9808 | </phrase> |
9809 | <phrase> | ||
9810 | id: LANG_UNPLUG | ||
9811 | desc: in settings_menu. | ||
9812 | user: | ||
9813 | <source> | ||
9814 | *: "Pause on headphone unplug" | ||
9815 | </source> | ||
9816 | <dest> | ||
9817 | *: "Pause on headphone unplug" | ||
9818 | </dest> | ||
9819 | <voice> | ||
9820 | *: "Pause on headphone unplug" | ||
9821 | </voice> | ||
9822 | </phrase> | ||
9823 | <phrase> | ||
9824 | id: LANG_UNPLUG_RESUME | ||
9825 | desc: in pause_phones_menu. | ||
9826 | user: | ||
9827 | <source> | ||
9828 | *: "Pause and Resume" | ||
9829 | </source> | ||
9830 | <dest> | ||
9831 | *: "Pause and Resume" | ||
9832 | </dest> | ||
9833 | <voice> | ||
9834 | *: "Pause and Resume" | ||
9835 | </voice> | ||
9836 | </phrase> | ||
9837 | <phrase> | ||
9838 | id: LANG_UNPLUG_RW | ||
9839 | desc: in pause_phones_menu. | ||
9840 | user: | ||
9841 | <source> | ||
9842 | *: "Duration to rewind" | ||
9843 | </source> | ||
9844 | <dest> | ||
9845 | *: "Duration to rewind" | ||
9846 | </dest> | ||
9847 | <voice> | ||
9848 | *: "Duration to rewind" | ||
9849 | </voice> | ||
9850 | </phrase> | ||
9851 | <phrase> | ||
9852 | id: LANG_UNPLUG_DISABLE_AUTORESUME | ||
9853 | desc: in pause_phones_menu. | ||
9854 | user: | ||
9855 | <source> | ||
9856 | *: "Disable auto-resume if phones not present" | ||
9857 | </source> | ||
9858 | <dest> | ||
9859 | *: "Disable auto-resume if phones not present" | ||
9860 | </dest> | ||
9861 | <voice> | ||
9862 | *: "Disable auto-resume if phones not present" | ||
9863 | </voice> | ||
9864 | </phrase> | ||
diff --git a/apps/misc.c b/apps/misc.c index e95c5e5650..806f5ff63e 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -580,6 +580,33 @@ void car_adapter_mode_init(void) | |||
580 | } | 580 | } |
581 | #endif | 581 | #endif |
582 | 582 | ||
583 | #ifdef HAVE_HEADPHONE_DETECTION | ||
584 | void unplug_change(bool inserted) | ||
585 | { | ||
586 | if (global_settings.unplug_mode) | ||
587 | { | ||
588 | if (inserted) | ||
589 | { | ||
590 | if ( global_settings.unplug_mode > 1 ) | ||
591 | audio_resume(); | ||
592 | backlight_on(); | ||
593 | } else { | ||
594 | audio_pause(); | ||
595 | |||
596 | if (global_settings.unplug_rw) | ||
597 | { | ||
598 | if ( audio_current_track()->elapsed > | ||
599 | (unsigned long)(global_settings.unplug_rw*1000)) | ||
600 | audio_ff_rewind(audio_current_track()->elapsed - | ||
601 | (global_settings.unplug_rw*1000)); | ||
602 | else | ||
603 | audio_ff_rewind(0); | ||
604 | } | ||
605 | } | ||
606 | } | ||
607 | } | ||
608 | #endif | ||
609 | |||
583 | long default_event_handler_ex(long event, void (*callback)(void *), void *parameter) | 610 | long default_event_handler_ex(long event, void (*callback)(void *), void *parameter) |
584 | { | 611 | { |
585 | switch(event) | 612 | switch(event) |
@@ -609,6 +636,15 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame | |||
609 | car_adapter_mode_processing(false); | 636 | car_adapter_mode_processing(false); |
610 | return SYS_CHARGER_DISCONNECTED; | 637 | return SYS_CHARGER_DISCONNECTED; |
611 | #endif | 638 | #endif |
639 | #ifdef HAVE_HEADPHONE_DETECTION | ||
640 | case SYS_PHONE_PLUGGED: | ||
641 | unplug_change(true); | ||
642 | return SYS_PHONE_PLUGGED; | ||
643 | |||
644 | case SYS_PHONE_UNPLUGGED: | ||
645 | unplug_change(false); | ||
646 | return SYS_PHONE_UNPLUGGED; | ||
647 | #endif | ||
612 | } | 648 | } |
613 | return 0; | 649 | return 0; |
614 | } | 650 | } |
diff --git a/apps/settings.c b/apps/settings.c index 3dc4ee1530..4746c22c87 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -655,6 +655,12 @@ static const struct bit_entry hd_bits[] = | |||
655 | #endif | 655 | #endif |
656 | #endif | 656 | #endif |
657 | 657 | ||
658 | #ifdef HAVE_HEADPHONE_DETECTION | ||
659 | {2, S_O(unplug_mode), 0, "pause on headphone unplug", NULL}, | ||
660 | {4, S_O(unplug_rw), 0, "rewind duration on pause", NULL}, | ||
661 | {1, S_O(unplug_autoresume), 0, "disable autoresume if phones not present", off_on }, | ||
662 | #endif | ||
663 | |||
658 | /* If values are just added to the end, no need to bump the version. */ | 664 | /* If values are just added to the end, no need to bump the version. */ |
659 | /* new stuff to be added at the end */ | 665 | /* new stuff to be added at the end */ |
660 | 666 | ||
diff --git a/apps/settings.h b/apps/settings.h index 561dc59375..9f8372415a 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -486,6 +486,12 @@ struct user_settings | |||
486 | #endif | 486 | #endif |
487 | bool hold_lr_for_scroll_in_list; /* hold L/R scrolls the list left/right */ | 487 | bool hold_lr_for_scroll_in_list; /* hold L/R scrolls the list left/right */ |
488 | int show_path_in_browser; /* 0=off, 1=current directory, 2=full path */ | 488 | int show_path_in_browser; /* 0=off, 1=current directory, 2=full path */ |
489 | |||
490 | #ifdef HAVE_HEADPHONE_DETECTION | ||
491 | int unplug_mode; /* pause on headphone unplug */ | ||
492 | int unplug_rw; /* time in s to rewind when pausing */ | ||
493 | bool unplug_autoresume; /* disable auto-resume if no phones */ | ||
494 | #endif | ||
489 | }; | 495 | }; |
490 | 496 | ||
491 | enum optiontype { INT, BOOL }; | 497 | enum optiontype { INT, BOOL }; |
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 8f9fbe1c62..36615cfc6a 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -1664,6 +1664,57 @@ static bool tagcache_settings_menu(void) | |||
1664 | return result; | 1664 | return result; |
1665 | } | 1665 | } |
1666 | 1666 | ||
1667 | #ifdef HAVE_HEADPHONE_DETECTION | ||
1668 | static bool unplug_mode(void) | ||
1669 | { | ||
1670 | static const struct opt_items names[] = { | ||
1671 | { STR(LANG_OFF) }, | ||
1672 | { STR(LANG_PAUSE) }, | ||
1673 | { STR(LANG_UNPLUG_RESUME) }, | ||
1674 | }; | ||
1675 | bool ret; | ||
1676 | ret=set_option( str(LANG_UNPLUG), | ||
1677 | &global_settings.unplug_mode, INT, names, 3, NULL); | ||
1678 | |||
1679 | return ret; | ||
1680 | } | ||
1681 | |||
1682 | static bool unplug_rw(void) | ||
1683 | { | ||
1684 | bool ret; | ||
1685 | |||
1686 | ret = set_int(str(LANG_UNPLUG_RW), "s", UNIT_SEC, | ||
1687 | &global_settings.unplug_rw, | ||
1688 | NULL, 1, 0, 15, NULL ); | ||
1689 | audio_set_crossfade(global_settings.unplug_rw); | ||
1690 | return ret; | ||
1691 | } | ||
1692 | |||
1693 | static bool unplug_autoresume(void) | ||
1694 | { | ||
1695 | return set_bool( str(LANG_UNPLUG_DISABLE_AUTORESUME), | ||
1696 | &global_settings.unplug_autoresume ); | ||
1697 | } | ||
1698 | |||
1699 | static bool unplug_menu(void) | ||
1700 | { | ||
1701 | int m; | ||
1702 | bool result; | ||
1703 | |||
1704 | static const struct menu_item items[] = { | ||
1705 | { ID2P(LANG_UNPLUG), unplug_mode }, | ||
1706 | { ID2P(LANG_UNPLUG_RW), unplug_rw }, | ||
1707 | { ID2P(LANG_UNPLUG_DISABLE_AUTORESUME), unplug_autoresume }, | ||
1708 | }; | ||
1709 | |||
1710 | m=menu_init( items, sizeof(items) / sizeof(*items), NULL, | ||
1711 | NULL, NULL, NULL); | ||
1712 | result = menu_run(m); | ||
1713 | menu_exit(m); | ||
1714 | return result; | ||
1715 | } | ||
1716 | #endif | ||
1717 | |||
1667 | static bool playback_settings_menu(void) | 1718 | static bool playback_settings_menu(void) |
1668 | { | 1719 | { |
1669 | int m; | 1720 | int m; |
@@ -1687,7 +1738,10 @@ static bool playback_settings_menu(void) | |||
1687 | { ID2P(LANG_SPDIF_ENABLE), spdif }, | 1738 | { ID2P(LANG_SPDIF_ENABLE), spdif }, |
1688 | #endif | 1739 | #endif |
1689 | { ID2P(LANG_ID3_ORDER), id3_order }, | 1740 | { ID2P(LANG_ID3_ORDER), id3_order }, |
1690 | { ID2P(LANG_NEXT_FOLDER), next_folder } | 1741 | { ID2P(LANG_NEXT_FOLDER), next_folder }, |
1742 | #ifdef HAVE_HEADPHONE_DETECTION | ||
1743 | { ID2P(LANG_UNPLUG), unplug_menu } | ||
1744 | #endif | ||
1691 | }; | 1745 | }; |
1692 | 1746 | ||
1693 | bool old_shuffle = global_settings.playlist_shuffle; | 1747 | bool old_shuffle = global_settings.playlist_shuffle; |
diff --git a/apps/tree.c b/apps/tree.c index 3ee3061540..0e2dcb6c87 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -466,7 +466,20 @@ static void start_resume(bool just_powered_on) | |||
466 | 466 | ||
467 | /* always resume? */ | 467 | /* always resume? */ |
468 | if ( global_settings.resume || ! just_powered_on) | 468 | if ( global_settings.resume || ! just_powered_on) |
469 | do_resume = true; | 469 | #ifdef HAVE_HEADPHONE_DETECTION |
470 | { | ||
471 | if ( just_powered_on ) | ||
472 | { | ||
473 | if ( !global_settings.unplug_autoresume | ||
474 | || headphones_inserted() ) | ||
475 | do_resume = true; | ||
476 | } | ||
477 | else | ||
478 | do_resume = true; | ||
479 | } | ||
480 | #else | ||
481 | do_resume = true; | ||
482 | #endif | ||
470 | 483 | ||
471 | if (! do_resume) return; | 484 | if (! do_resume) return; |
472 | 485 | ||
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 5add6cb817..0042d9b8eb 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -92,6 +92,10 @@ static bool remote_button_hold_only(void); | |||
92 | int int_btn = BUTTON_NONE; | 92 | int int_btn = BUTTON_NONE; |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | #ifdef HAVE_HEADPHONE_DETECTION | ||
96 | bool phones_present = false; | ||
97 | #endif | ||
98 | |||
95 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) && !defined(IPOD_MINI) | 99 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) && !defined(IPOD_MINI) |
96 | static void opto_i2c_init(void) | 100 | static void opto_i2c_init(void) |
97 | { | 101 | { |
@@ -433,6 +437,23 @@ static void button_tick(void) | |||
433 | } | 437 | } |
434 | #endif | 438 | #endif |
435 | 439 | ||
440 | #ifdef HAVE_HEADPHONE_DETECTION | ||
441 | if ( headphones_inserted() ) | ||
442 | { | ||
443 | if (! phones_present ) | ||
444 | { | ||
445 | queue_post(&button_queue, SYS_PHONE_PLUGGED, NULL); | ||
446 | phones_present = true; | ||
447 | } | ||
448 | } else { | ||
449 | if ( phones_present ) | ||
450 | { | ||
451 | queue_post(&button_queue, SYS_PHONE_UNPLUGGED, NULL); | ||
452 | phones_present = false; | ||
453 | } | ||
454 | } | ||
455 | #endif | ||
456 | |||
436 | btn = button_read(); | 457 | btn = button_read(); |
437 | 458 | ||
438 | /* Find out if a key has been released */ | 459 | /* Find out if a key has been released */ |
@@ -1327,3 +1348,10 @@ void button_clear_queue(void) | |||
1327 | queue_clear(&button_queue); | 1348 | queue_clear(&button_queue); |
1328 | } | 1349 | } |
1329 | 1350 | ||
1351 | #ifdef HAVE_HEADPHONE_DETECTION | ||
1352 | bool headphones_inserted(void) | ||
1353 | { | ||
1354 | return (GPIOA_INPUT_VAL & 0x80)?true:false; | ||
1355 | } | ||
1356 | #endif | ||
1357 | |||
diff --git a/firmware/export/button.h b/firmware/export/button.h index 0e11da9da5..39dfbff6fa 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h | |||
@@ -54,6 +54,9 @@ bool button_hold(void); | |||
54 | #ifdef HAS_REMOTE_BUTTON_HOLD | 54 | #ifdef HAS_REMOTE_BUTTON_HOLD |
55 | bool remote_button_hold(void); | 55 | bool remote_button_hold(void); |
56 | #endif | 56 | #endif |
57 | #ifdef HAVE_HEADPHONE_DETECTION | ||
58 | bool headphones_inserted(void); | ||
59 | #endif | ||
57 | 60 | ||
58 | 61 | ||
59 | #define BUTTON_NONE 0x00000000 | 62 | #define BUTTON_NONE 0x00000000 |
diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h index a5f186782f..2e8c4dcc33 100644 --- a/firmware/export/config-ipod4g.h +++ b/firmware/export/config-ipod4g.h | |||
@@ -109,6 +109,9 @@ | |||
109 | /* Define this if you have adjustable CPU frequency */ | 109 | /* Define this if you have adjustable CPU frequency */ |
110 | #define HAVE_ADJUSTABLE_CPU_FREQ | 110 | #define HAVE_ADJUSTABLE_CPU_FREQ |
111 | 111 | ||
112 | /* Define this if you can detect headphones */ | ||
113 | #define HAVE_HEADPHONE_DETECTION | ||
114 | |||
112 | #define BOOTFILE_EXT "ipod" | 115 | #define BOOTFILE_EXT "ipod" |
113 | #define BOOTFILE "rockbox." BOOTFILE_EXT | 116 | #define BOOTFILE "rockbox." BOOTFILE_EXT |
114 | 117 | ||
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h index 3366baa8ea..964f103214 100644 --- a/firmware/export/config-ipodcolor.h +++ b/firmware/export/config-ipodcolor.h | |||
@@ -105,6 +105,9 @@ | |||
105 | /* Define this if you have adjustable CPU frequency */ | 105 | /* Define this if you have adjustable CPU frequency */ |
106 | #define HAVE_ADJUSTABLE_CPU_FREQ | 106 | #define HAVE_ADJUSTABLE_CPU_FREQ |
107 | 107 | ||
108 | /* Define this if you can detect headphones */ | ||
109 | #define HAVE_HEADPHONE_DETECTION | ||
110 | |||
108 | #define BOOTFILE_EXT "ipod" | 111 | #define BOOTFILE_EXT "ipod" |
109 | #define BOOTFILE "rockbox." BOOTFILE_EXT | 112 | #define BOOTFILE "rockbox." BOOTFILE_EXT |
110 | 113 | ||
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h index c077c381f8..03f5b8c753 100644 --- a/firmware/export/config-ipodnano.h +++ b/firmware/export/config-ipodnano.h | |||
@@ -110,6 +110,9 @@ | |||
110 | /* Define this if you have adjustable CPU frequency */ | 110 | /* Define this if you have adjustable CPU frequency */ |
111 | #define HAVE_ADJUSTABLE_CPU_FREQ | 111 | #define HAVE_ADJUSTABLE_CPU_FREQ |
112 | 112 | ||
113 | /* Define this if you can detect headphones */ | ||
114 | #define HAVE_HEADPHONE_DETECTION | ||
115 | |||
113 | #define BOOTFILE_EXT "ipod" | 116 | #define BOOTFILE_EXT "ipod" |
114 | #define BOOTFILE "rockbox." BOOTFILE_EXT | 117 | #define BOOTFILE "rockbox." BOOTFILE_EXT |
115 | 118 | ||
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h index 5cea64deb4..4781a2c887 100644 --- a/firmware/export/config-ipodvideo.h +++ b/firmware/export/config-ipodvideo.h | |||
@@ -110,6 +110,9 @@ | |||
110 | /* Define this if you have adjustable CPU frequency */ | 110 | /* Define this if you have adjustable CPU frequency */ |
111 | #define HAVE_ADJUSTABLE_CPU_FREQ | 111 | #define HAVE_ADJUSTABLE_CPU_FREQ |
112 | 112 | ||
113 | /* Define this if you can detect headphones */ | ||
114 | #define HAVE_HEADPHONE_DETECTION | ||
115 | |||
113 | #define BOOTFILE_EXT "ipod" | 116 | #define BOOTFILE_EXT "ipod" |
114 | #define BOOTFILE "rockbox." BOOTFILE_EXT | 117 | #define BOOTFILE "rockbox." BOOTFILE_EXT |
115 | 118 | ||
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 482516b9dc..fcab2d923c 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h | |||
@@ -46,6 +46,8 @@ | |||
46 | #define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27))) | 46 | #define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27))) |
47 | #define SYS_CHARGER_CONNECTED ((SYS_EVENT | ((long)10 << 27))) | 47 | #define SYS_CHARGER_CONNECTED ((SYS_EVENT | ((long)10 << 27))) |
48 | #define SYS_CHARGER_DISCONNECTED ((SYS_EVENT | ((long)11 << 27))) | 48 | #define SYS_CHARGER_DISCONNECTED ((SYS_EVENT | ((long)11 << 27))) |
49 | #define SYS_PHONE_PLUGGED ((SYS_EVENT | ((long)12 << 27))) | ||
50 | #define SYS_PHONE_UNPLUGGED ((SYS_EVENT | ((long)13 << 27))) | ||
49 | 51 | ||
50 | struct event | 52 | struct event |
51 | { | 53 | { |