summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 4faadb8130..7ba229a6f3 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1467,6 +1467,82 @@ void format_time(char* buf, int buf_size, long t)
1467 t < 0, "-", units_in[UNIT_IDX_HR], hashours, ":", 1467 t < 0, "-", units_in[UNIT_IDX_HR], hashours, ":",
1468 hashours+1, units_in[UNIT_IDX_MIN], units_in[UNIT_IDX_SEC]); 1468 hashours+1, units_in[UNIT_IDX_MIN], units_in[UNIT_IDX_SEC]);
1469} 1469}
1470
1471const char* format_sleeptimer(char* buffer, size_t buffer_size,
1472 int value, const char* unit)
1473{
1474 (void) unit;
1475 int minutes, hours;
1476
1477 if (value) {
1478 hours = value / 60;
1479 minutes = value - (hours * 60);
1480 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
1481 return buffer;
1482 } else {
1483 return str(LANG_OFF);
1484 }
1485}
1486
1487static int seconds_to_min(int secs)
1488{
1489 return (secs + 10) / 60; /* round up for 50+ seconds */
1490}
1491
1492char* string_sleeptimer(char *buffer, size_t buffer_len)
1493{
1494 int sec = get_sleep_timer();
1495 char timer_buf[10];
1496
1497 snprintf(buffer, buffer_len, "%s (%s)",
1498 str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT
1499 : LANG_SLEEP_TIMER_START_CURRENT),
1500 format_sleeptimer(timer_buf, sizeof(timer_buf),
1501 sec ? seconds_to_min(sec)
1502 : global_settings.sleeptimer_duration, NULL));
1503 return buffer;
1504}
1505
1506/* If a sleep timer is running, cancel it, otherwise start one */
1507int toggle_sleeptimer(void)
1508{
1509 set_sleeptimer_duration(get_sleep_timer() ? 0
1510 : global_settings.sleeptimer_duration);
1511 return 0;
1512}
1513
1514void talk_sleeptimer(void)
1515{
1516 int seconds = get_sleep_timer();
1517 long talk_ids[] = {
1518 seconds ? LANG_SLEEP_TIMER_CANCEL_CURRENT
1519 : LANG_SLEEP_TIMER_START_CURRENT,
1520 VOICE_PAUSE,
1521 (seconds ? seconds_to_min(seconds)
1522 : global_settings.sleeptimer_duration) | UNIT_MIN << UNIT_SHIFT,
1523 TALK_FINAL_ID
1524 };
1525 talk_idarray(talk_ids, true);
1526}
1527
1528#if CONFIG_RTC
1529void talk_timedate(void)
1530{
1531 struct tm *tm = get_time();
1532 if (!global_settings.talk_menu)
1533 return;
1534 talk_id(VOICE_CURRENT_TIME, false);
1535 if (valid_time(tm))
1536 {
1537 talk_time(tm, true);
1538 talk_date(get_time(), true);
1539 }
1540 else
1541 {
1542 talk_id(LANG_UNKNOWN, true);
1543 }
1544}
1545#endif /* CONFIG_RTC */
1470#endif /* !defined(CHECKWPS) && !defined(DBTOOL)*/ 1546#endif /* !defined(CHECKWPS) && !defined(DBTOOL)*/
1471 1547
1472/** 1548/**