summaryrefslogtreecommitdiff
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.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 */
97static struct 97static 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
484static 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 */
483static bool exit_tsr(bool reenter) 506static 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
498int plugin_main(const void* parameter) 528int 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}