1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
From b36908b21def4916b10c62ae3e28cacb9073556e Mon Sep 17 00:00:00 2001
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Date: Tue, 18 Aug 2009 22:28:09 +0200
Subject: [PATCH] add simple beep applet, second version
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
---
include/applets.h | 1 +
include/usage.h | 9 +++++
miscutils/Config.in | 6 +++
miscutils/Kbuild | 1 +
miscutils/beep.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 118 insertions(+), 0 deletions(-)
create mode 100644 miscutils/beep.c
diff --git a/include/applets.h b/include/applets.h
index 32c596d..5ddbfe4 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -80,6 +80,7 @@ USE_ASH(APPLET(ash, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER, awk))
USE_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER, basename))
USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER))
+USE_BEEP(APPLET(beep, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
//USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_BLKID(APPLET(blkid, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
diff --git a/include/usage.h b/include/usage.h
index bfacc56..ac8669c 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -142,6 +142,15 @@
"$ basename /foo/bar.txt .txt\n" \
"bar"
+#define beep_trivial_usage \
+ "-f freq -l length -d delay -r repetitions"
+#define beep_full_usage "\n\n" \
+ "Options:\n" \
+ "\n -f Frequency in Hz" \
+ "\n -l Length in ms" \
+ "\n -d Delay in ms" \
+ "\n -r Repetitions" \
+
#define fbsplash_trivial_usage \
"-s IMGFILE [-c] [-d DEV] [-i INIFILE] [-f CMD]"
#define fbsplash_full_usage "\n\n" \
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 7feaf4a..e56a3fc 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -19,6 +19,12 @@ config BBCONFIG
The bbconfig applet will print the config file with which
busybox was built.
+config BEEP
+ bool "beep"
+ default n
+ help
+ The beep applets beeps in a given freq/Hz.
+
config CHAT
bool "chat"
default n
diff --git a/miscutils/Kbuild b/miscutils/Kbuild
index 23d7d8d..8cf3406 100644
--- a/miscutils/Kbuild
+++ b/miscutils/Kbuild
@@ -7,6 +7,7 @@
lib-y:=
lib-$(CONFIG_ADJTIMEX) += adjtimex.o
lib-$(CONFIG_BBCONFIG) += bbconfig.o
+lib-$(CONFIG_BEEP) += beep.o
lib-$(CONFIG_CHAT) += chat.o
lib-$(CONFIG_CHRT) += chrt.o
lib-$(CONFIG_CROND) += crond.o
diff --git a/miscutils/beep.c b/miscutils/beep.c
new file mode 100644
index 0000000..81755d8
--- /dev/null
+++ b/miscutils/beep.c
@@ -0,0 +1,101 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * beep implementation for busybox
+ *
+ * Copyright (C) 2009 Bernhard Reutner-Fischer
+ *
+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ *
+ */
+
+#include "libbb.h"
+
+#include <linux/kd.h>
+#ifndef CLOCK_TICK_RATE
+#define CLOCK_TICK_RATE 1193180
+#endif
+
+#define OPT_f (1<<0)
+#define OPT_l (1<<1)
+#define OPT_d (1<<2)
+#define OPT_r (1<<3)
+/* defaults */
+#define FREQ (4440)
+#define LENGTH (50)
+#define DELAY (0)
+#define REPETITIONS (1)
+#if 0
+typedef struct beep {
+ struct beep *next;
+ unsigned freq, length, delay, rep;
+} beep_t;
+static beep_t* new_beep(void) {
+ beep_t *beep = (beep_t*)xzalloc(sizeof(beep_t));
+ beep->freq = FREQ;
+ beep->length = LENGTH;
+ beep->delay = DELAY;
+ beep->rep = REPETITIONS;
+ return beep;
+}
+#endif
+#define GET_ARG do { if (!*++opt) opt = *++argv; } while (0)
+#define NEW_BEEP() { \
+ freq = FREQ; \
+ length = LENGTH; \
+ delay = DELAY; \
+ rep = REPETITIONS; \
+ }
+
+int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int beep_main(int argc UNUSED_PARAM, char **argv)
+{
+ int speaker = get_console_fd_or_die();
+ unsigned freq, length, delay, rep;
+ unsigned long ioctl_arg;
+
+ NEW_BEEP()
+ while (*++argv) {
+ char *opt = *argv;
+
+ while (*opt == '-')
+ ++opt;
+
+ switch (*opt) {
+ case 'f':
+ GET_ARG;
+ freq = xatoul(opt);
+ continue;
+ case 'l':
+ GET_ARG;
+ length = xatoul(opt);
+ continue;
+ case 'd':
+ GET_ARG;
+ delay = xatoul(opt);
+ continue;
+ case 'r':
+ GET_ARG;
+ freq = xatoul(opt);
+ continue;
+ case 'n':
+ break;
+ default:
+ bb_show_usage();
+ break;
+ }
+ while (rep) {
+//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
+ ioctl_arg = (int)(CLOCK_TICK_RATE/freq);
+ xioctl(speaker, KIOCSOUND, (void*)ioctl_arg);
+ usleep(1000 * length);
+ ioctl(speaker, KIOCSOUND, 0);
+ if (rep--)
+ usleep(delay);
+ }
+ if (opt && *opt == 'n')
+ NEW_BEEP()
+ }
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(speaker);
+ return EXIT_SUCCESS;
+}
--
1.6.4
|