summaryrefslogtreecommitdiffstats
path: root/apps/plugins/announce_status.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/announce_status.c')
-rw-r--r--apps/plugins/announce_status.c144
1 files changed, 86 insertions, 58 deletions
diff --git a/apps/plugins/announce_status.c b/apps/plugins/announce_status.c
index 84a44556ef..21518b4d68 100644
--- a/apps/plugins/announce_status.c
+++ b/apps/plugins/announce_status.c
@@ -27,6 +27,7 @@
****************************************************************************/
#include "plugin.h"
+#include "lib/helper.h"
#include "lib/kbd_helper.h"
#include "lib/configfile.h"
@@ -96,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)];
@@ -185,12 +187,13 @@ static void config_reset_voice(void)
}
/****************** helper fuctions ******************/
-
void announce(void)
{
rb->talk_force_shutup();
rb->sleep(HZ / 2);
voice_general_info(false);
+ if (rb->talk_id(VOICE_PAUSE, true) < 0)
+ rb->beep_play(800, 100, 1000);
//rb->talk_force_enqueue_next();
}
@@ -380,7 +383,7 @@ static int settings_menu(void)
break;
case 1:
rb->set_option(rb->str(LANG_ANNOUNCE_ON),
- &gAnnounce.announce_on, INT, announce_options, 2, NULL);
+ &gAnnounce.announce_on, RB_INT, announce_options, 2, NULL);
break;
case 2:
rb->set_int(rb->str(LANG_GROUPING), "", 1,
@@ -391,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:
@@ -412,6 +415,7 @@ static int settings_menu(void)
/****************** main thread + helper ******************/
void thread(void)
{
+ bool in_usb = false;
long interval;
long last_tick = *rb->current_tick; /* for 1 sec tick */
@@ -424,6 +428,15 @@ void thread(void)
{
case SYS_USB_CONNECTED:
rb->usb_acknowledge(SYS_USB_CONNECTED_ACK);
+ in_usb = true;
+ break;
+ case SYS_USB_DISCONNECTED:
+ in_usb = false;
+ /*fall through*/
+ case EV_STARTUP:
+ if (!gThread.resume)
+ rb->beep_play(1500, 100, 1000);
+ break;
case EV_EXIT:
return;
case EV_OTHINSTANCE:
@@ -431,15 +444,12 @@ void thread(void)
{
last_tick += interval;
rb->sleep(HZ / 10);
- announce();
+ if (!in_usb) announce();
}
break;
- case EV_STARTUP:
- rb->beep_play(1500, 100, 1000);
- break;
case EV_TRACKCHANGE:
rb->sleep(HZ / 10);
- announce();
+ if (!in_usb) announce();
break;
}
}
@@ -464,23 +474,52 @@ void thread_quit(void)
rb->thread_wait(gThread.id);
/* we don't want any more events */
rb->remove_event(PLAYBACK_EVENT_TRACK_CHANGE, playback_event_callback);
+
/* remove the thread's queue from the broadcast list */
rb->queue_delete(&gThread.queue);
gThread.exiting = true;
}
}
+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;
}
@@ -488,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;
@@ -560,6 +576,18 @@ int plugin_main(const void* parameter)
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;
}
@@ -658,7 +686,7 @@ static unsigned char* voice_info_group(unsigned char* current_token, bool testin
if (current_char == 'T')
{
runtime = rb->global_status->runtime;
- rb->talk_value(runtime, UNIT_TIME, true);
+ talk_val(runtime, UNIT_TIME, true);
}
/* prefix suffix connectives */
else if (current_char == '1')
@@ -669,7 +697,7 @@ static unsigned char* voice_info_group(unsigned char* current_token, bool testin
{
if (current_char == 'S')
{
- rb->talk_value(sleep_remaining, UNIT_TIME, true);
+ talk_val(sleep_remaining, UNIT_TIME, true);
}
/* prefix suffix connectives */
else if (current_char == '2')
@@ -704,15 +732,15 @@ static unsigned char* voice_info_group(unsigned char* current_token, bool testin
if (current_char == 'E')
{
- rb->talk_value(elapsed_length, UNIT_TIME, true);
+ talk_val(elapsed_length, UNIT_TIME, true);
}
else if (current_char == 'L')
{
- rb->talk_value(track_length, UNIT_TIME, true);
+ talk_val(track_length, UNIT_TIME, true);
}
else if (current_char == 'R')
{
- rb->talk_value(track_remaining, UNIT_TIME, true);
+ talk_val(track_remaining, UNIT_TIME, true);
}
else if (current_char == 'T' && id3->title)
{
@@ -797,11 +825,11 @@ static unsigned char* voice_info_group(unsigned char* current_token, bool testin
if (current_char == 'P')
{
- rb->talk_value(rb->battery_level(), UNIT_PERCENT, true);
+ talk_val(rb->battery_level(), UNIT_PERCENT, true);
}
else if (current_char == 'M')
{
- rb->talk_value(rb->battery_time() * 60, UNIT_TIME, true);
+ talk_val(rb->battery_time() * 60, UNIT_TIME, true);
}
/* prefix suffix connectives */
else if (current_char == '1')