1 /*-
2 * pccard noise interface.
3 * Nate Williams, October 1997.
4 * This file is in the public domain.
5 */
6 /* $FreeBSD: releng/5.1/sys/pccard/pccard_beep.c 104164 2002-09-29 23:41:25Z imp $ */
7
8 #include <sys/param.h>
9 #include <sys/kernel.h>
10 #include <sys/systm.h>
11
12 #include <machine/clock.h>
13
14 #include <pccard/driver.h>
15
16 static enum beepstate allow_beep = BEEP_OFF;
17 static int melody_type = 0;
18
19 #define MAX_TONE_MODE 3
20 #define MAX_STATE 4
21
22 struct tone {
23 int pitch;
24 int duration;
25 };
26
27 static struct tone silent_beep[] = {
28 {0, 0}
29 };
30
31 static struct tone success_beep[] = {
32 {1200, 40}, {0, 0}
33 };
34 static struct tone failure_beep[] = {
35 {3200, 40}, {0, 0}
36 };
37 static struct tone insert_remove_beep[] = {
38 {1600, 20}, {0, 0}
39 };
40
41 static struct tone success_melody_beep[] = {
42 {1200, 7}, {1000, 7}, { 800, 15}, {0, 0}
43 };
44 static struct tone failure_melody_beep[] = {
45 {2000, 7}, {2400, 7}, {2800, 15}, {0, 0}
46 };
47 static struct tone insert_melody_beep[] = {
48 {1600, 10}, {1200, 5}, {0, 0}
49 };
50 static struct tone remove_melody_beep[] = {
51 {1200, 10}, {1600, 5}, {0, 0}
52 };
53
54 static struct tone *melody_table[MAX_TONE_MODE][MAX_STATE] = {
55 { /* silent mode */
56 silent_beep, silent_beep, silent_beep, silent_beep,
57 },
58 { /* simple beep mode */
59 success_beep, failure_beep,
60 insert_remove_beep, insert_remove_beep,
61 },
62 { /* melody beep mode */
63 success_melody_beep, failure_melody_beep,
64 insert_melody_beep, remove_melody_beep,
65 },
66 };
67
68
69 static void
70 pccard_beep_sub(void *arg)
71 {
72 struct tone *melody;
73 melody = (struct tone *)arg;
74
75 if (melody->pitch != 0) {
76 sysbeep(melody->pitch, (melody->duration * hz + 99) / 100);
77 timeout(pccard_beep_sub, melody + 1,
78 (melody->duration * hz + 99) / 100);
79 } else
80 allow_beep = BEEP_ON;
81 }
82
83 static void
84 pccard_beep_start(void *arg)
85 {
86 struct tone *melody;
87 melody = (struct tone *)arg;
88
89 if (allow_beep == BEEP_ON && melody->pitch != 0) {
90 allow_beep = BEEP_OFF;
91 sysbeep(melody->pitch, (melody->duration * hz + 99) / 100);
92 timeout(pccard_beep_sub, melody + 1,
93 (melody->duration * hz + 99) / 100);
94 }
95 }
96
97 void
98 pccard_success_beep(void)
99 {
100 pccard_beep_start(melody_table[melody_type][0]);
101 }
102
103 void
104 pccard_failure_beep(void)
105 {
106 pccard_beep_start(melody_table[melody_type][1]);
107 }
108
109 void
110 pccard_insert_beep(void)
111 {
112 pccard_beep_start(melody_table[melody_type][2]);
113 }
114
115 void
116 pccard_remove_beep(void)
117 {
118 pccard_beep_start(melody_table[melody_type][3]);
119 }
120
121 int
122 pccard_beep_select(int type)
123 {
124 int errcode = 0;
125
126 if (type == 0) {
127 allow_beep = BEEP_OFF;
128 melody_type = 0;
129 } else if (type < 0 || MAX_TONE_MODE - 1 < type) {
130 errcode = 1;
131 } else {
132 allow_beep = BEEP_ON;
133 melody_type = type;
134 }
135 return (errcode);
136 }
Cache object: 57865909bf9c6ad80c5e3990bf002ce7
|