/*
- * Copyright (C) 1998-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2011 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
-/** \file fade.c A volume fader and alarm clock for linux. */
+/** \file fade.c A volume fader and alarm clock for OSS. */
#include <regex.h>
#include <sys/types.h>
-#include <dirent.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <stdlib.h> /* EXIT_SUCCESS */
#include "fd.h"
#include "string.h"
#include "error.h"
+#include "version.h"
INIT_FADE_ERRLISTS;
static struct fade_args_info conf;
-__printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...)
+__printf_2_3 void date_log(__a_unused int ll, const char *fmt, ...)
{
va_list argp;
time_t t1;
vprintf(fmt, argp);
va_end(argp);
}
+__printf_2_3 void (*para_log)(int, const char*, ...) = date_log;
/*
- * open mixer device
+ * Open the mixer device.
*/
static int open_mixer(void)
{
+ PARA_INFO_LOG("opening %s\n", conf.mixer_device_arg);
return para_open(conf.mixer_device_arg, O_RDWR, 42);
}
static void fixup_mixer_channel_arg(void)
{
- int val;
+ int val = SOUND_MIXER_VOLUME; /* STFU, gcc */
switch (conf.mixer_channel_arg) {
case mixer_channel_arg_volume: val = SOUND_MIXER_VOLUME; break;
case mixer_channel_arg_reclev: val = SOUND_MIXER_RECLEV; break;
case mixer_channel_arg_igain: val = SOUND_MIXER_IGAIN; break;
case mixer_channel_arg_ogain: val = SOUND_MIXER_OGAIN; break;
+ default: break;
}
conf.mixer_channel_arg = val;
}
/*
* Open mixer, get volume, fade to new_vol in secs seconds and
- * close mixer
+ * close mixer.
*/
static int fade(int new_vol, int fade_time)
{
unsigned int delay;
struct tm *tm;
int ret, min = conf.wake_min_arg;
- char *fa_mode = conf.fa_mode_arg;
- char *wake_mode = conf.wake_mode_arg;
- char *sleep_mode = conf.sleep_mode_arg;
- int wf = conf.wake_fade_arg;
- int sf = conf.fa_fade_arg;
- int wv = conf.wake_vol_arg;
- int sv = conf.fa_vol_arg;
- int iv = conf.sleep_ivol_arg;
+ char *fo_mood = conf.fo_mood_arg;
+ char *fi_mood = conf.fi_mood_arg;
+ char *sleep_mood = conf.sleep_mood_arg;
+ int fit = conf.fi_time_arg;
+ int fot = conf.fo_time_arg;
+ int fiv = conf.fi_vol_arg;
+ int fov = conf.fo_vol_arg;
+ int iv = conf.ivol_arg;
/* calculate wake time */
time(&t1);
PARA_INFO_LOG("waketime: %s", asctime(tm));
client_cmd("stop");
sleep(1);
- if (sf) {
+ if (fot) {
PARA_INFO_LOG("initial volume: %d\n", iv);
ret = open_and_set_mixer_channel(iv);
if (ret < 0)
return ret;
- change_afs_mode_and_play(fa_mode);
- ret = fade(sv, sf);
+ change_afs_mode_and_play(fo_mood);
+ ret = fade(fov, fot);
if (ret < 0)
return ret;
} else {
- ret = open_and_set_mixer_channel(sf);
+ ret = open_and_set_mixer_channel(fov);
if (ret < 0)
return ret;
}
- if (conf.sleep_mode_given)
- change_afs_mode_and_play(sleep_mode);
+ if (conf.sleep_mood_given)
+ change_afs_mode_and_play(sleep_mood);
else
client_cmd("stop");
- if (!wf)
+ if (!fit)
return 1;
for (;;) {
time(&t1);
- if (wake_time_epoch <= t1 + wf)
+ if (wake_time_epoch <= t1 + fit)
break;
- delay = wake_time_epoch - t1 - wf;
+ delay = wake_time_epoch - t1 - fit;
PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
delay, delay / 3600,
(delay % 3600) / 60);
sleep(delay);
}
- change_afs_mode_and_play(wake_mode);
- ret = fade(wv, wf);
+ change_afs_mode_and_play(fi_mood);
+ ret = fade(fiv, fit);
PARA_INFO_LOG("fade complete, returning\n");
return ret;
}
int ret;
unsigned sleep_time;
- if (conf.snooze_time_arg <= 0)
+ if (conf.so_time_arg <= 0)
return 1;
- sleep_time = conf.snooze_time_arg;
- if (open_and_get_mixer_channel() < conf.snooze_out_vol_arg)
- ret = open_and_set_mixer_channel(conf.snooze_out_vol_arg);
+ sleep_time = conf.so_time_arg;
+ if (open_and_get_mixer_channel() < conf.so_vol_arg)
+ ret = open_and_set_mixer_channel(conf.so_vol_arg);
else
- ret = fade(conf.snooze_out_vol_arg, conf.snooze_out_fade_arg);
+ ret = fade(conf.so_vol_arg, conf.so_time_arg);
if (ret < 0)
return ret;
client_cmd("pause");
PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
sleep(sleep_time);
client_cmd("play");
- return fade(conf.snooze_in_vol_arg, conf.snooze_in_fade_arg);
+ return fade(conf.si_vol_arg, conf.si_time_arg);
}
static int configfile_exists(void)
.override = 0,
.initialize = 0,
.check_required = 0,
- .check_ambiguity = 0
+ .check_ambiguity = 0,
+ .print_errors = 1
};
fade_cmdline_parser_config_file(conf.config_file_arg,
&conf, ¶ms);
}
fixup_mixer_channel_arg();
- if (!strcmp(conf.mode_arg, "sleep")) {
- ret = sweet_dreams();
- goto out;
- }
- if (!strcmp(conf.mode_arg, "fade")) {
+ switch (conf.mode_arg) {
+ case mode_arg_fade:
ret = fade(conf.fade_vol_arg, conf.fade_time_arg);
- goto out;
- }
- if (!strcmp(conf.mode_arg, "snooze")) {
+ break;
+ case mode_arg_snooze:
ret = snooze();
- goto out;
+ break;
+ default: /* sleep mode */
+ ret = sweet_dreams();
+ break;
}
- ret = -E_FADE_SYNTAX;
-out:
if (ret < 0)
PARA_EMERG_LOG("%s\n", para_strerror(-ret));
return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;