2009-08-21 11:18:31 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* beep implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Bernhard Reutner-Fischer
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2009-08-21 11:18:31 +00:00
|
|
|
*
|
|
|
|
*/
|
2011-04-11 01:29:49 +00:00
|
|
|
|
|
|
|
//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 01:58:28 +00:00
|
|
|
//usage: " -f Frequency in Hz"
|
2011-04-11 01:29:49 +00:00
|
|
|
//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 11:18:31 +00:00
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
#include <linux/kd.h>
|
|
|
|
#ifndef CLOCK_TICK_RATE
|
2009-08-22 16:00:39 +00:00
|
|
|
# define CLOCK_TICK_RATE 1193180
|
2009-08-21 11:18:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* defaults */
|
2009-08-21 12:40:29 +00:00
|
|
|
#ifndef CONFIG_FEATURE_BEEP_FREQ
|
|
|
|
# define FREQ (4000)
|
|
|
|
#else
|
|
|
|
# define FREQ (CONFIG_FEATURE_BEEP_FREQ)
|
|
|
|
#endif
|
2009-08-22 16:00:39 +00:00
|
|
|
#ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
|
2009-08-21 12:40:29 +00:00
|
|
|
# define LENGTH (30)
|
|
|
|
#else
|
2009-08-22 16:00:39 +00:00
|
|
|
# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
|
2009-08-21 12:40:29 +00:00
|
|
|
#endif
|
2009-08-21 11:18:31 +00:00
|
|
|
#define DELAY (0)
|
|
|
|
#define REPETITIONS (1)
|
|
|
|
|
|
|
|
int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2009-08-22 16:00:39 +00:00
|
|
|
int beep_main(int argc, char **argv)
|
2009-08-21 11:18:31 +00:00
|
|
|
{
|
|
|
|
int speaker = get_console_fd_or_die();
|
2009-12-12 01:42:35 +00:00
|
|
|
unsigned tickrate_div_freq = tickrate_div_freq; /* for compiler */
|
|
|
|
unsigned length = length;
|
|
|
|
unsigned delay = delay;
|
|
|
|
unsigned rep = rep;
|
2009-08-22 16:00:39 +00:00
|
|
|
int c;
|
2009-08-21 11:18:31 +00:00
|
|
|
|
2009-08-22 16:00:39 +00:00
|
|
|
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 11:18:31 +00:00
|
|
|
while (rep) {
|
|
|
|
//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
|
2010-03-14 14:32:49 +00:00
|
|
|
xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
|
2009-08-21 11:18:31 +00:00
|
|
|
usleep(1000 * length);
|
2009-08-22 16:00:39 +00:00
|
|
|
ioctl(speaker, KIOCSOUND, (void*)0);
|
|
|
|
if (--rep)
|
2010-03-14 14:32:49 +00:00
|
|
|
usleep(1000 * delay);
|
2009-08-21 11:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-22 16:00:39 +00:00
|
|
|
|
2009-08-21 11:18:31 +00:00
|
|
|
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 16:00:39 +00:00
|
|
|
-n -f$d -l200 \
|
|
|
|
-n -f$c -l200 -r2 \
|
|
|
|
-n -f$d -l200 \
|
|
|
|
-n -f$e -l200 \
|
|
|
|
-n -f$e -l400 \
|
2009-08-21 11:18:31 +00:00
|
|
|
-n -f$d -l100 \
|
|
|
|
-n -f$d -l200 \
|
|
|
|
*/
|