diff options
author | William Wilgus <wilgus.william@gmail.com> | 2023-03-20 22:15:33 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2023-03-25 10:02:43 -0400 |
commit | a2e5d9563f9dec84907f4f2060af6dfad895c4ba (patch) | |
tree | e2c27f4fca350e1f1ce8ba2ef8fe30fbb341c3c0 | |
parent | 2e99e2175b48cc00274b03bb4aecf5d01403110d (diff) | |
download | rockbox-a2e5d9563f9dec84907f4f2060af6dfad895c4ba.tar.gz rockbox-a2e5d9563f9dec84907f4f2060af6dfad895c4ba.zip |
[Feature] resume TSR plugins after interruption WIP
save tsr plugin path for later
resume tsr plugin when user stops the interrupting plugin
expand return of tsr_exit function to allow
continue, suspend, terminate
tsr plugins check parameter at start to determine if
the plugin is being resumed
Change-Id: I6fc70de664c7771e7dbc9a1af7a831e7b50b1d15
-rw-r--r-- | apps/plugin.c | 51 | ||||
-rw-r--r-- | apps/plugin.h | 30 | ||||
-rw-r--r-- | apps/plugins/announce_status.c | 107 | ||||
-rw-r--r-- | apps/plugins/battery_bench.c | 68 | ||||
-rw-r--r-- | apps/plugins/lastfm_scrobbler.c | 32 | ||||
-rw-r--r-- | apps/plugins/test_usb.c | 13 |
6 files changed, 177 insertions, 124 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 3db4bb2d80..cd58209fb7 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -74,7 +74,7 @@ extern unsigned char pluginbuf[]; | |||
74 | 74 | ||
75 | /* for actual plugins only, not for codecs */ | 75 | /* for actual plugins only, not for codecs */ |
76 | static int plugin_size = 0; | 76 | static int plugin_size = 0; |
77 | static bool (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */ | 77 | static int (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */ |
78 | static char current_plugin[MAX_PATH]; | 78 | static char current_plugin[MAX_PATH]; |
79 | /* NULL if no plugin is loaded, otherwise the handle that lc_open() returned */ | 79 | /* NULL if no plugin is loaded, otherwise the handle that lc_open() returned */ |
80 | static void *current_plugin_handle; | 80 | static void *current_plugin_handle; |
@@ -83,7 +83,7 @@ char *plugin_get_current_filename(void); | |||
83 | 83 | ||
84 | static void* plugin_get_audio_buffer(size_t *buffer_size); | 84 | static void* plugin_get_audio_buffer(size_t *buffer_size); |
85 | static void plugin_release_audio_buffer(void); | 85 | static void plugin_release_audio_buffer(void); |
86 | static void plugin_tsr(bool (*exit_callback)(bool)); | 86 | static void plugin_tsr(int (*exit_callback)(bool)); |
87 | 87 | ||
88 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE | 88 | #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE |
89 | /* File handle leak prophylaxis */ | 89 | /* File handle leak prophylaxis */ |
@@ -183,6 +183,8 @@ static const struct plugin_api rockbox_api = { | |||
183 | /* lcd */ | 183 | /* lcd */ |
184 | splash, | 184 | splash, |
185 | splashf, | 185 | splashf, |
186 | splash_progress, | ||
187 | splash_progress_set_delay, | ||
186 | #ifdef HAVE_LCD_CONTRAST | 188 | #ifdef HAVE_LCD_CONTRAST |
187 | lcd_set_contrast, | 189 | lcd_set_contrast, |
188 | #endif | 190 | #endif |
@@ -436,6 +438,7 @@ static const struct plugin_api rockbox_api = { | |||
436 | set_current_file, | 438 | set_current_file, |
437 | set_dirfilter, | 439 | set_dirfilter, |
438 | onplay_show_playlist_menu, | 440 | onplay_show_playlist_menu, |
441 | onplay_show_playlist_cat_menu, | ||
439 | browse_id3, | 442 | browse_id3, |
440 | 443 | ||
441 | /* talking */ | 444 | /* talking */ |
@@ -587,6 +590,7 @@ static const struct plugin_api rockbox_api = { | |||
587 | buflib_get_data, | 590 | buflib_get_data, |
588 | 591 | ||
589 | /* sound */ | 592 | /* sound */ |
593 | adjust_volume, | ||
590 | sound_set, | 594 | sound_set, |
591 | sound_current, /*stub*/ | 595 | sound_current, /*stub*/ |
592 | sound_default, | 596 | sound_default, |
@@ -674,6 +678,7 @@ static const struct plugin_api rockbox_api = { | |||
674 | tagcache_fill_tags, | 678 | tagcache_fill_tags, |
675 | #endif | 679 | #endif |
676 | #endif | 680 | #endif |
681 | tagtree_subentries_do_action, | ||
677 | #endif /* HAVE_TAGCACHE */ | 682 | #endif /* HAVE_TAGCACHE */ |
678 | 683 | ||
679 | #ifdef HAVE_ALBUMART | 684 | #ifdef HAVE_ALBUMART |
@@ -685,6 +690,7 @@ static const struct plugin_api rockbox_api = { | |||
685 | playlist_amount, | 690 | playlist_amount, |
686 | playlist_resume, | 691 | playlist_resume, |
687 | playlist_resume_track, | 692 | playlist_resume_track, |
693 | playlist_set_modified, | ||
688 | playlist_start, | 694 | playlist_start, |
689 | playlist_add, | 695 | playlist_add, |
690 | playlist_sync, | 696 | playlist_sync, |
@@ -814,6 +820,7 @@ static const struct plugin_api rockbox_api = { | |||
814 | sys_reboot, | 820 | sys_reboot, |
815 | 821 | ||
816 | /* pathfuncs */ | 822 | /* pathfuncs */ |
823 | fix_path_part, | ||
817 | #ifdef HAVE_MULTIVOLUME | 824 | #ifdef HAVE_MULTIVOLUME |
818 | path_strip_volume, | 825 | path_strip_volume, |
819 | #endif | 826 | #endif |
@@ -821,15 +828,6 @@ static const struct plugin_api rockbox_api = { | |||
821 | /* new stuff at the end, sort into place next time | 828 | /* new stuff at the end, sort into place next time |
822 | the API gets incompatible */ | 829 | the API gets incompatible */ |
823 | 830 | ||
824 | splash_progress, | ||
825 | splash_progress_set_delay, | ||
826 | fix_path_part, | ||
827 | onplay_show_playlist_cat_menu, | ||
828 | #if defined(HAVE_TAGCACHE) | ||
829 | tagtree_subentries_do_action, | ||
830 | #endif | ||
831 | adjust_volume, | ||
832 | playlist_set_modified, | ||
833 | }; | 831 | }; |
834 | 832 | ||
835 | static int plugin_buffer_handle; | 833 | static int plugin_buffer_handle; |
@@ -839,17 +837,31 @@ int plugin_load(const char* plugin, const void* parameter) | |||
839 | { | 837 | { |
840 | struct plugin_header *p_hdr; | 838 | struct plugin_header *p_hdr; |
841 | struct lc_header *hdr; | 839 | struct lc_header *hdr; |
840 | const char * resume_plugin = NULL; | ||
841 | |||
842 | if (!plugin) | ||
843 | return PLUGIN_ERROR; | ||
842 | 844 | ||
843 | if (current_plugin_handle && pfn_tsr_exit) | 845 | if (current_plugin_handle && pfn_tsr_exit) |
844 | { /* if we have a resident old plugin and a callback */ | 846 | { /* if we have a resident old plugin and a callback */ |
845 | if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false ) | 847 | bool reenter = (strcmp(current_plugin, plugin) == 0); |
848 | int exit_status = pfn_tsr_exit(reenter); | ||
849 | if (exit_status == PLUGIN_TSR_CONTINUE) | ||
846 | { | 850 | { |
847 | /* not allowing another plugin to load */ | 851 | /* not allowing another plugin to load */ |
848 | return PLUGIN_OK; | 852 | return PLUGIN_OK; |
849 | } | 853 | } |
850 | lc_close(current_plugin_handle); | 854 | else |
851 | current_plugin_handle = pfn_tsr_exit = NULL; | 855 | { |
852 | plugin_buffer_handle = core_free(plugin_buffer_handle); | 856 | lc_close(current_plugin_handle); |
857 | current_plugin_handle = pfn_tsr_exit = NULL; | ||
858 | plugin_buffer_handle = core_free(plugin_buffer_handle); | ||
859 | |||
860 | if (!reenter) | ||
861 | resume_plugin = strdupa(current_plugin); | ||
862 | else if (exit_status == PLUGIN_TSR_TERMINATE) | ||
863 | return PLUGIN_OK; /* don't even load the new plugin either */ | ||
864 | } | ||
853 | } | 865 | } |
854 | 866 | ||
855 | #ifdef HAVE_DISK_STORAGE | 867 | #ifdef HAVE_DISK_STORAGE |
@@ -857,7 +869,6 @@ int plugin_load(const char* plugin, const void* parameter) | |||
857 | splash(0, ID2P(LANG_WAIT)); | 869 | splash(0, ID2P(LANG_WAIT)); |
858 | #endif | 870 | #endif |
859 | strcpy(current_plugin, plugin); | 871 | strcpy(current_plugin, plugin); |
860 | |||
861 | current_plugin_handle = lc_open(plugin, pluginbuf, PLUGIN_BUFFER_SIZE); | 872 | current_plugin_handle = lc_open(plugin, pluginbuf, PLUGIN_BUFFER_SIZE); |
862 | if (current_plugin_handle == NULL) { | 873 | if (current_plugin_handle == NULL) { |
863 | splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin); | 874 | splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin); |
@@ -990,6 +1001,12 @@ int plugin_load(const char* plugin, const void* parameter) | |||
990 | if (rc == PLUGIN_ERROR) | 1001 | if (rc == PLUGIN_ERROR) |
991 | splash(HZ*2, str(LANG_PLUGIN_ERROR)); | 1002 | splash(HZ*2, str(LANG_PLUGIN_ERROR)); |
992 | 1003 | ||
1004 | if (resume_plugin && rc != PLUGIN_GOTO_PLUGIN && !pfn_tsr_exit) | ||
1005 | { | ||
1006 | /*plugin = resume_plugin;*/ | ||
1007 | /*parameter = rockbox_api.plugin_tsr;*/ | ||
1008 | return plugin_load(resume_plugin, rockbox_api.plugin_tsr); | ||
1009 | } | ||
993 | return rc; | 1010 | return rc; |
994 | } | 1011 | } |
995 | 1012 | ||
@@ -1067,7 +1084,7 @@ static void plugin_release_audio_buffer(void) | |||
1067 | /* The plugin wants to stay resident after leaving its main function, e.g. | 1084 | /* The plugin wants to stay resident after leaving its main function, e.g. |
1068 | runs from timer or own thread. The callback is registered to later | 1085 | runs from timer or own thread. The callback is registered to later |
1069 | instruct it to free its resources before a new plugin gets loaded. */ | 1086 | instruct it to free its resources before a new plugin gets loaded. */ |
1070 | static void plugin_tsr(bool (*exit_callback)(bool)) | 1087 | static void plugin_tsr(int (*exit_callback)(bool)) |
1071 | { | 1088 | { |
1072 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ | 1089 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ |
1073 | } | 1090 | } |
diff --git a/apps/plugin.h b/apps/plugin.h index c54ef180ec..3eb4101cbe 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -162,7 +162,7 @@ int plugin_open(const char *plugin, const char *parameter); | |||
162 | * when this happens please take the opportunity to sort in | 162 | * when this happens please take the opportunity to sort in |
163 | * any new functions "waiting" at the end of the list. | 163 | * any new functions "waiting" at the end of the list. |
164 | */ | 164 | */ |
165 | #define PLUGIN_API_VERSION 266 | 165 | #define PLUGIN_API_VERSION 267 |
166 | 166 | ||
167 | /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ | 167 | /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ |
168 | 168 | ||
@@ -179,6 +179,12 @@ enum plugin_status { | |||
179 | PLUGIN_ERROR = -1, | 179 | PLUGIN_ERROR = -1, |
180 | }; | 180 | }; |
181 | 181 | ||
182 | enum plugin_tsr_status { | ||
183 | PLUGIN_TSR_CONTINUE = 0, /* TSR continues running */ | ||
184 | PLUGIN_TSR_SUSPEND, /* TSR exits but will restart later */ | ||
185 | PLUGIN_TSR_TERMINATE, /* TSR exits and will not be restarted */ | ||
186 | }; | ||
187 | |||
182 | /* NOTE: To support backwards compatibility, only add new functions at | 188 | /* NOTE: To support backwards compatibility, only add new functions at |
183 | the end of the structure. Every time you add a new function, | 189 | the end of the structure. Every time you add a new function, |
184 | remember to increase PLUGIN_API_VERSION. If you make changes to the | 190 | remember to increase PLUGIN_API_VERSION. If you make changes to the |
@@ -195,6 +201,8 @@ struct plugin_api { | |||
195 | /* lcd */ | 201 | /* lcd */ |
196 | void (*splash)(int ticks, const char *str); | 202 | void (*splash)(int ticks, const char *str); |
197 | void (*splashf)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); | 203 | void (*splashf)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); |
204 | void (*splash_progress)(int current, int total, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); | ||
205 | void (*splash_progress_set_delay)(long delay_ticks); | ||
198 | #ifdef HAVE_LCD_CONTRAST | 206 | #ifdef HAVE_LCD_CONTRAST |
199 | void (*lcd_set_contrast)(int x); | 207 | void (*lcd_set_contrast)(int x); |
200 | #endif | 208 | #endif |
@@ -488,6 +496,8 @@ struct plugin_api { | |||
488 | void (*set_dirfilter)(int l_dirfilter); | 496 | void (*set_dirfilter)(int l_dirfilter); |
489 | 497 | ||
490 | void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb)); | 498 | void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb)); |
499 | void (*onplay_show_playlist_cat_menu)(const char* track_name, int attr, | ||
500 | void (*add_to_pl_cb)); | ||
491 | bool (*browse_id3)(struct mp3entry *id3, | 501 | bool (*browse_id3)(struct mp3entry *id3, |
492 | int playlist_display_index, int playlist_amount, | 502 | int playlist_display_index, int playlist_amount, |
493 | struct tm *modified); | 503 | struct tm *modified); |
@@ -660,6 +670,7 @@ struct plugin_api { | |||
660 | void* (*buflib_get_data)(struct buflib_context* ctx, int handle); | 670 | void* (*buflib_get_data)(struct buflib_context* ctx, int handle); |
661 | 671 | ||
662 | /* sound */ | 672 | /* sound */ |
673 | void (*adjust_volume)(int steps); | ||
663 | void (*sound_set)(int setting, int value); | 674 | void (*sound_set)(int setting, int value); |
664 | int (*sound_current)(int setting); /*stub*/ | 675 | int (*sound_current)(int setting); /*stub*/ |
665 | int (*sound_default)(int setting); | 676 | int (*sound_default)(int setting); |
@@ -769,6 +780,7 @@ struct plugin_api { | |||
769 | bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename); | 780 | bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename); |
770 | #endif | 781 | #endif |
771 | #endif | 782 | #endif |
783 | bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name)); | ||
772 | #endif /* HAVE_TAGCACHE */ | 784 | #endif /* HAVE_TAGCACHE */ |
773 | 785 | ||
774 | #ifdef HAVE_ALBUMART | 786 | #ifdef HAVE_ALBUMART |
@@ -782,6 +794,7 @@ struct plugin_api { | |||
782 | int (*playlist_resume)(void); | 794 | int (*playlist_resume)(void); |
783 | void (*playlist_resume_track)(int start_index, unsigned int crc, | 795 | void (*playlist_resume_track)(int start_index, unsigned int crc, |
784 | unsigned long elapsed, unsigned long offset); | 796 | unsigned long elapsed, unsigned long offset); |
797 | void (*playlist_set_modified)(struct playlist_info *playlist, bool modified); | ||
785 | void (*playlist_start)(int start_index, unsigned long elapsed, | 798 | void (*playlist_start)(int start_index, unsigned long elapsed, |
786 | unsigned long offset); | 799 | unsigned long offset); |
787 | int (*playlist_add)(const char *filename); | 800 | int (*playlist_add)(const char *filename); |
@@ -932,29 +945,20 @@ struct plugin_api { | |||
932 | void* (*plugin_get_buffer)(size_t *buffer_size); | 945 | void* (*plugin_get_buffer)(size_t *buffer_size); |
933 | void* (*plugin_get_audio_buffer)(size_t *buffer_size); | 946 | void* (*plugin_get_audio_buffer)(size_t *buffer_size); |
934 | void (*plugin_release_audio_buffer)(void); | 947 | void (*plugin_release_audio_buffer)(void); |
935 | void (*plugin_tsr)(bool (*exit_callback)(bool reenter)); | 948 | void (*plugin_tsr)(int (*exit_callback)(bool reenter)); |
936 | char* (*plugin_get_current_filename)(void); | 949 | char* (*plugin_get_current_filename)(void); |
937 | size_t (*plugin_reserve_buffer)(size_t buffer_size); | 950 | size_t (*plugin_reserve_buffer)(size_t buffer_size); |
938 | /* reboot and poweroff */ | 951 | /* reboot and poweroff */ |
939 | void (*sys_poweroff)(void); | 952 | void (*sys_poweroff)(void); |
940 | void (*sys_reboot)(void); | 953 | void (*sys_reboot)(void); |
941 | /* pathfuncs */ | 954 | /* pathfuncs */ |
955 | void (*fix_path_part)(char* path, int offset, int count); | ||
942 | #ifdef HAVE_MULTIVOLUME | 956 | #ifdef HAVE_MULTIVOLUME |
943 | int (*path_strip_volume)(const char *name, const char **nameptr, bool greedy); | 957 | int (*path_strip_volume)(const char *name, const char **nameptr, bool greedy); |
944 | #endif | 958 | #endif |
945 | /* new stuff at the end, sort into place next time | 959 | /* new stuff at the end, sort into place next time |
946 | the API gets incompatible */ | 960 | the API gets incompatible */ |
947 | 961 | ||
948 | void (*splash_progress)(int current, int total, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); | ||
949 | void (*splash_progress_set_delay)(long delay_ticks); | ||
950 | void (*fix_path_part)(char* path, int offset, int count); | ||
951 | void (*onplay_show_playlist_cat_menu)(const char* track_name, int attr, | ||
952 | void (*add_to_pl_cb)); | ||
953 | #ifdef HAVE_TAGCACHE | ||
954 | bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name)); | ||
955 | #endif | ||
956 | void (*adjust_volume)(int steps); | ||
957 | void (*playlist_set_modified)(struct playlist_info *playlist, bool modified); | ||
958 | }; | 962 | }; |
959 | 963 | ||
960 | /* plugin header */ | 964 | /* plugin header */ |
diff --git a/apps/plugins/announce_status.c b/apps/plugins/announce_status.c index 77e9015000..1ccfc1e70a 100644 --- a/apps/plugins/announce_status.c +++ b/apps/plugins/announce_status.c | |||
@@ -97,6 +97,7 @@ enum plugin_status plugin_start(const void* parameter); /* entry */ | |||
97 | static struct | 97 | static struct |
98 | { | 98 | { |
99 | bool exiting; /* signal to the thread that we want to exit */ | 99 | bool exiting; /* signal to the thread that we want to exit */ |
100 | bool resume; | ||
100 | unsigned int id; /* worker thread id */ | 101 | unsigned int id; /* worker thread id */ |
101 | struct event_queue queue; /* thread event queue */ | 102 | struct event_queue queue; /* thread event queue */ |
102 | long stack[THREAD_STACK_SIZE / sizeof(long)]; | 103 | long stack[THREAD_STACK_SIZE / sizeof(long)]; |
@@ -393,7 +394,7 @@ static int settings_menu(void) | |||
393 | break; | 394 | break; |
394 | case 4: /*sep*/ | 395 | case 4: /*sep*/ |
395 | continue; | 396 | continue; |
396 | case 5: | 397 | case 5: /* quit the plugin */ |
397 | return -1; | 398 | return -1; |
398 | break; | 399 | break; |
399 | case 6: | 400 | case 6: |
@@ -433,7 +434,8 @@ void thread(void) | |||
433 | in_usb = false; | 434 | in_usb = false; |
434 | /*fall through*/ | 435 | /*fall through*/ |
435 | case EV_STARTUP: | 436 | case EV_STARTUP: |
436 | rb->beep_play(1500, 100, 1000); | 437 | if (!gThread.resume) |
438 | rb->beep_play(1500, 100, 1000); | ||
437 | break; | 439 | break; |
438 | case EV_EXIT: | 440 | case EV_EXIT: |
439 | return; | 441 | return; |
@@ -479,17 +481,45 @@ void thread_quit(void) | |||
479 | } | 481 | } |
480 | } | 482 | } |
481 | 483 | ||
484 | static bool check_user_input(void) | ||
485 | { | ||
486 | int i = 0; | ||
487 | rb->button_clear_queue(); | ||
488 | if (rb->button_get_w_tmo(HZ) > BUTTON_NONE) | ||
489 | { | ||
490 | while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL) | ||
491 | { | ||
492 | if (i & 1) | ||
493 | rb->beep_play(800, 100, 1000 - i * (1000 / 15)); | ||
494 | |||
495 | if (++i > 15) | ||
496 | { | ||
497 | return true; | ||
498 | } | ||
499 | rb->sleep(HZ / 5); | ||
500 | } | ||
501 | } | ||
502 | return false; | ||
503 | } | ||
504 | |||
482 | /* callback to end the TSR plugin, called before a new one gets loaded */ | 505 | /* callback to end the TSR plugin, called before a new one gets loaded */ |
483 | static bool exit_tsr(bool reenter) | 506 | static int exit_tsr(bool reenter) |
484 | { | 507 | { |
485 | if (reenter) | 508 | if (reenter) |
486 | { | 509 | { |
487 | rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0); | 510 | rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0); |
488 | return false; /* dont let it start again */ | 511 | |
512 | /* quit the plugin if user holds a button */ | ||
513 | if (check_user_input() == true) | ||
514 | { | ||
515 | if (settings_menu() < 0) | ||
516 | return PLUGIN_TSR_TERMINATE; /*kill TSR dont let it start again */ | ||
517 | } | ||
518 | return PLUGIN_TSR_CONTINUE; /* dont let new plugin start*/ | ||
489 | } | 519 | } |
490 | thread_quit(); | 520 | thread_quit(); |
491 | 521 | ||
492 | return true; | 522 | return PLUGIN_TSR_SUSPEND; |
493 | } | 523 | } |
494 | 524 | ||
495 | 525 | ||
@@ -497,58 +527,35 @@ static bool exit_tsr(bool reenter) | |||
497 | 527 | ||
498 | int plugin_main(const void* parameter) | 528 | int plugin_main(const void* parameter) |
499 | { | 529 | { |
500 | (void)parameter; | ||
501 | bool settings = false; | ||
502 | int i = 0; | ||
503 | |||
504 | rb->memset(&gThread, 0, sizeof(gThread)); | 530 | rb->memset(&gThread, 0, sizeof(gThread)); |
505 | 531 | ||
506 | gAnnounce.index = 0; | 532 | gAnnounce.index = 0; |
507 | gAnnounce.timeout = 0; | 533 | gAnnounce.timeout = 0; |
508 | 534 | /* Resume plugin ? */ | |
509 | rb->splash(HZ / 2, "Announce Status"); | 535 | if (parameter == rb->plugin_tsr) |
510 | |||
511 | if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0) | ||
512 | { | ||
513 | /* If the loading failed, save a new config file */ | ||
514 | config_set_defaults(); | ||
515 | configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER); | ||
516 | |||
517 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
518 | } | ||
519 | |||
520 | if (gAnnounce.show_prompt) | ||
521 | { | 536 | { |
522 | if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING) | 537 | gThread.resume = true; |
523 | { | ||
524 | rb->talk_id(LANG_HOLD_FOR_SETTINGS, false); | ||
525 | } | ||
526 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
527 | } | 538 | } |
528 | 539 | else | |
529 | rb->button_clear_queue(); | ||
530 | if (rb->button_get_w_tmo(HZ) > BUTTON_NONE) | ||
531 | { | 540 | { |
532 | while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL) | 541 | rb->splash(HZ / 2, "Announce Status"); |
542 | if (gAnnounce.show_prompt) | ||
533 | { | 543 | { |
534 | if (i & 1) | 544 | if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING) |
535 | rb->beep_play(800, 100, 1000); | ||
536 | |||
537 | if (++i > 15) | ||
538 | { | 545 | { |
539 | settings = true; | 546 | rb->talk_id(LANG_HOLD_FOR_SETTINGS, false); |
540 | break; | ||
541 | } | 547 | } |
542 | rb->sleep(HZ / 5); | 548 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); |
543 | } | 549 | } |
544 | } | ||
545 | 550 | ||
546 | if (settings) | 551 | |
547 | { | 552 | if (check_user_input() == true) |
548 | rb->splash(100, ID2P(LANG_SETTINGS)); | 553 | { |
549 | int ret = settings_menu(); | 554 | rb->splash(100, ID2P(LANG_SETTINGS)); |
550 | if (ret < 0) | 555 | int ret = settings_menu(); |
551 | return 0; | 556 | if (ret < 0) |
557 | return 0; | ||
558 | } | ||
552 | } | 559 | } |
553 | 560 | ||
554 | gAnnounce.timeout = *rb->current_tick; | 561 | gAnnounce.timeout = *rb->current_tick; |
@@ -571,6 +578,16 @@ enum plugin_status plugin_start(const void* parameter) | |||
571 | /* now go ahead and have fun! */ | 578 | /* now go ahead and have fun! */ |
572 | if (rb->usb_inserted() == true) | 579 | if (rb->usb_inserted() == true) |
573 | return PLUGIN_USB_CONNECTED; | 580 | return PLUGIN_USB_CONNECTED; |
581 | |||
582 | config_set_defaults(); | ||
583 | if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0) | ||
584 | { | ||
585 | /* If the loading failed, save a new config file */ | ||
586 | config_set_defaults(); | ||
587 | configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER); | ||
588 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
589 | } | ||
590 | |||
574 | int ret = plugin_main(parameter); | 591 | int ret = plugin_main(parameter); |
575 | return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR; | 592 | return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR; |
576 | } | 593 | } |
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 17d3b918cf..f258492363 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -289,11 +289,11 @@ static struct event_queue thread_q SHAREDBSS_ATTR; | |||
289 | static bool in_usb_mode; | 289 | static bool in_usb_mode; |
290 | static unsigned int buf_idx; | 290 | static unsigned int buf_idx; |
291 | 291 | ||
292 | static bool exit_tsr(bool reenter) | 292 | static int exit_tsr(bool reenter) |
293 | { | 293 | { |
294 | bool is_exit; | 294 | int exit_status; |
295 | long button; | 295 | long button; |
296 | (void)reenter; | 296 | |
297 | rb->lcd_clear_display(); | 297 | rb->lcd_clear_display(); |
298 | rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running."); | 298 | rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running."); |
299 | rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " to cancel the test"); | 299 | rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " to cancel the test"); |
@@ -313,16 +313,17 @@ static bool exit_tsr(bool reenter) | |||
313 | rb->thread_wait(gThread.id); | 313 | rb->thread_wait(gThread.id); |
314 | /* remove the thread's queue from the broadcast list */ | 314 | /* remove the thread's queue from the broadcast list */ |
315 | rb->queue_delete(&thread_q); | 315 | rb->queue_delete(&thread_q); |
316 | is_exit = true; | 316 | exit_status = (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
317 | |||
317 | } | 318 | } |
318 | else is_exit = false; | 319 | else exit_status = PLUGIN_TSR_CONTINUE; |
319 | 320 | ||
320 | break; | 321 | break; |
321 | } | 322 | } |
322 | FOR_NB_SCREENS(idx) | 323 | FOR_NB_SCREENS(idx) |
323 | rb->screens[idx]->scroll_stop(); | 324 | rb->screens[idx]->scroll_stop(); |
324 | 325 | ||
325 | return is_exit; | 326 | return exit_status; |
326 | } | 327 | } |
327 | 328 | ||
328 | #define BIT_CHARGER 0x1 | 329 | #define BIT_CHARGER 0x1 |
@@ -502,14 +503,19 @@ static void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, in | |||
502 | 503 | ||
503 | enum plugin_status plugin_start(const void* parameter) | 504 | enum plugin_status plugin_start(const void* parameter) |
504 | { | 505 | { |
505 | (void)parameter; | ||
506 | int button, fd; | 506 | int button, fd; |
507 | bool resume = false; | ||
507 | bool on = false; | 508 | bool on = false; |
508 | start_tick = *rb->current_tick; | 509 | start_tick = *rb->current_tick; |
509 | int i; | 510 | int i; |
510 | const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG, | 511 | const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG, |
511 | "for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - quit" }; | 512 | "for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - quit" }; |
512 | rb->lcd_clear_display(); | 513 | |
514 | if (parameter == rb->plugin_tsr) | ||
515 | { | ||
516 | resume = true; | ||
517 | on = true; | ||
518 | } | ||
513 | 519 | ||
514 | rb->lcd_clear_display(); | 520 | rb->lcd_clear_display(); |
515 | rb->lcd_setfont(FONT_SYSFIXED); | 521 | rb->lcd_setfont(FONT_SYSFIXED); |
@@ -529,36 +535,38 @@ enum plugin_status plugin_start(const void* parameter) | |||
529 | rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2); | 535 | rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2); |
530 | rb->lcd_remote_update(); | 536 | rb->lcd_remote_update(); |
531 | #endif | 537 | #endif |
532 | 538 | if (!resume) | |
533 | do | ||
534 | { | 539 | { |
535 | button = rb->button_get(true); | 540 | do |
536 | switch (button) | ||
537 | { | 541 | { |
538 | case BATTERY_ON: | 542 | button = rb->button_get(true); |
539 | #ifdef BATTERY_RC_ON | 543 | switch (button) |
540 | case BATTERY_RC_ON: | 544 | { |
541 | #endif | 545 | case BATTERY_ON: |
542 | on = true; | 546 | #ifdef BATTERY_RC_ON |
543 | break; | 547 | case BATTERY_RC_ON: |
544 | case BATTERY_OFF: | 548 | #endif |
545 | #ifdef BATTERY_RC_OFF | 549 | on = true; |
546 | case BATTERY_RC_OFF: | 550 | break; |
547 | #endif | 551 | case BATTERY_OFF: |
548 | return PLUGIN_OK; | 552 | #ifdef BATTERY_RC_OFF |
549 | 553 | case BATTERY_RC_OFF: | |
550 | default: | 554 | #endif |
551 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 555 | return PLUGIN_OK; |
552 | return PLUGIN_USB_CONNECTED; | 556 | |
553 | } | 557 | default: |
554 | }while(!on); | 558 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
555 | 559 | return PLUGIN_USB_CONNECTED; | |
560 | } | ||
561 | }while(!on); | ||
562 | } | ||
556 | fd = rb->open(BATTERY_LOG, O_RDONLY); | 563 | fd = rb->open(BATTERY_LOG, O_RDONLY); |
557 | if (fd < 0) | 564 | if (fd < 0) |
558 | { | 565 | { |
559 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666); | 566 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666); |
560 | if (fd >= 0) | 567 | if (fd >= 0) |
561 | { | 568 | { |
569 | |||
562 | rb->fdprintf(fd, | 570 | rb->fdprintf(fd, |
563 | "# This plugin will log your battery performance in a\n" | 571 | "# This plugin will log your battery performance in a\n" |
564 | "# file (%s) every minute.\n" | 572 | "# file (%s) every minute.\n" |
diff --git a/apps/plugins/lastfm_scrobbler.c b/apps/plugins/lastfm_scrobbler.c index 5565eed4c5..dce6be0d1e 100644 --- a/apps/plugins/lastfm_scrobbler.c +++ b/apps/plugins/lastfm_scrobbler.c | |||
@@ -98,7 +98,7 @@ static struct | |||
98 | bool force_flush; | 98 | bool force_flush; |
99 | } gCache; | 99 | } gCache; |
100 | 100 | ||
101 | static struct | 101 | static struct lastfm_config |
102 | { | 102 | { |
103 | int savepct; | 103 | int savepct; |
104 | int beeplvl; | 104 | int beeplvl; |
@@ -528,7 +528,7 @@ void thread_quit(void) | |||
528 | } | 528 | } |
529 | 529 | ||
530 | /* callback to end the TSR plugin, called before a new one gets loaded */ | 530 | /* callback to end the TSR plugin, called before a new one gets loaded */ |
531 | static bool exit_tsr(bool reenter) | 531 | static int exit_tsr(bool reenter) |
532 | { | 532 | { |
533 | MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS), | 533 | MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS), |
534 | "Flush Cache", "Exit Plugin", ID2P(LANG_BACK)); | 534 | "Flush Cache", "Exit Plugin", ID2P(LANG_BACK)); |
@@ -556,19 +556,13 @@ static bool exit_tsr(bool reenter) | |||
556 | case 2: /* exit plugin - quit */ | 556 | case 2: /* exit plugin - quit */ |
557 | if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES) | 557 | if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES) |
558 | { | 558 | { |
559 | scrobbler_flush_cache(); | ||
559 | thread_quit(); | 560 | thread_quit(); |
560 | if (reenter) | 561 | return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
561 | rb->plugin_tsr(NULL); /* remove TSR cb */ | ||
562 | return !reenter; | ||
563 | } | 562 | } |
564 | 563 | /* Fall Through */ | |
565 | if(!reenter) | ||
566 | return false; | ||
567 | |||
568 | break; | ||
569 | |||
570 | case 3: /* back to menu */ | 564 | case 3: /* back to menu */ |
571 | return false; | 565 | return PLUGIN_TSR_CONTINUE; |
572 | } | 566 | } |
573 | } | 567 | } |
574 | } | 568 | } |
@@ -576,7 +570,17 @@ static bool exit_tsr(bool reenter) | |||
576 | /****************** main ******************/ | 570 | /****************** main ******************/ |
577 | static int plugin_main(const void* parameter) | 571 | static int plugin_main(const void* parameter) |
578 | { | 572 | { |
579 | (void)parameter; | 573 | struct lastfm_config cfg; |
574 | rb->memcpy(&cfg, & gConfig, sizeof(struct lastfm_config)); | ||
575 | |||
576 | /* Resume plugin ? */ | ||
577 | if (parameter == rb->plugin_tsr) | ||
578 | { | ||
579 | |||
580 | gConfig.beeplvl = 0; | ||
581 | gConfig.playback = false; | ||
582 | gConfig.verbose = false; | ||
583 | } | ||
580 | 584 | ||
581 | rb->memset(&gThread, 0, sizeof(gThread)); | 585 | rb->memset(&gThread, 0, sizeof(gThread)); |
582 | if (gConfig.verbose) | 586 | if (gConfig.verbose) |
@@ -586,9 +590,11 @@ static int plugin_main(const void* parameter) | |||
586 | rb->plugin_tsr(exit_tsr); /* stay resident */ | 590 | rb->plugin_tsr(exit_tsr); /* stay resident */ |
587 | 591 | ||
588 | thread_create(); | 592 | thread_create(); |
593 | rb->memcpy(&gConfig, &cfg, sizeof(struct lastfm_config)); | ||
589 | 594 | ||
590 | if (gConfig.playback) | 595 | if (gConfig.playback) |
591 | return PLUGIN_GOTO_WPS; | 596 | return PLUGIN_GOTO_WPS; |
597 | |||
592 | return PLUGIN_OK; | 598 | return PLUGIN_OK; |
593 | } | 599 | } |
594 | 600 | ||
diff --git a/apps/plugins/test_usb.c b/apps/plugins/test_usb.c index 6bb77c40be..28ef8f7e5f 100644 --- a/apps/plugins/test_usb.c +++ b/apps/plugins/test_usb.c | |||
@@ -85,7 +85,7 @@ static void kill_tsr(void) | |||
85 | rb->queue_delete(&queue); | 85 | rb->queue_delete(&queue); |
86 | } | 86 | } |
87 | 87 | ||
88 | static bool exit_tsr(bool reenter) | 88 | static int exit_tsr(bool reenter) |
89 | { | 89 | { |
90 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | 90 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, |
91 | "Status", "Stop plugin", "Back"); | 91 | "Status", "Stop plugin", "Back"); |
@@ -100,9 +100,9 @@ static bool exit_tsr(bool reenter) | |||
100 | case 1: | 100 | case 1: |
101 | rb->splashf(HZ, "Stopping USB test thread"); | 101 | rb->splashf(HZ, "Stopping USB test thread"); |
102 | kill_tsr(); | 102 | kill_tsr(); |
103 | return true; | 103 | return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
104 | case 2: | 104 | case 2: |
105 | return false; | 105 | return PLUGIN_TSR_CONTINUE; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -119,14 +119,15 @@ static void run_tsr(void) | |||
119 | 119 | ||
120 | enum plugin_status plugin_start(const void* parameter) | 120 | enum plugin_status plugin_start(const void* parameter) |
121 | { | 121 | { |
122 | (void)parameter; | 122 | bool resume = (parameter == rb->plugin_tsr); |
123 | |||
123 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | 124 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, |
124 | "Start", "Quit"); | 125 | "Start", "Quit"); |
125 | 126 | ||
126 | switch(rb->do_menu(&menu, NULL, NULL, false)) { | 127 | switch(!resume ? rb->do_menu(&menu, NULL, NULL, false) : 0) { |
127 | case 0: | 128 | case 0: |
128 | run_tsr(); | 129 | run_tsr(); |
129 | rb->splashf(HZ, "Thread started"); | 130 | rb->splashf(HZ, "USB test thread started"); |
130 | return PLUGIN_OK; | 131 | return PLUGIN_OK; |
131 | case 1: | 132 | case 1: |
132 | return PLUGIN_OK; | 133 | return PLUGIN_OK; |