diff options
Diffstat (limited to 'apps/menus/main_menu.c')
-rw-r--r-- | apps/menus/main_menu.c | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index 66d49a920e..602becd2b3 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c | |||
@@ -419,21 +419,71 @@ static void sleep_timer_set(int minutes) | |||
419 | 419 | ||
420 | static int sleep_timer(void) | 420 | static int sleep_timer(void) |
421 | { | 421 | { |
422 | int minutes = get_sleep_timer() ? 0 : global_settings.sleeptimer_duration; | 422 | int minutes = global_settings.sleeptimer_duration; |
423 | return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, | 423 | if (get_sleep_timer()) |
424 | &sleep_timer_set, 5, 0, 300, sleep_timer_formatter); | 424 | sleep_timer_set(0); |
425 | else | ||
426 | set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, | ||
427 | &sleep_timer_set, 5, 0, 300, sleep_timer_formatter); | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | static int seconds_to_min(int secs) | ||
432 | { | ||
433 | int min = secs / 60; | ||
434 | if ((secs % 60) > 50) /* round up for 50+ seconds */ | ||
435 | min++; | ||
436 | |||
437 | return min; | ||
438 | } | ||
439 | |||
440 | static char* sleep_timer_getname(int selected_item, void * data, char *buffer) | ||
441 | { | ||
442 | (void)selected_item; | ||
443 | (void)data; | ||
444 | (void)buffer; | ||
445 | int sec = get_sleep_timer(); | ||
446 | char timer_buf[10]; | ||
447 | /* we have no sprintf, so MAX_PATH is a guess */ | ||
448 | if (sec > 0) | ||
449 | { /* show cancel and countdown if running */ | ||
450 | snprintf(buffer, MAX_PATH, "%s (%s)", str(LANG_SLEEP_TIMER_CANCEL_CURRENT), | ||
451 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), seconds_to_min(sec), NULL)); | ||
452 | } | ||
453 | else | ||
454 | snprintf(buffer, MAX_PATH, "%s", str(LANG_SLEEP_TIMER)); | ||
455 | |||
456 | return buffer; | ||
425 | } | 457 | } |
426 | 458 | ||
459 | static int sleep_timer_voice(int selected_item, void*data) | ||
460 | { | ||
461 | (void)selected_item; | ||
462 | (void)data; | ||
463 | int seconds = get_sleep_timer(); | ||
464 | if (seconds > 0) | ||
465 | { | ||
466 | long talk_ids[] = { | ||
467 | LANG_SLEEP_TIMER_CANCEL_CURRENT, | ||
468 | VOICE_PAUSE, | ||
469 | seconds_to_min(seconds) | UNIT_MIN << UNIT_SHIFT, | ||
470 | TALK_FINAL_ID | ||
471 | }; | ||
472 | talk_idarray(talk_ids, true); | ||
473 | } | ||
474 | else | ||
475 | talk_id(LANG_SLEEP_TIMER, true); | ||
476 | return 0; | ||
477 | } | ||
427 | 478 | ||
428 | #if CONFIG_RTC | 479 | #if CONFIG_RTC |
429 | int time_screen(void* ignored); | 480 | int time_screen(void* ignored); |
430 | MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU), | 481 | MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU), |
431 | time_screen, NULL, NULL, Icon_Menu_setting ); | 482 | time_screen, NULL, NULL, Icon_Menu_setting ); |
432 | #endif | 483 | #endif |
433 | /* Sleep timer items are in the time/date screen if there is a RTC */ | 484 | MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, sleep_timer_getname, |
434 | MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer, | 485 | sleep_timer_voice, NULL, NULL, Icon_Menu_setting); |
435 | NULL, NULL, Icon_Menu_setting); /* make it look like a | 486 | /* make it look like a setting to the user */ |
436 | setting to the user */ | ||
437 | #if CONFIG_RTC == 0 | 487 | #if CONFIG_RTC == 0 |
438 | MENUITEM_SETTING(sleeptimer_on_startup, | 488 | MENUITEM_SETTING(sleeptimer_on_startup, |
439 | &global_settings.sleeptimer_on_startup, NULL); | 489 | &global_settings.sleeptimer_on_startup, NULL); |