2009-08-21 16:48:31 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* beep implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Bernhard Reutner-Fischer
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2009-08-21 16:48:31 +05:30
|
|
|
*/
|
2016-11-23 03:44:24 +05:30
|
|
|
//config:config BEEP
|
2017-07-19 18:02:54 +05:30
|
|
|
//config: bool "beep (3 kb)"
|
2016-11-23 03:44:24 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: The beep applets beeps in a given freq/Hz.
|
2016-11-23 03:44:24 +05:30
|
|
|
//config:
|
|
|
|
//config:config FEATURE_BEEP_FREQ
|
|
|
|
//config: int "default frequency"
|
2017-07-08 15:51:45 +05:30
|
|
|
//config: range 20 50000 # allowing 0 here breaks the build
|
2016-11-23 03:44:24 +05:30
|
|
|
//config: default 4000
|
|
|
|
//config: depends on BEEP
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Frequency for default beep.
|
2016-11-23 03:44:24 +05:30
|
|
|
//config:
|
|
|
|
//config:config FEATURE_BEEP_LENGTH_MS
|
|
|
|
//config: int "default length"
|
|
|
|
//config: range 0 2147483647
|
|
|
|
//config: default 30
|
|
|
|
//config: depends on BEEP
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Length in ms for default beep.
|
2011-04-11 06:59:49 +05:30
|
|
|
|
2016-11-23 04:24:17 +05:30
|
|
|
//applet:IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_BEEP) += beep.o
|
|
|
|
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage:#define beep_trivial_usage
|
|
|
|
//usage: "-f FREQ -l LEN -d DELAY -r COUNT -n"
|
|
|
|
//usage:#define beep_full_usage "\n\n"
|
2011-06-05 07:28:28 +05:30
|
|
|
//usage: " -f Frequency in Hz"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage: "\n -l Length in ms"
|
|
|
|
//usage: "\n -d Delay in ms"
|
|
|
|
//usage: "\n -r Repetitions"
|
|
|
|
//usage: "\n -n Start new tone"
|
|
|
|
|
2009-08-21 16:48:31 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
#include <linux/kd.h>
|
|
|
|
#ifndef CLOCK_TICK_RATE
|
2009-08-22 21:30:39 +05:30
|
|
|
# define CLOCK_TICK_RATE 1193180
|
2009-08-21 16:48:31 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/* defaults */
|
2009-08-21 18:10:29 +05:30
|
|
|
#ifndef CONFIG_FEATURE_BEEP_FREQ
|
|
|
|
# define FREQ (4000)
|
|
|
|
#else
|
|
|
|
# define FREQ (CONFIG_FEATURE_BEEP_FREQ)
|
|
|
|
#endif
|
2009-08-22 21:30:39 +05:30
|
|
|
#ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
|
2009-08-21 18:10:29 +05:30
|
|
|
# define LENGTH (30)
|
|
|
|
#else
|
2009-08-22 21:30:39 +05:30
|
|
|
# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
|
2009-08-21 18:10:29 +05:30
|
|
|
#endif
|
2009-08-21 16:48:31 +05:30
|
|
|
#define DELAY (0)
|
|
|
|
#define REPETITIONS (1)
|
|
|
|
|
|
|
|
int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2009-08-22 21:30:39 +05:30
|
|
|
int beep_main(int argc, char **argv)
|
2009-08-21 16:48:31 +05:30
|
|
|
{
|
|
|
|
int speaker = get_console_fd_or_die();
|
2009-12-12 07:12:35 +05:30
|
|
|
unsigned tickrate_div_freq = tickrate_div_freq; /* for compiler */
|
|
|
|
unsigned length = length;
|
|
|
|
unsigned delay = delay;
|
|
|
|
unsigned rep = rep;
|
2009-08-22 21:30:39 +05:30
|
|
|
int c;
|
2009-08-21 16:48:31 +05:30
|
|
|
|
2009-08-22 21:30:39 +05:30
|
|
|
c = 'n';
|
|
|
|
while (c != -1) {
|
|
|
|
if (c == 'n') {
|
|
|
|
tickrate_div_freq = CLOCK_TICK_RATE / FREQ;
|
|
|
|
length = LENGTH;
|
|
|
|
delay = DELAY;
|
|
|
|
rep = REPETITIONS;
|
|
|
|
}
|
|
|
|
c = getopt(argc, argv, "f:l:d:r:n");
|
|
|
|
/* TODO: -s, -c:
|
|
|
|
* pipe stdin to stdout, but also beep after each line (-s) or char (-c)
|
|
|
|
*/
|
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
/* TODO: what "-f 0" should do? */
|
|
|
|
tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg);
|
|
|
|
continue;
|
|
|
|
case 'l':
|
|
|
|
length = xatou(optarg);
|
|
|
|
continue;
|
|
|
|
case 'd':
|
|
|
|
/* TODO:
|
|
|
|
* -d N, -D N
|
|
|
|
* specify a delay of N milliseconds between repetitions.
|
|
|
|
* -d specifies that this delay should only occur between beeps,
|
|
|
|
* that is, it should not occur after the last repetition.
|
|
|
|
* -D indicates that the delay should occur after every repetition
|
|
|
|
*/
|
|
|
|
delay = xatou(optarg);
|
|
|
|
continue;
|
|
|
|
case 'r':
|
|
|
|
rep = xatou(optarg);
|
|
|
|
continue;
|
|
|
|
case 'n':
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bb_show_usage();
|
|
|
|
}
|
2009-08-21 16:48:31 +05:30
|
|
|
while (rep) {
|
2016-03-30 19:34:37 +05:30
|
|
|
//bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
|
2010-03-14 20:02:49 +05:30
|
|
|
xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
|
2009-08-21 16:48:31 +05:30
|
|
|
usleep(1000 * length);
|
2009-08-22 21:30:39 +05:30
|
|
|
ioctl(speaker, KIOCSOUND, (void*)0);
|
|
|
|
if (--rep)
|
2010-03-14 20:02:49 +05:30
|
|
|
usleep(1000 * delay);
|
2009-08-21 16:48:31 +05:30
|
|
|
}
|
|
|
|
}
|
2009-08-22 21:30:39 +05:30
|
|
|
|
2009-08-21 16:48:31 +05:30
|
|
|
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 \
|
2009-08-22 21:30:39 +05:30
|
|
|
-n -f$d -l200 \
|
|
|
|
-n -f$c -l200 -r2 \
|
|
|
|
-n -f$d -l200 \
|
|
|
|
-n -f$e -l200 \
|
|
|
|
-n -f$e -l400 \
|
2009-08-21 16:48:31 +05:30
|
|
|
-n -f$d -l100 \
|
|
|
|
-n -f$d -l200 \
|
|
|
|
*/
|