[Pommed-commits] r361 - in trunk: . pommed pommed/data
jblache at alioth.debian.org
jblache at alioth.debian.org
Mon Oct 1 14:40:02 UTC 2007
Author: jblache
Date: 2007-10-01 14:40:02 +0000 (Mon, 01 Oct 2007)
New Revision: 361
Added:
trunk/pommed/beep.c
trunk/pommed/beep.h
trunk/pommed/data/
trunk/pommed/data/KDE_Beep_Beep.wav
Modified:
trunk/AUTHORS
trunk/ChangeLog
trunk/INSTALL
trunk/pommed.conf.mactel
trunk/pommed.conf.pmac
trunk/pommed/Makefile
trunk/pommed/conffile.c
trunk/pommed/conffile.h
trunk/pommed/evdev.c
trunk/pommed/pommed.c
Log:
Add a beeper to pommed, to replace the missing PC Speaker on Apple laptops.
Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/AUTHORS 2007-10-01 14:40:02 UTC (rev 361)
@@ -17,7 +17,10 @@
On PowerBook machines, pommed uses the OFlib written by
Alastair Poole <netstar at gatheringofgray.com>
+The beep sound KDE_Beep_Beep.wav included with pommed was taken from the kdebase
+package, version 3.5.7, under the GPL.
+
gpomme
------
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/ChangeLog 2007-10-01 14:40:02 UTC (rev 361)
@@ -2,8 +2,10 @@
--------------------
version 1.10:
+ - pommed: add a beeper feature as a substitute to the missing PC
+ Speaker. The feature is disabled by default, as not all machines
+ need it and not everybody wants it ;)
-
version 1.9:
- pommed: add an idle timer to automatically switch off the
keyboard backlight. Suggested by Javier Marcet.
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/INSTALL 2007-10-01 14:40:02 UTC (rev 361)
@@ -16,6 +16,7 @@
- libconfuse
- libdbus
- libasound
+ - libaudiofile
- libofapi (aka oflib); see below
- eject
@@ -45,6 +46,7 @@
To install pommed:
- copy pommed somewhere in your PATH (/usr/bin)
+ - install pommed/data as /usr/share/pommed
- copy pommed.conf.(mactel|pmac) as /etc/pommed.conf
- copy dbus-policy.conf as /etc/dbus-1/system.d/pommed.conf
- restart dbus
Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed/Makefile 2007-10-01 14:40:02 UTC (rev 361)
@@ -8,17 +8,20 @@
ALSA_CFLAGS = $(shell pkg-config alsa --cflags)
ALSA_LIBS = $(shell pkg-config alsa --libs)
+AUDIOFILE_CFLAGS = $(shell pkg-config audiofile --cflags)
+AUDIOFILE_LIBS = $(shell pkg-config audiofile --libs)
+
CONFUSE_CFLAGS = $(shell pkg-config libconfuse --cflags)
CONFUSE_LIBS = $(shell pkg-config libconfuse --libs)
-CFLAGS = -g -O2 -Wall $(DBUS_CFLAGS) $(ALSA_CFLAGS) $(CONFUSE_CFLAGS)
+CFLAGS = -g -O2 -Wall $(DBUS_CFLAGS) $(ALSA_CFLAGS) $(AUDIOFILE_CFLAGS) $(CONFUSE_CFLAGS)
ifeq ($(ARCH), ppc)
OFLIB ?=
-LDFLAGS = -lz $(DBUS_LIBS) $(ALSA_LIBS) $(CONFUSE_LIBS)
+LDFLAGS = -lz $(DBUS_LIBS) $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(CONFUSE_LIBS)
-SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c power.c \
+SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c power.c beep.c \
pmac/sysfs_backlight.c pmac/pmu.c \
pmac/kbd_backlight.c pmac/ambient.c
@@ -36,9 +39,9 @@
else
-LDFLAGS = -lz -lsmbios $(DBUS_LIBS) $(ALSA_LIBS) $(CONFUSE_LIBS)
+LDFLAGS = -lz -lsmbios $(DBUS_LIBS) $(ALSA_LIBS) $(AUDIOFILE_LIBS) $(CONFUSE_LIBS)
-SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c power.c \
+SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c power.c beep.c \
mactel/x1600_backlight.c mactel/gma950_backlight.c \
mactel/nv8600mgt_backlight.c \
mactel/kbd_backlight.c mactel/ambient.c mactel/acpi.c
@@ -51,13 +54,13 @@
pommed: $(OBJS) $(LIBS)
-pommed.o: pommed.c pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h evdev.h conffile.h audio.h dbus.h
+pommed.o: pommed.c pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h evdev.h conffile.h audio.h dbus.h beep.h
cd_eject.o: cd_eject.c cd_eject.h pommed.h conffile.h dbus.h
-evdev.o: evdev.c evdev.h pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h conffile.h audio.h
+evdev.o: evdev.c evdev.h pommed.h kbd_backlight.h lcd_backlight.h cd_eject.h conffile.h audio.h beep.h
-conffile.o: conffile.c conffile.h pommed.h lcd_backlight.h kbd_backlight.h cd_eject.h audio.h
+conffile.o: conffile.c conffile.h pommed.h lcd_backlight.h kbd_backlight.h cd_eject.h audio.h beep.h
audio.o: audio.c audio.h pommed.h conffile.h dbus.h
@@ -65,7 +68,9 @@
power.o: power.c power.h pommed.h lcd_backlight.h
+beep.o: beep.c beep.h pommed.h audio.h
+
# PowerMac-specific files
pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
Added: trunk/pommed/beep.c
===================================================================
--- trunk/pommed/beep.c (rev 0)
+++ trunk/pommed/beep.c 2007-10-01 14:40:02 UTC (rev 361)
@@ -0,0 +1,518 @@
+/*
+ * pommed - Apple laptops hotkeys handler daemon
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org>
+ * Copyright (C) 2006 Soeren SONNENBURG <debian at nn7.de>
+ *
+ * Portions of the code below dealing with the audio thread were shamelessly
+ * stolen from pbbuttonsd. Thanks ! ;-)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <errno.h>
+
+#include <syslog.h>
+
+#include <linux/input.h>
+#include <linux/uinput.h>
+
+#include <pthread.h>
+
+#define NDEBUG
+#include <alsa/asoundlib.h>
+
+#include <audiofile.h>
+
+#include "pommed.h"
+#include "conffile.h"
+#include "audio.h"
+#include "beep.h"
+
+
+
+/* Added to linux/input.h after Linux 2.6.18 */
+#ifndef BUS_VIRTUAL
+# define BUS_VIRTUAL 0x06
+#endif
+
+
+struct _beep_info beep_info;
+
+
+/* Beep thread */
+static void
+beep_thread_command(int command);
+
+static void
+beep_thread_cleanup(void);
+
+static int
+beep_thread_init(void);
+
+
+void
+beep_beep(void)
+{
+ if (beep_cfg.enabled == 0)
+ return;
+
+ if (audio_info.muted)
+ return;
+
+ beep_thread_command(AUDIO_CLICK);
+}
+
+int
+beep_open_device(void)
+{
+ struct uinput_user_dev dv;
+ int fd;
+ int ret;
+
+ if (beep_cfg.enabled == 0)
+ return -1;
+
+ fd = open("/dev/input/uinput", O_RDWR, 0);
+ if (fd < 0)
+ {
+ logmsg(LOG_ERR, "beep: could not open /dev/input/uinput: %s", strerror(errno));
+ logmsg(LOG_ERR, "beep: Do you have the uinput module loaded?");
+
+ return -1;
+ }
+
+ memset(&dv, 0, sizeof(dv));
+ strcpy(dv.name, BEEP_DEVICE_NAME);
+ dv.id.bustype = BUS_VIRTUAL;
+ dv.id.vendor = 0;
+ dv.id.product = 0;
+ dv.id.version = 1;
+
+ ret = write(fd, &dv, sizeof(dv));
+ if (ret != sizeof(dv))
+ {
+ logmsg(LOG_ERR, "beep: could not set device name: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ ret = ioctl(fd, UI_SET_EVBIT, EV_SND);
+ if (ret != 0)
+ {
+ logmsg(LOG_ERR, "beep: could not request EV_SND: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ ret = ioctl(fd, UI_SET_SNDBIT, SND_BELL);
+ if (ret != 0)
+ {
+ logmsg(LOG_ERR, "beep: could not request SND_BELL: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ ret = ioctl(fd, UI_SET_SNDBIT, SND_TONE);
+ if (ret != 0)
+ {
+ logmsg(LOG_ERR, "beep: could not request SND_TONE: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ ret = ioctl(fd, UI_DEV_CREATE, NULL);
+ if (ret != 0)
+ {
+ logmsg(LOG_ERR, "beep: could not create uinput device: %s", strerror(errno));
+
+ close(fd);
+ return -1;
+ }
+
+ beep_info.fd = fd;
+
+ return 0;
+}
+
+void
+beep_close_device(void)
+{
+ if (beep_cfg.enabled == 0)
+ return;
+
+ ioctl(beep_info.fd, UI_DEV_DESTROY, NULL);
+
+ close(beep_info.fd);
+
+ beep_info.fd = -1;
+}
+
+
+int
+beep_init(void)
+{
+ int ret;
+
+ if (beep_cfg.enabled == 0)
+ return 0;
+
+ ret = beep_thread_init();
+ if (ret < 0)
+ {
+ logmsg(LOG_ERR, "beep: thread init failed, disabling");
+
+ beep_cfg.enabled = 0;
+
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+beep_cleanup(void)
+{
+ if (beep_cfg.enabled == 0)
+ return;
+
+ beep_thread_command(AUDIO_COMMAND_QUIT);
+ beep_thread_cleanup();
+}
+
+void
+beep_fix_config(void)
+{
+ if (beep_cfg.enabled == 0)
+ return;
+
+ if (beep_cfg.beepfile == NULL)
+ beep_cfg.beepfile = strdup(BEEP_DEFAULT_FILE);
+
+ if (access(beep_cfg.beepfile, R_OK) != 0)
+ {
+ logmsg(LOG_WARNING, "beep: cannot access WAV file %s: %s", beep_cfg.beepfile, strerror(errno));
+
+ if (access(BEEP_DEFAULT_FILE, R_OK) == 0)
+ {
+ logmsg(LOG_WARNING, "beep: falling back to default file %s", BEEP_DEFAULT_FILE);
+
+ free(beep_cfg.beepfile);
+ beep_cfg.beepfile = strdup(BEEP_DEFAULT_FILE);
+ }
+ else
+ {
+ logmsg(LOG_ERR, "beep: cannot access default file %s: %s", BEEP_DEFAULT_FILE, strerror(errno));
+ logmsg(LOG_ERR, "beep: disabling beeper");
+
+ beep_cfg.enabled = 0;
+ }
+ }
+}
+
+
+/*
+ * Beep thread - taken from gpomme
+ * If there's a bug somewhere below, it's also in gpomme, so please fix it there too.
+ */
+
+struct dspdata _dsp;
+
+/* Called from the main thread */
+static struct sample *
+beep_load_sample(char *filename)
+{
+ AFfilehandle affd; /* filehandle for soundfile from libaudiofile */
+ AFframecount framecount;
+ int dummy, channels, byteorder, framesize, precision, err = 0;
+ struct sample *sample;
+
+ int ret;
+
+ sample = (struct sample *) malloc(sizeof(struct sample));
+ if (sample == NULL)
+ return NULL;
+
+ affd = afOpenFile(filename, "r", 0);
+ if (affd > 0)
+ {
+ afGetSampleFormat(affd, AF_DEFAULT_TRACK, &dummy, &precision);
+ channels = afGetChannels(affd, AF_DEFAULT_TRACK);
+ byteorder = afGetVirtualByteOrder(affd, AF_DEFAULT_TRACK);
+ framesize = (int) afGetFrameSize(affd, AF_DEFAULT_TRACK, 0);
+ framecount = afGetFrameCount(affd, AF_DEFAULT_TRACK);
+ sample->speed = (int) afGetRate(affd, AF_DEFAULT_TRACK);
+
+ if (channels <= 2)
+ sample->channels = channels;
+ else
+ err = -1;
+
+ if (precision == 8)
+ sample->format = SND_PCM_FORMAT_S8;
+ else if (precision == 16)
+ {
+ if (byteorder == AF_BYTEORDER_LITTLEENDIAN)
+ sample->format = SND_PCM_FORMAT_S16_LE;
+ else
+ sample->format = SND_PCM_FORMAT_S16_BE;
+ }
+ else
+ err = -1;
+
+ if (err == 0)
+ {
+ sample->framesize = framesize;
+ sample->framecount = framecount;
+ sample->audiodatalen = framecount * framesize;
+
+ sample->audiodata = (char *) malloc(sample->audiodatalen);
+ if (sample->audiodata != NULL)
+ {
+ ret = afReadFrames(affd, AF_DEFAULT_TRACK, sample->audiodata, framecount);
+ if (ret != framecount)
+ {
+ free(sample->audiodata);
+ err = -1;
+ }
+ }
+ else
+ ret = -1;
+ }
+ afCloseFile(affd);
+ }
+
+ if (err == -1)
+ {
+ free(sample);
+ return NULL;
+ }
+
+ sample->periods = sample->framesize;
+ sample->buffersize = (sample->periods * 8192) >> 2;
+
+ return sample;
+}
+
+
+/* Called from the audio thread */
+static void
+beep_play_sample(struct dspdata *dsp, int cmd)
+{
+ snd_pcm_t *pcm_handle;
+ snd_pcm_hw_params_t *hwparams;
+
+ char *pcm_name = "default";
+
+ struct sample *s = dsp->sample[cmd];
+
+ snd_pcm_hw_params_alloca(&hwparams);
+
+ if (snd_pcm_open(&pcm_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, 0) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error opening PCM device %s", pcm_name);
+ return;
+ }
+
+ if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: cannot configure PCM device");
+ return;
+ }
+
+ if (snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting access");
+ return;
+ }
+
+ if (snd_pcm_hw_params_set_format(pcm_handle, hwparams, s->format) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting format");
+ return;
+ }
+
+ if (snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &s->speed, 0) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting rate");
+ return;
+ }
+
+ /* Set number of channels */
+ if (snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &s->channels) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting channels");
+ return;
+ }
+
+ /* Set number of periods. Periods used to be called fragments. */
+ if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &s->periods, 0) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting periods");
+ return;
+ }
+
+ /* Set buffer size (in frames). The resulting latency is given by */
+ /* latency = periodsize * periods / (rate * bytes_per_frame) */
+ if (snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &s->buffersize) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting buffersize");
+ return;
+ }
+
+ /* Apply HW parameter settings to */
+ /* PCM device and prepare device */
+ if (snd_pcm_hw_params(pcm_handle, hwparams) < 0)
+ {
+ logmsg(LOG_WARNING, "beep: error setting HW params");
+ return;
+ }
+
+ int pcmreturn;
+ /* Write num_frames frames from buffer data to */
+ /* the PCM device pointed to by pcm_handle. */
+ /* Returns the number of frames actually written. */
+ while ((pcmreturn = snd_pcm_writei(pcm_handle, s->audiodata, s->framecount)) < 0)
+ {
+ snd_pcm_prepare(pcm_handle);
+ }
+
+ /* Stop PCM device and drop pending frames */
+ snd_pcm_drop(pcm_handle);
+
+ /* Stop PCM device after pending frames have been played */
+ snd_pcm_close(pcm_handle);
+}
+
+
+/* Called from the audio thread
+ * Audio thread main loop
+ */
+void *
+beep_thread (void *arg)
+{
+ struct dspdata *dsp = (struct dspdata *) arg;
+ for (;;)
+ {
+ pthread_mutex_lock(&dsp->mutex);
+ pthread_cond_wait(&dsp->cond, &dsp->mutex);
+ pthread_mutex_unlock(&dsp->mutex);
+
+ switch (dsp->command)
+ {
+ case AUDIO_CLICK:
+ dsp->command = AUDIO_COMMAND_NONE;
+
+ beep_play_sample(dsp, AUDIO_CLICK);
+ break;
+ case AUDIO_COMMAND_QUIT:
+ pthread_exit(NULL);
+ break;
+ case AUDIO_COMMAND_NONE:
+ break;
+ }
+ }
+
+ return NULL;
+}
+
+
+/* Called from the main thread
+ * This function wakes the audio thread
+ */
+static void
+beep_thread_command(int command)
+{
+ if (!_dsp.sample)
+ return;
+
+ pthread_mutex_lock(&(_dsp.mutex));
+
+ _dsp.command = command;
+
+ pthread_cond_signal(&(_dsp.cond));
+ pthread_mutex_unlock(&(_dsp.mutex));
+}
+
+
+/* Called from the main thread */
+static void
+beep_thread_cleanup(void)
+{
+ int i;
+
+ if (!_dsp.sample)
+ return;
+
+ for (i = 0; i < AUDIO_N; i++)
+ {
+ if (_dsp.sample[i] == NULL)
+ continue;
+
+ if (_dsp.sample[i]->audiodata != NULL)
+ free(_dsp.sample[i]->audiodata);
+
+ free(_dsp.sample[i]);
+ }
+
+ pthread_mutex_destroy(&(_dsp.mutex));
+ pthread_cond_destroy(&(_dsp.cond));
+}
+
+/* Called from the main thread
+ * This function sets up the sound playing thread.
+ * It starts the thread or if an error occur cleans
+ * up all the audio stuff
+ */
+static int
+beep_thread_init(void)
+{
+ pthread_attr_t attr;
+ int ret;
+
+ _dsp.sample[AUDIO_CLICK] = beep_load_sample(beep_cfg.beepfile);
+
+ if (_dsp.sample[AUDIO_CLICK] == NULL)
+ return -1;
+
+ _dsp.thread = 0;
+
+ pthread_mutex_init(&(_dsp.mutex), NULL);
+ pthread_cond_init (&(_dsp.cond), NULL);
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+ ret = pthread_create(&(_dsp.thread), &attr, beep_thread, (void *) &_dsp);
+ if (ret != 0)
+ {
+ beep_thread_cleanup();
+ ret = -1;
+ }
+
+ pthread_attr_destroy(&attr);
+
+ return ret;
+}
Property changes on: trunk/pommed/beep.c
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/pommed/beep.h
===================================================================
--- trunk/pommed/beep.h (rev 0)
+++ trunk/pommed/beep.h 2007-10-01 14:40:02 UTC (rev 361)
@@ -0,0 +1,67 @@
+/*
+ * $Id$
+ */
+
+#ifndef __BEEP_H__
+#define __BEEP_H__
+
+struct _beep_info
+{
+ int fd;
+};
+
+extern struct _beep_info beep_info;
+
+
+#define BEEP_DEFAULT_FILE "/usr/share/pommed/beep.wav"
+#define BEEP_DEVICE_NAME "Pommed beeper device"
+
+void
+beep_beep(void);
+
+int
+beep_open_device(void);
+
+void
+beep_close_device(void);
+
+int
+beep_init(void);
+
+void
+beep_cleanup(void);
+
+void
+beep_fix_config(void);
+
+
+/* Beep thread data definitions */
+struct sample {
+ char *audiodata;
+ int audiodatalen;
+ int format;
+ unsigned int channels;
+ unsigned int speed;
+ unsigned int framesize;
+ int framecount;
+ unsigned int periods;
+ unsigned long buffersize;
+};
+
+enum {
+ AUDIO_COMMAND_NONE = -2,
+ AUDIO_COMMAND_QUIT = -1,
+ AUDIO_CLICK = 0,
+ AUDIO_N /* keep this one last */
+};
+
+struct dspdata {
+ int command;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ pthread_t thread;
+ struct sample *sample[AUDIO_N]; /* sound to play */
+};
+
+
+#endif /* !__BEEP_H__ */
Property changes on: trunk/pommed/beep.h
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/pommed/conffile.c
===================================================================
--- trunk/pommed/conffile.c 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed/conffile.c 2007-10-01 14:40:02 UTC (rev 361)
@@ -32,6 +32,7 @@
#include "lcd_backlight.h"
#include "kbd_backlight.h"
#include "cd_eject.h"
+#include "beep.h"
#include "audio.h"
@@ -46,6 +47,7 @@
struct _audio_cfg audio_cfg;
struct _kbd_cfg kbd_cfg;
struct _eject_cfg eject_cfg;
+struct _beep_cfg beep_cfg;
#ifndef __powerpc__
struct _appleir_cfg appleir_cfg;
#endif
@@ -124,6 +126,13 @@
CFG_END()
};
+static cfg_opt_t beep_opts[] =
+ {
+ CFG_BOOL("enabled", 0, CFGF_NONE),
+ CFG_STR("beepfile", BEEP_DEFAULT_FILE, CFGF_NONE),
+ CFG_END()
+ };
+
#ifndef __powerpc__
static cfg_opt_t appleir_opts[] =
{
@@ -145,6 +154,7 @@
CFG_SEC("audio", audio_opts, CFGF_NONE),
CFG_SEC("kbd", kbd_opts, CFGF_NONE),
CFG_SEC("eject", eject_opts, CFGF_NONE),
+ CFG_SEC("beep", beep_opts, CFGF_NONE),
#ifndef __powerpc__
CFG_SEC("appleir", appleir_opts, CFGF_NONE),
#endif
@@ -223,6 +233,9 @@
printf(" + CD eject:\n");
printf(" enabled: %s\n", (eject_cfg.enabled) ? "yes" : "no");
printf(" device: %s\n", eject_cfg.device);
+ printf(" + Beep:\n");
+ printf(" enabled: %s\n", (beep_cfg.enabled) ? "yes" : "no");
+ printf(" beepfile: %s\n", beep_cfg.beepfile);
#ifndef __powerpc__
printf(" + Apple Remote IR Receiver:\n");
printf(" enabled: %s\n", (appleir_cfg.enabled) ? "yes" : "no");
@@ -278,6 +291,8 @@
cfg_set_validate_func(cfg, "kbd|off_threshold", config_validate_positive_integer);
/* CD eject */
cfg_set_validate_func(cfg, "eject|device", config_validate_string);
+ /* beep */
+ cfg_set_validate_func(cfg, "beep|beepfile", config_validate_string);
/*
* Do the actual parsing.
@@ -355,6 +370,11 @@
eject_cfg.device = strdup(cfg_getstr(sec, "device"));
cd_eject_fix_config();
+ sec = cfg_getsec(cfg, "beep");
+ beep_cfg.enabled = cfg_getbool(sec, "enabled");
+ beep_cfg.beepfile = strdup(cfg_getstr(sec, "beepfile"));
+ beep_fix_config();
+
#ifndef __powerpc__
sec = cfg_getsec(cfg, "appleir");
appleir_cfg.enabled = cfg_getbool(sec, "enabled");
@@ -377,4 +397,6 @@
free(audio_cfg.head);
free(eject_cfg.device);
+
+ free(beep_cfg.beepfile);
}
Modified: trunk/pommed/conffile.h
===================================================================
--- trunk/pommed/conffile.h 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed/conffile.h 2007-10-01 14:40:02 UTC (rev 361)
@@ -61,6 +61,11 @@
char *device;
};
+struct _beep_cfg {
+ int enabled;
+ char *beepfile;
+};
+
#ifndef __powerpc__
struct _appleir_cfg {
int enabled;
@@ -79,6 +84,7 @@
extern struct _audio_cfg audio_cfg;
extern struct _kbd_cfg kbd_cfg;
extern struct _eject_cfg eject_cfg;
+extern struct _beep_cfg beep_cfg;
#ifndef __powerpc__
extern struct _appleir_cfg appleir_cfg;
#endif
Added: trunk/pommed/data/KDE_Beep_Beep.wav
===================================================================
(Binary files differ)
Property changes on: trunk/pommed/data/KDE_Beep_Beep.wav
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/pommed/evdev.c
===================================================================
--- trunk/pommed/evdev.c 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed/evdev.c 2007-10-01 14:40:02 UTC (rev 361)
@@ -41,6 +41,7 @@
#include "lcd_backlight.h"
#include "cd_eject.h"
#include "audio.h"
+#include "beep.h"
#define BITS_PER_LONG (sizeof(long) * 8)
@@ -186,6 +187,16 @@
break;
}
}
+ else if (ev.type == EV_SND)
+ {
+ /* Beeper device */
+ if ((ev.code == SND_TONE) && (ev.value > 0))
+ {
+ logdebug("\nBEEP: BEEP!\n");
+
+ beep_beep(); /* Catch that, Coyote */
+ }
+ }
else if (ev.type == EV_SW)
{
/* Lid switch
@@ -548,7 +559,8 @@
logdebug("\nFound %d devices\n", found);
- *fds = (struct pollfd *) malloc(found * sizeof(struct pollfd));
+ /* Allocate found pollfd structs + 1 for the beeper */
+ *fds = (struct pollfd *) malloc((found + 1) * sizeof(struct pollfd));
if (*fds == NULL)
{
@@ -574,6 +586,14 @@
j++;
}
+ ret = beep_open_device();
+ if (ret == 0)
+ {
+ (*fds)[j].fd = beep_info.fd;
+ (*fds)[j].events = POLLIN;
+ found++;
+ }
+
return found;
}
@@ -585,7 +605,12 @@
if (*fds != NULL)
{
for (i = 0; i < nfds; i++)
- close((*fds)[i].fd);
+ {
+ if ((*fds)[i].fd == beep_info.fd)
+ beep_close_device();
+ else
+ close((*fds)[i].fd);
+ }
free(*fds);
}
Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed/pommed.c 2007-10-01 14:40:02 UTC (rev 361)
@@ -54,6 +54,7 @@
#include "audio.h"
#include "dbus.h"
#include "power.h"
+#include "beep.h"
/* Machine-specific operations */
@@ -710,6 +711,8 @@
exit(1);
}
+ beep_init();
+
nfds = evdev_open(&fds);
if (nfds < 1)
{
@@ -868,6 +871,8 @@
evdev_close(&fds, nfds);
+ beep_cleanup();
+
mbpdbus_cleanup();
config_cleanup();
Modified: trunk/pommed.conf.mactel
===================================================================
--- trunk/pommed.conf.mactel 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed.conf.mactel 2007-10-01 14:40:02 UTC (rev 361)
@@ -81,6 +81,14 @@
device = "/dev/dvd"
}
+# Beeper
+beep {
+ # enable/disable beeper
+ enabled = no
+ # WAV file to use
+ beepfile = "/usr/share/pommed/beep.wav"
+}
+
# Apple Remote
appleir {
# enable/disable the appleir support
Modified: trunk/pommed.conf.pmac
===================================================================
--- trunk/pommed.conf.pmac 2007-09-22 16:59:49 UTC (rev 360)
+++ trunk/pommed.conf.pmac 2007-10-01 14:40:02 UTC (rev 361)
@@ -70,3 +70,11 @@
# CD/DVD device
device = "/dev/dvd"
}
+
+# Beeper
+beep {
+ # enable/disable beeper
+ enabled = no
+ # WAV file to use
+ beepfile = "/usr/share/pommed/beep.wav"
+}
More information about the Pommed-commits
mailing list