summaryrefslogtreecommitdiff
path: root/apps/shortcuts.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/shortcuts.c')
-rw-r--r--apps/shortcuts.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index c0f9ed2612..c64976c46c 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -244,8 +244,11 @@ static void shortcuts_ata_idle_callback(void)
244#endif 244#endif
245 { 245 {
246 write(fd, "sleep ", 6); 246 write(fd, "sleep ", 6);
247 len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout); 247 if (sc->u.timedata.sleep_timeout >= 0)
248 write(fd, buf, len); 248 {
249 len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout);
250 write(fd, buf, len);
251 }
249 } 252 }
250 } 253 }
251 else 254 else
@@ -348,8 +351,12 @@ static int readline_cb(int n, char *buf, void *parameters)
348 sc->u.timedata.talktime = true; 351 sc->u.timedata.talktime = true;
349 else 352 else
350#endif 353#endif
351 if (!strncasecmp(value, "sleep ", strlen("sleep "))) 354 if (!strncasecmp(value, "sleep", strlen("sleep")))
352 sc->u.timedata.sleep_timeout = atoi(&value[strlen("sleep ")]); 355 {
356 /* 'sleep' may appear alone or followed by number after a space */
357 sc->u.timedata.sleep_timeout = strlen(&value[5]) > 1 ?
358 atoi(&value[strlen("sleep ")]) : -1;
359 }
353 else 360 else
354 sc->type = SHORTCUT_UNDEFINED; /* error */ 361 sc->type = SHORTCUT_UNDEFINED; /* error */
355 break; 362 break;
@@ -411,6 +418,8 @@ void shortcuts_init(void)
411 --buflib_move_lock; 418 --buflib_move_lock;
412} 419}
413 420
421char* sleep_timer_getname(int selected_item, void * data,
422 char *buffer, size_t buffer_len); /* settings_menu.c */
414static const char * shortcut_menu_get_name(int selected_item, void * data, 423static const char * shortcut_menu_get_name(int selected_item, void * data,
415 char * buffer, size_t buffer_len) 424 char * buffer, size_t buffer_len)
416{ 425{
@@ -420,8 +429,21 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
420 return ""; 429 return "";
421 if (sc->type == SHORTCUT_SETTING) 430 if (sc->type == SHORTCUT_SETTING)
422 return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); 431 return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id));
423 else if (sc->type == SHORTCUT_SEPARATOR || sc->type == SHORTCUT_TIME) 432 else if (sc->type == SHORTCUT_SEPARATOR)
433 return sc->name;
434 else if (sc->type == SHORTCUT_TIME)
435 {
436 if (sc->u.timedata.sleep_timeout < 0
437#if CONFIG_RTC
438 && !sc->u.timedata.talktime
439#endif
440 ) /* Toggle Sleep Timer */
441 {
442 sleep_timer_getname(selected_item, data, buffer, buffer_len);
443 return buffer;
444 }
424 return sc->name; 445 return sc->name;
446 }
425 else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') 447 else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0')
426 { 448 {
427 /* No translation support as only soft_shutdown has LANG_SHUTDOWN defined */ 449 /* No translation support as only soft_shutdown has LANG_SHUTDOWN defined */
@@ -513,6 +535,7 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data
513} 535}
514 536
515void talk_timedate(void); 537void talk_timedate(void);
538int sleep_timer_voice(int selected_item, void*data); /* settings_menu.c */
516static int shortcut_menu_speak_item(int selected_item, void * data) 539static int shortcut_menu_speak_item(int selected_item, void * data)
517{ 540{
518 (void)data; 541 (void)data;
@@ -576,7 +599,9 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
576 talk_timedate(); 599 talk_timedate();
577 else 600 else
578#endif 601#endif
579 if (sc->name[0]) 602 if (sc->u.timedata.sleep_timeout < 0)
603 sleep_timer_voice(selected_item, data);
604 else if (sc->name[0])
580 talk_spell(sc->name, false); 605 talk_spell(sc->name, false);
581 break; 606 break;
582 case SHORTCUT_SHUTDOWN: 607 case SHORTCUT_SHUTDOWN:
@@ -596,7 +621,7 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
596 621
597const char* sleep_timer_formatter(char* buffer, size_t buffer_size, 622const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
598 int value, const char* unit); 623 int value, const char* unit);
599 624int toggle_sleeptimer(void); /* settings_menu.c */
600int do_shortcut_menu(void *ignored) 625int do_shortcut_menu(void *ignored)
601{ 626{
602 (void)ignored; 627 (void)ignored;
@@ -717,10 +742,16 @@ int do_shortcut_menu(void *ignored)
717#endif 742#endif
718 { 743 {
719 char timer_buf[10]; 744 char timer_buf[10];
720 set_sleeptimer_duration(sc->u.timedata.sleep_timeout); 745 if (sc->u.timedata.sleep_timeout >= 0)
721 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), 746 {
722 sleep_timer_formatter(timer_buf, sizeof(timer_buf), 747 set_sleeptimer_duration(sc->u.timedata.sleep_timeout);
723 sc->u.timedata.sleep_timeout, NULL)); 748 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
749 sleep_timer_formatter(timer_buf, sizeof(timer_buf),
750 sc->u.timedata.sleep_timeout,
751 NULL));
752 }
753 else
754 toggle_sleeptimer();
724 } 755 }
725 break; 756 break;
726 case SHORTCUT_UNDEFINED: 757 case SHORTCUT_UNDEFINED: