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 | |
| 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>
| -rw-r--r-- | include/applets.h | 1 | ||||
| -rw-r--r-- | include/usage.h | 10 | ||||
| -rw-r--r-- | miscutils/Config.in | 6 | ||||
| -rw-r--r-- | miscutils/Kbuild | 1 | ||||
| -rw-r--r-- | miscutils/beep.c | 119 |
5 files changed, 137 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h index d4fbbc95c..9b6b54e63 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -80,6 +80,7 @@ IF_ASH(APPLET(ash, _BB_DIR_BIN, _BB_SUID_DROP)) | |||
| 80 | IF_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_DROP, awk)) | 80 | IF_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_DROP, awk)) |
| 81 | IF_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_DROP, basename)) | 81 | IF_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_DROP, basename)) |
| 82 | IF_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_DROP)) | 82 | IF_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_DROP)) |
| 83 | IF_BEEP(APPLET(beep, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | ||
| 83 | //IF_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_DROP)) | 84 | //IF_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_DROP)) |
| 84 | IF_BLKID(APPLET(blkid, _BB_DIR_SBIN, _BB_SUID_DROP)) | 85 | IF_BLKID(APPLET(blkid, _BB_DIR_SBIN, _BB_SUID_DROP)) |
| 85 | IF_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) | 86 | IF_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) |
diff --git a/include/usage.h b/include/usage.h index 8a5c7a088..227ed8001 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -145,6 +145,16 @@ | |||
| 145 | "$ basename /foo/bar.txt .txt\n" \ | 145 | "$ basename /foo/bar.txt .txt\n" \ |
| 146 | "bar" | 146 | "bar" |
| 147 | 147 | ||
| 148 | #define beep_trivial_usage \ | ||
| 149 | "-f freq -l length -d delay -r repetitions -n" | ||
| 150 | #define beep_full_usage "\n\n" \ | ||
| 151 | "Options:\n" \ | ||
| 152 | "\n -f Frequency in Hz" \ | ||
| 153 | "\n -l Length in ms" \ | ||
| 154 | "\n -d Delay in ms" \ | ||
| 155 | "\n -r Repetitions" \ | ||
| 156 | "\n -n Start new tone" \ | ||
| 157 | |||
| 148 | #define fbsplash_trivial_usage \ | 158 | #define fbsplash_trivial_usage \ |
| 149 | "-s IMGFILE [-c] [-d DEV] [-i INIFILE] [-f CMD]" | 159 | "-s IMGFILE [-c] [-d DEV] [-i INIFILE] [-f CMD]" |
| 150 | #define fbsplash_full_usage "\n\n" \ | 160 | #define fbsplash_full_usage "\n\n" \ |
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 | */ | ||
