diff options
author | Christian Soffke <christian.soffke@gmail.com> | 2024-05-13 17:11:45 +0200 |
---|---|---|
committer | Christian Soffke <christian.soffke@gmail.com> | 2024-05-13 18:18:45 +0200 |
commit | fdba79cd7777d3318531995083984fade98afae8 (patch) | |
tree | 908ff3d74414e133456b9f29aab4fedb58f5ba0c /apps/misc.c | |
parent | 8eeef333a15d99a38f733a45612728dfae66b862 (diff) | |
download | rockbox-fdba79cd7777d3318531995083984fade98afae8.tar.gz rockbox-fdba79cd7777d3318531995083984fade98afae8.zip |
shortcuts: refactor sleeptimer / talk_timedate
move some functions around, with no effect on behavior
Change-Id: I4638a28f5ff2a851534a3dd696ea7e763029cb2f
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 76 |
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 | |||
1471 | const 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 | |||
1487 | static int seconds_to_min(int secs) | ||
1488 | { | ||
1489 | return (secs + 10) / 60; /* round up for 50+ seconds */ | ||
1490 | } | ||
1491 | |||
1492 | char* 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 */ | ||
1507 | int toggle_sleeptimer(void) | ||
1508 | { | ||
1509 | set_sleeptimer_duration(get_sleep_timer() ? 0 | ||
1510 | : global_settings.sleeptimer_duration); | ||
1511 | return 0; | ||
1512 | } | ||
1513 | |||
1514 | void 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 | ||
1529 | void 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 | /** |