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
|
/*-
* pccard noise interface.
* Nate Williams, October 1997.
* This file is in the public domain.
*/
/* $FreeBSD$ */
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <machine/clock.h>
#include <pccard/driver.h>
static enum beepstate allow_beep = BEEP_OFF;
static int melody_type = 0;
#define MAX_TONE_MODE 3
#define MAX_STATE 4
struct tone {
int pitch;
int duration;
};
static struct tone silent_beep[] = {
{0, 0}
};
static struct tone success_beep[] = {
{1200, 40}, {0, 0}
};
static struct tone failure_beep[] = {
{3200, 40}, {0, 0}
};
static struct tone insert_remove_beep[] = {
{1600, 20}, {0, 0}
};
static struct tone success_melody_beep[] = {
{1200, 7}, {1000, 7}, { 800, 15}, {0, 0}
};
static struct tone failure_melody_beep[] = {
{2000, 7}, {2400, 7}, {2800, 15}, {0, 0}
};
static struct tone insert_melody_beep[] = {
{1600, 10}, {1200, 5}, {0, 0}
};
static struct tone remove_melody_beep[] = {
{1200, 10}, {1600, 5}, {0, 0}
};
static struct tone *melody_table[MAX_TONE_MODE][MAX_STATE] = {
{ /* silent mode */
silent_beep, silent_beep, silent_beep, silent_beep,
},
{ /* simple beep mode */
success_beep, failure_beep,
insert_remove_beep, insert_remove_beep,
},
{ /* melody beep mode */
success_melody_beep, failure_melody_beep,
insert_melody_beep, remove_melody_beep,
},
};
static void
pccard_beep_sub(void *arg)
{
struct tone *melody;
melody = (struct tone *)arg;
if (melody->pitch != 0) {
sysbeep(melody->pitch, melody->duration);
timeout(pccard_beep_sub, melody + 1, melody->duration);
} else
allow_beep = BEEP_ON;
}
static void
pccard_beep_start(void *arg)
{
struct tone *melody;
melody = (struct tone *)arg;
if (allow_beep == BEEP_ON && melody->pitch != 0) {
allow_beep = BEEP_OFF;
sysbeep(melody->pitch, melody->duration);
timeout(pccard_beep_sub, melody + 1, melody->duration);
}
}
void
pccard_success_beep(void)
{
pccard_beep_start(melody_table[melody_type][0]);
}
void
pccard_failure_beep(void)
{
pccard_beep_start(melody_table[melody_type][1]);
}
void
pccard_insert_beep(void)
{
pccard_beep_start(melody_table[melody_type][2]);
}
void
pccard_remove_beep(void)
{
pccard_beep_start(melody_table[melody_type][3]);
}
int
pccard_beep_select(int type)
{
int errcode = 0;
if (type == 0) {
allow_beep = BEEP_OFF;
melody_type = 0;
} else if (type < 0 || MAX_TONE_MODE - 1 < type) {
errcode = 1;
} else {
allow_beep = BEEP_ON;
melody_type = type;
}
return (errcode);
}
|