Re: /proc/beep
From: Neil Brown (neilb_at_cse.unsw.edu.au)
Date: 09/11/03
- Previous message: Hal: "BUG: missing config options in 2.6.0-test5-bk1 arch PPC"
- Next in thread: Frank Cusack: "Re: /proc/beep"
- Reply: Frank Cusack: "Re: /proc/beep"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: Frank Cusack <fcusack@fcusack.com> Date: Thu, 11 Sep 2003 14:42:21 +1000
On Wednesday September 10, fcusack@fcusack.com wrote:
> /proc/beep is a kernel tweak that sends beep "signals" to a userspace
> process reading the /proc/beep file. There are one or two of these
> modules you can find on the Internet. In order to support them the
> kernel needs to export kd_mksound.
>
> Would a /proc/beep module be accepted into the main tree? From the
> ones I've found, I can understand why they might not be accepted. But
> I'm willing to do the [small amount of] work required to get one looking
> like other kernel modules.
>
> If not, could at least kd_mksound be exported by default anyway? This
> would allow homegrown /proc/beep's to not require any kernel mods.
The equivalent can be done with the "input layer" in 2.6.
Open /dev/input/uinput and register yourself as a beep handler, and
you get the beeps instead of the speaker.
The following code does this (but doesn't claim to be well written,
portable, reliable, secure, or anything else).
It requires you do be runnig 'esd' and to have loaded some sample into
esd. The sample is played instead of any beep.
NeilBrown
/*
* A user event handler that notices bells and
* echos something
*/
#include <linux/input.h>
#include <linux/uinput.h>
#include <fcntl.h>
#include <stdio.h>
main(int argc, char *argv[])
{
char *dev = "/dev/input/user";
int fd;
int esd,id;
struct input_event ev;
struct uinput_user_dev dv;
if (argc >= 2)
dev = argv[1];
fd = open(dev, O_RDWR, 0);
if (!fd) {
perror(dev);
exit(1);
}
memset(&dv, 0, sizeof(dv));
strcpy(dv.name, "Quiet Bell");
dv.id.bustype = 0;
dv.id.vendor = 0;
dv.id.product = 0;
dv.id.version = 1;
if (write(fd, &dv, sizeof(dv)) != sizeof(dv)) {
perror("Write device name");
exit(1);
}
if (ioctl(fd, UI_SET_EVBIT, EV_SND)) {
perror("Cannot request snd event");
exit(1);
}
if (ioctl(fd, UI_SET_SNDBIT, 0)) {
perror("Cannot request Click");
exit(1);
}
if (ioctl(fd, UI_SET_SNDBIT, 1)) {
perror("Cannot request Bell");
exit(1);
}
if (ioctl(fd, UI_SET_SNDBIT, 2)) {
perror("Cannot request Tone");
exit(1);
}
if (ioctl(fd, UI_DEV_CREATE, NULL)) {
perror("Create uinput dev");
exit(1);
}
if (argc > 2) {
esd = esd_open_sound(NULL);
id = esd_sample_getid(esd, argv[2]);
}
while (read(fd, &ev, sizeof(ev)) == sizeof(ev)) {
if (argc <= 2)
printf("%d %d %d\n", ev.type, ev.code, ev.value);
else if (ev.type == 18 && ev.code == 2 && ev.value > 0)
esd_sample_play(esd, id);
}
exit(0);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- Previous message: Hal: "BUG: missing config options in 2.6.0-test5-bk1 arch PPC"
- Next in thread: Frank Cusack: "Re: /proc/beep"
- Reply: Frank Cusack: "Re: /proc/beep"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|