On Tue, Aug 18, 2009 at 07:33:20PM +0200, Natanael Copa wrote:
>On Tue, 2009-08-18 at 19:17 +0200, Bernhard Reutner-Fischer wrote:
>> On Tue, Aug 18, 2009 at 07:10:30PM +0200, Natanael Copa wrote:
>> >In case someone have time I'd like to have a 'beep' applet in busybox.
>> >Its handy on headless boxes.
>>
>> printf "\a" ?
>> for your convenience:
>> cat > /bin/beep <<hmz
>> #!/bin/sh
>> /usr/bin/printf "\a"
>> hmz
>> chmod +x /bin/beep
>> >
>
>'beep' can play any given frequency. We have a "happy" sound that plays
>after a successful boot. And you can have a "sad" melody when things
>fails.
>
>Usage:
>beep [-f freq] [-l length] [-r reps] [-d delay] [-D delay] [-s] [-c]
>beep [Options...] [-n] [--new] [Options...] ...
>beep [-h] [--help]
>beep [-v] [-V] [--version]
I tested attached with the input-script you gave me, does it sound
vaguely similar? If not, can you send me an .au as a sample how it
should sound?
cheers,
Bernhard
PS: There is certainly room for improvement, size- and functionality
wise:
$ size miscutils/beep.o
text data bss dec hex filename
568 0 0 568 238 miscutils/beep.o
>From fb9ab3547192a7983df52e6e18e9e7908f9ba782 Mon Sep 17 00:00:00 2001
From: Bernhard Reutner-Fischer <[email protected]>
Date: Tue, 18 Aug 2009 22:28:09 +0200
Subject: [PATCH] add simple beep applet
Signed-off-by: Bernhard Reutner-Fischer <[email protected]>
---
include/applets.h | 1 +
include/usage.h | 9 ++++++
miscutils/Config.in | 6 ++++
miscutils/Kbuild | 1 +
miscutils/beep.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 87 insertions(+), 0 deletions(-)
create mode 100644 miscutils/beep.c
diff --git a/include/applets.h b/include/applets.h
index cb1ed56..d1cdb0f 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -80,6 +80,7 @@ IF_ASH(APPLET(ash, _BB_DIR_BIN, _BB_SUID_DROP))
IF_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_DROP, awk))
IF_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_DROP, basename))
IF_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_DROP))
+IF_BEEP(APPLET(beep, _BB_DIR_USR_BIN, _BB_SUID_DROP))
//IF_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_DROP))
IF_BLKID(APPLET(blkid, _BB_DIR_SBIN, _BB_SUID_DROP))
IF_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
diff --git a/include/usage.h b/include/usage.h
index accda33..1ba5b4a 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -148,6 +148,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 6890447..7209d29 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 e378a09..d88cb39 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..4c25454
--- /dev/null
+++ b/miscutils/beep.c
@@ -0,0 +1,70 @@
+/* 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)
+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();
+ llist_t *_freq = NULL, *_length = NULL, *_delay = NULL, *_rep = NULL;
+ unsigned freq, length, delay, rep;
+ unsigned long ioctl_arg;
+ unsigned opt;
+
+ opt_complementary = "f::l::d::r::";
+ opt = getopt32(argv, "f:l:d:r:n", &_freq, &_length, &_delay, &_rep);
+
+ do {
+ if (opt & OPT_f && _freq)
+ freq = xatoul((char*)(llist_pop(&_freq)));
+ else
+ freq = FREQ;
+ if (opt & OPT_l && _length)
+ length = xatoul((char*)(llist_pop(&_length)));
+ else
+ length = LENGTH;
+ if (opt & OPT_d && _delay)
+ delay = xatoul((char*)(llist_pop(&_delay)));
+ else
+ delay = DELAY;
+ if (opt & OPT_r && _rep)
+ rep = xatoul((char*)(llist_pop(&_rep)));
+ else
+ rep = REPETITIONS;
+
+ while (rep) {
+//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d\n", 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);
+ }
+ } while (_freq || _length || _delay || _rep);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(speaker);
+ return EXIT_SUCCESS;
+}
--
1.6.3.3
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox