-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeep.diff
140 lines (132 loc) · 4.87 KB
/
beep.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--- /home/silasbrown/Downloads/beep(1).c 2021-04-02 09:46:29.695286944 +0100
+++ beep.c 2021-04-02 09:14:11.486246016 +0100
@@ -1,3 +1,5 @@
+/* Modified by ssb22 for NSLU2 / Debian 5 */
+
/* beep - just what it sounds like, makes the console beep - but with
* precision control. See the man page for details.
*
@@ -13,7 +15,8 @@
* warranties of merchantability or fitness for a particular use or ability to
* breed pandas in captivity, it just can't be done.
*
- * Bug me, I like it: http://johnath.com/ or [email protected]
+ * Original author's contact: http://johnath.com/ or [email protected]
+ * but note that this version was modified for NSLU2 / Debian 5
*/
#include <fcntl.h>
@@ -44,7 +47,11 @@
result of this is a tone at approximately the desired frequency. :)
*/
#ifndef CLOCK_TICK_RATE
-#define CLOCK_TICK_RATE 1193180
+//#define CLOCK_TICK_RATE 1193180
+#define CLOCK_TICK_RATE 64000000 // nslu2
+/* (SSB: do the NSLU2 alteration HERE, not
+ * by opening an event device, because that
+ * introduces extra delays in Debian 5) */
#endif
#define VERSION_STRING "beep-1.2.2"
@@ -110,7 +117,7 @@
/* print usage and exit */
void usage_bail(const char *executable_name) {
printf("Usage:\n%s [-f freq] [-l length] [-r reps] [-d delay] "
- "[-D delay] [-s] [-c]\n",
+ "[-D delay] [-s] [-c] [-e device (ignored)]\n",
executable_name);
printf("%s [Options...] [-n] [--new] [Options...] ... \n", executable_name);
printf("%s [-h] [--help]\n", executable_name);
@@ -145,7 +152,7 @@
{"version", 0, NULL, 'V'},
{"new", 0, NULL, 'n'},
{0,0,0,0}};
- while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVn", opt_list, NULL))
+ while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVne:", opt_list, NULL))
!= EOF) {
int argval = -1; /* handle parsed numbers for various arguments */
float argfreq = -1;
@@ -197,8 +204,10 @@
exit(0);
break;
case 'n' : /* also --new - create another beep */
+ if (result->freq == 0)
+ result->freq = DEFAULT_FREQ;
result->next = (beep_parms_t *)malloc(sizeof(beep_parms_t));
- result->next->freq = DEFAULT_FREQ;
+ result->next->freq = 0;
result->next->length = DEFAULT_LENGTH;
result->next->reps = DEFAULT_REPS;
result->next->delay = DEFAULT_DELAY;
@@ -207,26 +216,20 @@
result->next->next = NULL;
result = result->next; /* yes, I meant to do that. */
break;
+ case 'e' : /* also --device */
+ break;
case 'h' : /* notice that this is also --help */
default :
usage_bail(argv[0]);
}
}
+ if (result->freq == 0)
+ result->freq = DEFAULT_FREQ;
}
void play_beep(beep_parms_t parms) {
int i; /* loop counter */
- /* try to snag the console */
- if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
- if((console_fd = open("/dev/vc/0", O_WRONLY)) == -1) {
- fprintf(stderr, "Could not open /dev/tty0 or /dev/vc/0 for writing.\n");
- printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
- perror("open");
- exit(1);
- }
- }
-
/* Beep */
for (i = 0; i < parms.reps; i++) { /* start beep */
if(ioctl(console_fd, KIOCSOUND, (int)(CLOCK_TICK_RATE/parms.freq)) < 0) {
@@ -236,20 +239,16 @@
/* Look ma, I'm not ansi C compatible! */
usleep(1000*parms.length); /* wait... */
ioctl(console_fd, KIOCSOUND, 0); /* stop beep */
- if(parms.end_delay || (i+1 < parms.reps))
+ if((parms.end_delay || (i+1 < parms.reps)) && /*parms.delay*/ 1)
usleep(1000*parms.delay); /* wait... */
} /* repeat. */
-
- close(console_fd);
}
-
-
int main(int argc, char **argv) {
char sin[4096], *ptr;
beep_parms_t *parms = (beep_parms_t *)malloc(sizeof(beep_parms_t));
- parms->freq = DEFAULT_FREQ;
+ parms->freq = 0;
parms->length = DEFAULT_LENGTH;
parms->reps = DEFAULT_REPS;
parms->delay = DEFAULT_DELAY;
@@ -260,6 +259,17 @@
signal(SIGINT, handle_signal);
parse_command_line(argc, argv, parms);
+
+ /* try to snag the console */
+ /* (SSB: do this at TOP level, NOT on every beep
+ * which may increase the probability of NSLU2 crash) */
+ if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
+ fprintf(stderr, "Could not open console device for writing.\n");
+ printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
+ perror("open");
+ exit(1);
+ }
+
/* this outermost while loop handles the possibility that -n/--new has been
used, i.e. that we have multiple beeps specified. Each iteration will
play, then free() one parms instance. */
@@ -297,5 +307,6 @@
parms = next;
}
+ close(console_fd);
return EXIT_SUCCESS;
}