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