summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 @@
</phrase>
<phrase>
id: LANG_SLEEP_TIMER_DURATION
- desc: default sleep timer duration in minutes
+ desc: default sleep timer duration in minutes (unused in UI)
user: core
<source>
*: "Default Sleep Timer Duration"
@@ -12889,3 +12889,17 @@
*: "Start Sleep Timer On Boot"
</voice>
</phrase>
+<phrase>
+ id: LANG_SLEEP_TIMER_CANCEL_CURRENT
+ desc: shown instead of sleep timer when it's running
+ user: core
+ <source>
+ *: "Cancel Sleep Timer"
+ </source>
+ <dest>
+ *: "Cancel Sleep Timer"
+ </dest>
+ <voice>
+ *: "Cancel Sleep Timer"
+ </voice>
+</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,
static const struct menu_get_name_and_icon name##_ \
= {callback,text_callback,voice_callback,text_cb_data,icon}; \
static const struct menu_func name##__ = {{(void*)func}, param}; \
- static const struct menu_item_ex name = \
+ const struct menu_item_ex name = \
{ MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
{ .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
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)
static int sleep_timer(void)
{
- int minutes = get_sleep_timer() ? 0 : global_settings.sleeptimer_duration;
- return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
- &sleep_timer_set, 5, 0, 300, sleep_timer_formatter);
+ int minutes = global_settings.sleeptimer_duration;
+ if (get_sleep_timer())
+ sleep_timer_set(0);
+ else
+ set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
+ &sleep_timer_set, 5, 0, 300, sleep_timer_formatter);
+ return 0;
+}
+
+static int seconds_to_min(int secs)
+{
+ int min = secs / 60;
+ if ((secs % 60) > 50) /* round up for 50+ seconds */
+ min++;
+
+ return min;
+}
+
+static char* sleep_timer_getname(int selected_item, void * data, char *buffer)
+{
+ (void)selected_item;
+ (void)data;
+ (void)buffer;
+ int sec = get_sleep_timer();
+ char timer_buf[10];
+ /* we have no sprintf, so MAX_PATH is a guess */
+ if (sec > 0)
+ { /* show cancel and countdown if running */
+ snprintf(buffer, MAX_PATH, "%s (%s)", str(LANG_SLEEP_TIMER_CANCEL_CURRENT),
+ sleep_timer_formatter(timer_buf, sizeof(timer_buf), seconds_to_min(sec), NULL));
+ }
+ else
+ snprintf(buffer, MAX_PATH, "%s", str(LANG_SLEEP_TIMER));
+
+ return buffer;
}
+static int sleep_timer_voice(int selected_item, void*data)
+{
+ (void)selected_item;
+ (void)data;
+ int seconds = get_sleep_timer();
+ if (seconds > 0)
+ {
+ long talk_ids[] = {
+ LANG_SLEEP_TIMER_CANCEL_CURRENT,
+ VOICE_PAUSE,
+ seconds_to_min(seconds) | UNIT_MIN << UNIT_SHIFT,
+ TALK_FINAL_ID
+ };
+ talk_idarray(talk_ids, true);
+ }
+ else
+ talk_id(LANG_SLEEP_TIMER, true);
+ return 0;
+}
#if CONFIG_RTC
int time_screen(void* ignored);
MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU),
time_screen, NULL, NULL, Icon_Menu_setting );
#endif
-/* Sleep timer items are in the time/date screen if there is a RTC */
-MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer,
- NULL, NULL, Icon_Menu_setting); /* make it look like a
- setting to the user */
+MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, sleep_timer_getname,
+ sleep_timer_voice, NULL, NULL, Icon_Menu_setting);
+ /* make it look like a setting to the user */
#if CONFIG_RTC == 0
MENUITEM_SETTING(sleeptimer_on_startup,
&global_settings.sleeptimer_on_startup, NULL);