beep: optimize
function old new delta beep_main 394 276 -118 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -567,6 +567,9 @@ CONFIG_FEATURE_MOUNT_LOOP=y
|
|||||||
#
|
#
|
||||||
CONFIG_ADJTIMEX=y
|
CONFIG_ADJTIMEX=y
|
||||||
CONFIG_BBCONFIG=y
|
CONFIG_BBCONFIG=y
|
||||||
|
CONFIG_BEEP=y
|
||||||
|
CONFIG_FEATURE_BEEP_FREQ=4000
|
||||||
|
CONFIG_FEATURE_BEEP_LENGTH_MS=30
|
||||||
CONFIG_CHAT=y
|
CONFIG_CHAT=y
|
||||||
CONFIG_FEATURE_CHAT_NOFAIL=y
|
CONFIG_FEATURE_CHAT_NOFAIL=y
|
||||||
CONFIG_FEATURE_CHAT_TTY_HIFI=y
|
CONFIG_FEATURE_CHAT_TTY_HIFI=y
|
||||||
|
@@ -33,7 +33,7 @@ config FEATURE_BEEP_FREQ
|
|||||||
help
|
help
|
||||||
Frequency for default beep.
|
Frequency for default beep.
|
||||||
|
|
||||||
config FEATURE_BEEP_LENGTH
|
config FEATURE_BEEP_LENGTH_MS
|
||||||
int "default length"
|
int "default length"
|
||||||
range 0 2147483647
|
range 0 2147483647
|
||||||
default 30
|
default 30
|
||||||
|
122
miscutils/beep.c
122
miscutils/beep.c
@@ -11,92 +11,80 @@
|
|||||||
|
|
||||||
#include <linux/kd.h>
|
#include <linux/kd.h>
|
||||||
#ifndef CLOCK_TICK_RATE
|
#ifndef CLOCK_TICK_RATE
|
||||||
#define CLOCK_TICK_RATE 1193180
|
# define CLOCK_TICK_RATE 1193180
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OPT_f (1<<0)
|
|
||||||
#define OPT_l (1<<1)
|
|
||||||
#define OPT_d (1<<2)
|
|
||||||
#define OPT_r (1<<3)
|
|
||||||
/* defaults */
|
/* defaults */
|
||||||
#ifndef CONFIG_FEATURE_BEEP_FREQ
|
#ifndef CONFIG_FEATURE_BEEP_FREQ
|
||||||
# define FREQ (4000)
|
# define FREQ (4000)
|
||||||
#else
|
#else
|
||||||
# define FREQ (CONFIG_FEATURE_BEEP_FREQ)
|
# define FREQ (CONFIG_FEATURE_BEEP_FREQ)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_FEATURE_BEEP_LENGTH
|
#ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
|
||||||
# define LENGTH (30)
|
# define LENGTH (30)
|
||||||
#else
|
#else
|
||||||
# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH)
|
# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
|
||||||
#endif
|
#endif
|
||||||
#define DELAY (0)
|
#define DELAY (0)
|
||||||
#define REPETITIONS (1)
|
#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, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int beep_main(int argc UNUSED_PARAM, char **argv)
|
int beep_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int speaker = get_console_fd_or_die();
|
int speaker = get_console_fd_or_die();
|
||||||
unsigned freq, length, delay, rep;
|
unsigned length, delay, rep;
|
||||||
unsigned long ioctl_arg;
|
unsigned tickrate_div_freq;
|
||||||
char *opt = NULL;
|
int c;
|
||||||
bool do_parse = true;
|
|
||||||
|
|
||||||
NEW_BEEP()
|
c = 'n';
|
||||||
while (*argv && *++argv) {
|
while (c != -1) {
|
||||||
opt = *argv;
|
if (c == 'n') {
|
||||||
|
tickrate_div_freq = CLOCK_TICK_RATE / FREQ;
|
||||||
while (*opt == '-')
|
length = LENGTH;
|
||||||
++opt;
|
delay = DELAY;
|
||||||
if (do_parse)
|
rep = REPETITIONS;
|
||||||
switch (*opt) {
|
}
|
||||||
case 'f':
|
c = getopt(argc, argv, "f:l:d:r:n");
|
||||||
GET_ARG;
|
/* TODO: -s, -c:
|
||||||
freq = xatoul(opt);
|
* pipe stdin to stdout, but also beep after each line (-s) or char (-c)
|
||||||
continue;
|
*/
|
||||||
case 'l':
|
switch (c) {
|
||||||
GET_ARG;
|
case 'f':
|
||||||
length = xatoul(opt);
|
/* TODO: what "-f 0" should do? */
|
||||||
continue;
|
tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg);
|
||||||
case 'd':
|
continue;
|
||||||
GET_ARG;
|
case 'l':
|
||||||
delay = xatoul(opt);
|
length = xatou(optarg);
|
||||||
continue;
|
continue;
|
||||||
case 'r':
|
case 'd':
|
||||||
GET_ARG;
|
/* TODO:
|
||||||
rep = xatoul(opt);
|
* -d N, -D N
|
||||||
continue;
|
* specify a delay of N milliseconds between repetitions.
|
||||||
case 'n':
|
* -d specifies that this delay should only occur between beeps,
|
||||||
break;
|
* that is, it should not occur after the last repetition.
|
||||||
default:
|
* -D indicates that the delay should occur after every repetition
|
||||||
bb_show_usage();
|
*/
|
||||||
break;
|
delay = xatou(optarg);
|
||||||
}
|
continue;
|
||||||
again:
|
case 'r':
|
||||||
|
rep = xatou(optarg);
|
||||||
|
continue;
|
||||||
|
case 'n':
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bb_show_usage();
|
||||||
|
}
|
||||||
while (rep) {
|
while (rep) {
|
||||||
//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
|
//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*)(long)tickrate_div_freq);
|
||||||
xioctl(speaker, KIOCSOUND, (void*)ioctl_arg);
|
|
||||||
usleep(1000 * length);
|
usleep(1000 * length);
|
||||||
ioctl(speaker, KIOCSOUND, 0);
|
ioctl(speaker, KIOCSOUND, (void*)0);
|
||||||
if (rep--)
|
if (--rep)
|
||||||
usleep(delay);
|
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)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
close(speaker);
|
close(speaker);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@@ -117,11 +105,11 @@ g=$((392*3))
|
|||||||
-n -f$g -l200 -r2 \
|
-n -f$g -l200 -r2 \
|
||||||
-n -f$f -l200 \
|
-n -f$f -l200 \
|
||||||
-n -f$e -l200 \
|
-n -f$e -l200 \
|
||||||
-n -f$d -l200 \
|
-n -f$d -l200 \
|
||||||
-n -f$c -l200 -r2 \
|
-n -f$c -l200 -r2 \
|
||||||
-n -f$d -l200 \
|
-n -f$d -l200 \
|
||||||
-n -f$e -l200 \
|
-n -f$e -l200 \
|
||||||
-n -f$e -l400 \
|
-n -f$e -l400 \
|
||||||
-n -f$d -l100 \
|
-n -f$d -l100 \
|
||||||
-n -f$d -l200 \
|
-n -f$d -l200 \
|
||||||
*/
|
*/
|
||||||
|
@@ -569,7 +569,7 @@ CONFIG_ADJTIMEX=y
|
|||||||
# CONFIG_BBCONFIG is not set
|
# CONFIG_BBCONFIG is not set
|
||||||
CONFIG_BEEP=y
|
CONFIG_BEEP=y
|
||||||
CONFIG_FEATURE_BEEP_FREQ=4000
|
CONFIG_FEATURE_BEEP_FREQ=4000
|
||||||
CONFIG_FEATURE_BEEP_LENGTH=30
|
CONFIG_FEATURE_BEEP_LENGTH_MS=30
|
||||||
CONFIG_CHAT=y
|
CONFIG_CHAT=y
|
||||||
CONFIG_FEATURE_CHAT_NOFAIL=y
|
CONFIG_FEATURE_CHAT_NOFAIL=y
|
||||||
# CONFIG_FEATURE_CHAT_TTY_HIFI is not set
|
# CONFIG_FEATURE_CHAT_TTY_HIFI is not set
|
||||||
|
Reference in New Issue
Block a user