diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2009-08-21 13:18:31 +0200 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2009-08-21 13:18:31 +0200 |
commit | 45de0746b33b3716101caa5fa08ee601221dce39 (patch) | |
tree | d073e0980d8ee319c7c48999fa5e3278aed3b1b3 /miscutils | |
parent | e10db56aa3e069388e84f7166e05032ba5b89295 (diff) | |
download | busybox-w32-45de0746b33b3716101caa5fa08ee601221dce39.tar.gz busybox-w32-45de0746b33b3716101caa5fa08ee601221dce39.tar.bz2 busybox-w32-45de0746b33b3716101caa5fa08ee601221dce39.zip |
add simple beep applet
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/Config.in | 6 | ||||
-rw-r--r-- | miscutils/Kbuild | 1 | ||||
-rw-r--r-- | miscutils/beep.c | 119 |
3 files changed, 126 insertions, 0 deletions
diff --git a/miscutils/Config.in b/miscutils/Config.in index 689044794..7209d2944 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -19,6 +19,12 @@ config BBCONFIG | |||
19 | The bbconfig applet will print the config file with which | 19 | The bbconfig applet will print the config file with which |
20 | busybox was built. | 20 | busybox was built. |
21 | 21 | ||
22 | config BEEP | ||
23 | bool "beep" | ||
24 | default n | ||
25 | help | ||
26 | The beep applets beeps in a given freq/Hz. | ||
27 | |||
22 | config CHAT | 28 | config CHAT |
23 | bool "chat" | 29 | bool "chat" |
24 | default n | 30 | default n |
diff --git a/miscutils/Kbuild b/miscutils/Kbuild index e378a099f..d88cb39ac 100644 --- a/miscutils/Kbuild +++ b/miscutils/Kbuild | |||
@@ -7,6 +7,7 @@ | |||
7 | lib-y:= | 7 | lib-y:= |
8 | lib-$(CONFIG_ADJTIMEX) += adjtimex.o | 8 | lib-$(CONFIG_ADJTIMEX) += adjtimex.o |
9 | lib-$(CONFIG_BBCONFIG) += bbconfig.o | 9 | lib-$(CONFIG_BBCONFIG) += bbconfig.o |
10 | lib-$(CONFIG_BEEP) += beep.o | ||
10 | lib-$(CONFIG_CHAT) += chat.o | 11 | lib-$(CONFIG_CHAT) += chat.o |
11 | lib-$(CONFIG_CHRT) += chrt.o | 12 | lib-$(CONFIG_CHRT) += chrt.o |
12 | lib-$(CONFIG_CROND) += crond.o | 13 | lib-$(CONFIG_CROND) += crond.o |
diff --git a/miscutils/beep.c b/miscutils/beep.c new file mode 100644 index 000000000..d5c353197 --- /dev/null +++ b/miscutils/beep.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * beep implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2009 Bernhard Reutner-Fischer | ||
6 | * | ||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | ||
8 | * | ||
9 | */ | ||
10 | #include "libbb.h" | ||
11 | |||
12 | #include <linux/kd.h> | ||
13 | #ifndef CLOCK_TICK_RATE | ||
14 | #define CLOCK_TICK_RATE 1193180 | ||
15 | #endif | ||
16 | |||
17 | #define OPT_f (1<<0) | ||
18 | #define OPT_l (1<<1) | ||
19 | #define OPT_d (1<<2) | ||
20 | #define OPT_r (1<<3) | ||
21 | /* defaults */ | ||
22 | #define FREQ (4440) | ||
23 | #define LENGTH (50) | ||
24 | #define DELAY (0) | ||
25 | #define REPETITIONS (1) | ||
26 | |||
27 | #define GET_ARG do { if (!*++opt) opt = *++argv; if (opt == NULL) bb_show_usage();} while (0) | ||
28 | #define NEW_BEEP() { \ | ||
29 | freq = FREQ; \ | ||
30 | length = LENGTH; \ | ||
31 | delay = DELAY; \ | ||
32 | rep = REPETITIONS; \ | ||
33 | } | ||
34 | |||
35 | int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
36 | int beep_main(int argc UNUSED_PARAM, char **argv) | ||
37 | { | ||
38 | int speaker = get_console_fd_or_die(); | ||
39 | unsigned freq, length, delay, rep; | ||
40 | unsigned long ioctl_arg; | ||
41 | char *opt = NULL; | ||
42 | bool do_parse = true; | ||
43 | |||
44 | NEW_BEEP() | ||
45 | while (*argv && *++argv) { | ||
46 | opt = *argv; | ||
47 | |||
48 | while (*opt == '-') | ||
49 | ++opt; | ||
50 | if (do_parse) | ||
51 | switch (*opt) { | ||
52 | case 'f': | ||
53 | GET_ARG; | ||
54 | freq = xatoul(opt); | ||
55 | continue; | ||
56 | case 'l': | ||
57 | GET_ARG; | ||
58 | length = xatoul(opt); | ||
59 | continue; | ||
60 | case 'd': | ||
61 | GET_ARG; | ||
62 | delay = xatoul(opt); | ||
63 | continue; | ||
64 | case 'r': | ||
65 | GET_ARG; | ||
66 | rep = xatoul(opt); | ||
67 | continue; | ||
68 | case 'n': | ||
69 | break; | ||
70 | default: | ||
71 | bb_show_usage(); | ||
72 | break; | ||
73 | } | ||
74 | again: | ||
75 | while (rep) { | ||
76 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); | ||
77 | ioctl_arg = (int)(CLOCK_TICK_RATE/freq); | ||
78 | xioctl(speaker, KIOCSOUND, (void*)ioctl_arg); | ||
79 | usleep(1000 * length); | ||
80 | ioctl(speaker, KIOCSOUND, 0); | ||
81 | if (rep--) | ||
82 | usleep(delay); | ||
83 | } | ||
84 | if (opt && *opt == 'n') | ||
85 | NEW_BEEP() | ||
86 | if (!do_parse && *argv == NULL) | ||
87 | goto out; | ||
88 | } | ||
89 | do_parse = false; | ||
90 | goto again; | ||
91 | out: | ||
92 | if (ENABLE_FEATURE_CLEAN_UP) | ||
93 | close(speaker); | ||
94 | return EXIT_SUCCESS; | ||
95 | } | ||
96 | /* | ||
97 | * so, e.g. Beethoven's 9th symphony "Ode an die Freude" would be | ||
98 | * something like: | ||
99 | a=$((220*3)) | ||
100 | b=$((247*3)) | ||
101 | c=$((262*3)) | ||
102 | d=$((294*3)) | ||
103 | e=$((329*3)) | ||
104 | f=$((349*3)) | ||
105 | g=$((392*3)) | ||
106 | #./beep -f$d -l200 -r2 -n -f$e -l100 -d 10 -n -f$c -l400 -f$g -l200 | ||
107 | ./beep -f$e -l200 -r2 \ | ||
108 | -n -d 100 -f$f -l200 \ | ||
109 | -n -f$g -l200 -r2 \ | ||
110 | -n -f$f -l200 \ | ||
111 | -n -f$e -l200 \ | ||
112 | -n -f$d -l200 \ | ||
113 | -n -f$c -l200 -r2 \ | ||
114 | -n -f$d -l200 \ | ||
115 | -n -f$e -l200 \ | ||
116 | -n -f$e -l400 \ | ||
117 | -n -f$d -l100 \ | ||
118 | -n -f$d -l200 \ | ||
119 | */ | ||