#define _XOPEN_SOURCE 500 #include #include #include #include #include int main(int argc, char **argv) { const char *dev = NULL; int fd, freq = 1000, duration = 100000; unsigned long snd_bits; struct input_event event; opterr = 1; while (1) { switch (getopt(argc, argv, "d:f:t:")) { case 'd': dev = optarg; continue; case 'f': freq = strtol(optarg, NULL, 0); continue; case 't': duration = strtol(optarg, NULL, 0); continue; case -1: break; default: continue;; } break; } fd = open(dev, O_WRONLY); if (fd < 0) { perror("open"); return 1; } if (ioctl(fd, EVIOCGBIT(EV_SND, sizeof snd_bits), &snd_bits) == -1) { perror("ioctl"); return 1; } if (snd_bits & (1 << SND_TONE)) { event.code = SND_TONE; } else if (snd_bits & (1 << SND_BELL)) { event.code = SND_BELL; } else { puts("Neither SND_TONE nor SND_BELL is supported."); return 1; } event.type = EV_SND; event.value = freq; if (write(fd, &event, sizeof event) < 0) { perror("write"); } usleep(duration); event.value = 0; if (write(fd, &event, sizeof event) < 0) { perror("write"); } return 0; }