Select the given mood or playlist after the fade-out. If unset,
playback is stopped until fade-in starts.
[/help]
- [option wake-hour]
- short_opt = H
- summary = A number between 0 and 23
+ [option wake-time]
+ short_opt = w
+ summary = when to start fade in
arg_info = required_arg
- arg_type = uint32
- typestr = hour
+ arg_type = string
+ typestr = [+][HH][:MM]
+ default_val = +9:00
[help]
- If this is not given, the default is computed as now + 9 hours.
+ If the optional plus character is given, the wake time is computed as
+ now + HH hours + MM minutes. Otherwise the HH:MM argument is considered
+ an absolute time (referring to either the current or the next day).
[/help]
- [option wake-min]
- short_opt = M
- summary = A number between 0 and 59
- arg_info = required_arg
- arg_type = uint32
- typestr = minutes
[option fi-mood]
summary = mood or playlist for fade-in
arg_info = required_arg
time_t t1, wake_time_epoch;
unsigned int delay;
struct tm *tm;
- int ret, min = OPT_UINT32_VAL(SLEEP, WAKE_MIN);
+ int ret;
+ const char *wake_time = OPT_STRING_VAL(SLEEP, WAKE_TIME);
const char *fo_mood = OPT_STRING_VAL(SLEEP, FO_MOOD);
const char *fi_mood = OPT_STRING_VAL(SLEEP, FI_MOOD);
const char *sleep_mood = OPT_STRING_VAL(SLEEP, SLEEP_MOOD);
int fot = OPT_UINT32_VAL(SLEEP, FO_TIME);
int fiv = OPT_UINT32_VAL(SLEEP, FI_VOL);
int fov = OPT_UINT32_VAL(SLEEP, FO_VOL);
+ int32_t hour, min = 0;
+ char *tmp;
+ char *wt = para_strdup(wake_time + (wake_time[0] == '+'));
/* calculate wake time */
time(&t1);
- if (OPT_GIVEN(SLEEP, WAKE_HOUR)) {
- int hour = OPT_UINT32_VAL(SLEEP, WAKE_HOUR);
+ tmp = strchr(wt, ':');
+ if (tmp) {
+ *tmp = '\0';
+ tmp++;
+ ret = para_atoi32(tmp, &min);
+ if (ret < 0) {
+ free(wt);
+ return ret;
+ }
+ }
+ ret = para_atoi32(wt, &hour);
+ free(wt);
+ if (ret < 0)
+ return ret;
+ if (wake_time[0] == '+') { /* relative */
+ t1 += hour * 60 * 60 + min * 60;
+ tm = localtime(&t1);
+ } else {
tm = localtime(&t1);
if (tm->tm_hour > hour || (tm->tm_hour == hour && tm->tm_min> min)) {
t1 += 86400; /* wake time is tomorrow */
tm->tm_hour = hour;
tm->tm_min = min;
tm->tm_sec = 0;
- } else {
- t1 += 9 * 60 * 60; /* nine hours from now */
- PARA_INFO_LOG("default wake time: %lu\n", (long unsigned)t1);
- tm = localtime(&t1);
}
wake_time_epoch = mktime(tm);
PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);