summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/lang/english.lang16
-rw-r--r--apps/menu.h2
-rw-r--r--apps/menus/main_menu.c64
3 files changed, 73 insertions, 9 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 3fc2c72ec4..5a59473681 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -12863,7 +12863,7 @@
12863</phrase> 12863</phrase>
12864<phrase> 12864<phrase>
12865 id: LANG_SLEEP_TIMER_DURATION 12865 id: LANG_SLEEP_TIMER_DURATION
12866 desc: default sleep timer duration in minutes 12866 desc: default sleep timer duration in minutes (unused in UI)
12867 user: core 12867 user: core
12868 <source> 12868 <source>
12869 *: "Default Sleep Timer Duration" 12869 *: "Default Sleep Timer Duration"
@@ -12889,3 +12889,17 @@
12889 *: "Start Sleep Timer On Boot" 12889 *: "Start Sleep Timer On Boot"
12890 </voice> 12890 </voice>
12891</phrase> 12891</phrase>
12892<phrase>
12893 id: LANG_SLEEP_TIMER_CANCEL_CURRENT
12894 desc: shown instead of sleep timer when it's running
12895 user: core
12896 <source>
12897 *: "Cancel Sleep Timer"
12898 </source>
12899 <dest>
12900 *: "Cancel Sleep Timer"
12901 </dest>
12902 <voice>
12903 *: "Cancel Sleep Timer"
12904 </voice>
12905</phrase>
diff --git a/apps/menu.h b/apps/menu.h
index b5bab90981..2251de243c 100644
--- a/apps/menu.h
+++ b/apps/menu.h
@@ -198,7 +198,7 @@ int do_menu(const struct menu_item_ex *menu, int *start_selected,
198 static const struct menu_get_name_and_icon name##_ \ 198 static const struct menu_get_name_and_icon name##_ \
199 = {callback,text_callback,voice_callback,text_cb_data,icon}; \ 199 = {callback,text_callback,voice_callback,text_cb_data,icon}; \
200 static const struct menu_func name##__ = {{(void*)func}, param}; \ 200 static const struct menu_func name##__ = {{(void*)func}, param}; \
201 static const struct menu_item_ex name = \ 201 const struct menu_item_ex name = \
202 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ 202 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
203 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; 203 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
204 204
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
420static int sleep_timer(void) 420static 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
431static 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
440static 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
459static 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
429int time_screen(void* ignored); 480int time_screen(void* ignored);
430MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU), 481MENUITEM_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 */ 484MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, sleep_timer_getname,
434MENUITEM_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
438MENUITEM_SETTING(sleeptimer_on_startup, 488MENUITEM_SETTING(sleeptimer_on_startup,
439 &global_settings.sleeptimer_on_startup, NULL); 489 &global_settings.sleeptimer_on_startup, NULL);