mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-11-24 12:19:49 +00:00
add simple beep applet
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
parent
e10db56aa3
commit
45de0746b3
@ -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))
|
||||
|
@ -145,6 +145,16 @@
|
||||
"$ basename /foo/bar.txt .txt\n" \
|
||||
"bar"
|
||||
|
||||
#define beep_trivial_usage \
|
||||
"-f freq -l length -d delay -r repetitions -n"
|
||||
#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" \
|
||||
"\n -n Start new tone" \
|
||||
|
||||
#define fbsplash_trivial_usage \
|
||||
"-s IMGFILE [-c] [-d DEV] [-i INIFILE] [-f CMD]"
|
||||
#define fbsplash_full_usage "\n\n" \
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
119
miscutils/beep.c
Normal file
119
miscutils/beep.c
Normal file
@ -0,0 +1,119 @@
|
||||
/* 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)
|
||||
|
||||
#define GET_ARG do { if (!*++opt) opt = *++argv; if (opt == NULL) bb_show_usage();} 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;
|
||||
char *opt = NULL;
|
||||
bool do_parse = true;
|
||||
|
||||
NEW_BEEP()
|
||||
while (*argv && *++argv) {
|
||||
opt = *argv;
|
||||
|
||||
while (*opt == '-')
|
||||
++opt;
|
||||
if (do_parse)
|
||||
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;
|
||||
rep = xatoul(opt);
|
||||
continue;
|
||||
case 'n':
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
break;
|
||||
}
|
||||
again:
|
||||
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 (!do_parse && *argv == NULL)
|
||||
goto out;
|
||||
}
|
||||
do_parse = false;
|
||||
goto again;
|
||||
out:
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
close(speaker);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
/*
|
||||
* so, e.g. Beethoven's 9th symphony "Ode an die Freude" would be
|
||||
* something like:
|
||||
a=$((220*3))
|
||||
b=$((247*3))
|
||||
c=$((262*3))
|
||||
d=$((294*3))
|
||||
e=$((329*3))
|
||||
f=$((349*3))
|
||||
g=$((392*3))
|
||||
#./beep -f$d -l200 -r2 -n -f$e -l100 -d 10 -n -f$c -l400 -f$g -l200
|
||||
./beep -f$e -l200 -r2 \
|
||||
-n -d 100 -f$f -l200 \
|
||||
-n -f$g -l200 -r2 \
|
||||
-n -f$f -l200 \
|
||||
-n -f$e -l200 \
|
||||
-n -f$d -l200 \
|
||||
-n -f$c -l200 -r2 \
|
||||
-n -f$d -l200 \
|
||||
-n -f$e -l200 \
|
||||
-n -f$e -l400 \
|
||||
-n -f$d -l100 \
|
||||
-n -f$d -l200 \
|
||||
*/
|
Loading…
Reference in New Issue
Block a user