summaryrefslogtreecommitdiffstats
path: root/apps/plugins/announce_status.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-03-20 22:15:33 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2023-03-25 10:02:43 -0400
commita2e5d9563f9dec84907f4f2060af6dfad895c4ba (patch)
treee2c27f4fca350e1f1ce8ba2ef8fe30fbb341c3c0 /apps/plugins/announce_status.c
parent2e99e2175b48cc00274b03bb4aecf5d01403110d (diff)
downloadrockbox-a2e5d9563f.tar.gz
rockbox-a2e5d9563f.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
Diffstat (limited to 'apps/plugins/announce_status.c')
-rw-r--r--apps/plugins/announce_status.c107
1 files changed, 62 insertions, 45 deletions
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 */
static struct
{
bool exiting; /* signal to the thread that we want to exit */
+ bool resume;
unsigned int id; /* worker thread id */
struct event_queue queue; /* thread event queue */
long stack[THREAD_STACK_SIZE / sizeof(long)];
@@ -393,7 +394,7 @@ static int settings_menu(void)
break;
case 4: /*sep*/
continue;
- case 5:
+ case 5: /* quit the plugin */
return -1;
break;
case 6:
@@ -433,7 +434,8 @@ void thread(void)
in_usb = false;
/*fall through*/
case EV_STARTUP:
- rb->beep_play(1500, 100, 1000);
+ if (!gThread.resume)
+ rb->beep_play(1500, 100, 1000);
break;
case EV_EXIT:
return;
@@ -479,17 +481,45 @@ void thread_quit(void)
}
}
+static bool check_user_input(void)
+{
+ int i = 0;
+ rb->button_clear_queue();
+ if (rb->button_get_w_tmo(HZ) > BUTTON_NONE)
+ {
+ while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL)
+ {
+ if (i & 1)
+ rb->beep_play(800, 100, 1000 - i * (1000 / 15));
+
+ if (++i > 15)
+ {
+ return true;
+ }
+ rb->sleep(HZ / 5);
+ }
+ }
+ return false;
+}
+
/* callback to end the TSR plugin, called before a new one gets loaded */
-static bool exit_tsr(bool reenter)
+static int exit_tsr(bool reenter)
{
if (reenter)
{
rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0);
- return false; /* dont let it start again */
+
+ /* quit the plugin if user holds a button */
+ if (check_user_input() == true)
+ {
+ if (settings_menu() < 0)
+ return PLUGIN_TSR_TERMINATE; /*kill TSR dont let it start again */
+ }
+ return PLUGIN_TSR_CONTINUE; /* dont let new plugin start*/
}
thread_quit();
- return true;
+ return PLUGIN_TSR_SUSPEND;
}
@@ -497,58 +527,35 @@ static bool exit_tsr(bool reenter)
int plugin_main(const void* parameter)
{
- (void)parameter;
- bool settings = false;
- int i = 0;
-
rb->memset(&gThread, 0, sizeof(gThread));
gAnnounce.index = 0;
gAnnounce.timeout = 0;
-
- rb->splash(HZ / 2, "Announce Status");
-
- if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0)
- {
- /* If the loading failed, save a new config file */
- config_set_defaults();
- configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER);
-
- rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
- }
-
- if (gAnnounce.show_prompt)
+ /* Resume plugin ? */
+ if (parameter == rb->plugin_tsr)
{
- if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING)
- {
- rb->talk_id(LANG_HOLD_FOR_SETTINGS, false);
- }
- rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
+ gThread.resume = true;
}
-
- rb->button_clear_queue();
- if (rb->button_get_w_tmo(HZ) > BUTTON_NONE)
+ else
{
- while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL)
+ rb->splash(HZ / 2, "Announce Status");
+ if (gAnnounce.show_prompt)
{
- if (i & 1)
- rb->beep_play(800, 100, 1000);
-
- if (++i > 15)
+ if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING)
{
- settings = true;
- break;
+ rb->talk_id(LANG_HOLD_FOR_SETTINGS, false);
}
- rb->sleep(HZ / 5);
+ rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
}
- }
- if (settings)
- {
- rb->splash(100, ID2P(LANG_SETTINGS));
- int ret = settings_menu();
- if (ret < 0)
- return 0;
+
+ if (check_user_input() == true)
+ {
+ rb->splash(100, ID2P(LANG_SETTINGS));
+ int ret = settings_menu();
+ if (ret < 0)
+ return 0;
+ }
}
gAnnounce.timeout = *rb->current_tick;
@@ -571,6 +578,16 @@ enum plugin_status plugin_start(const void* parameter)
/* now go ahead and have fun! */
if (rb->usb_inserted() == true)
return PLUGIN_USB_CONNECTED;
+
+ config_set_defaults();
+ if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0)
+ {
+ /* If the loading failed, save a new config file */
+ config_set_defaults();
+ configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER);
+ rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
+ }
+
int ret = plugin_main(parameter);
return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR;
}