From: Andre Date: Fri, 23 Jun 2006 08:29:29 +0000 (+0200) Subject: fade: wake time defaults to "8 hours from now" X-Git-Tag: v0.2.14~60^2~2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=1731fa265eddfb0e1a025114e18de44b913e48df;p=paraslash.git fade: wake time defaults to "8 hours from now" For all those shiftmen --- diff --git a/NEWS b/NEWS index 9750b12d..9c8d2cce 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ A bunch of new features and core changes. - random/playlist selector: improved info strings - new audiod commands: tasks, kill - update to libortp-0.10.0 + - para_fade: wake time defaults to 8 hours from now ------------------------------------------ diff --git a/fade.c b/fade.c index b42e4a1c..8dfbcc2f 100644 --- a/fade.c +++ b/fade.c @@ -188,7 +188,6 @@ static void sweet_dreams(void) time_t t1, wake_time_epoch; unsigned int delay; struct tm *tm; - int hour = args_info.wake_hour_arg; int min = args_info.wake_min_arg; char *fa_stream = args_info.fa_stream_arg; char *wake_stream = args_info.wake_stream_arg; @@ -201,6 +200,25 @@ static void sweet_dreams(void) char *cmd, *sleep_stream = args_info.sleep_stream_given? args_info.sleep_stream_arg : NULL; + /* calculate wake time */ + time(&t1); + if (args_info.wake_hour_given) { + int hour = args_info.wake_hour_arg; + tm = localtime(&t1); + if (tm->tm_hour > hour || (tm->tm_hour == hour && tm->tm_min> min)) { + t1 += 86400; /* wake time is tomorrow */ + tm = localtime(&t1); + } + tm->tm_hour = hour; + tm->tm_min = min; + tm->tm_sec = 0; + } else { + t1 += 8 * 60 * 60; + PARA_INFO_LOG("default wake time: %lu\n", t1); + tm = localtime(&t1); + } + wake_time_epoch = mktime(tm); + PARA_INFO_LOG("waketime: %s", asctime(tm)); if (sf) { PARA_INFO_LOG("initial volume: %d\n", iv); set_vol(iv); @@ -217,27 +235,15 @@ static void sweet_dreams(void) client_cmd("stop"); if (!wf) return; - /* calculate wake time */ - time(&t1); - tm = localtime(&t1); - if (tm->tm_hour > hour || (tm->tm_hour == hour && tm->tm_min> min)) { - /* wake time is tomorrow */ - t1 += 86400; - tm = localtime(&t1); - t1 -= 86400; - } - tm->tm_hour = hour; - tm->tm_min = min; - tm->tm_sec = 0; - wake_time_epoch = mktime(tm); - PARA_INFO_LOG("waketime: %s", asctime(tm)); - while (wake_time_epoch > t1 + wf) { + for (;;) { + time(&t1); + if (wake_time_epoch <= t1 + wf) + break; delay = wake_time_epoch - t1 - wf; PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n", delay, delay / 3600, (delay % 3600) / 60); sleep(delay); - time(&t1); } cmd = make_message("csp %s\n", wake_stream); client_cmd(cmd);