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