Changes and cleanups for the timer API.

The device lists use the next device syntax now.
This commit is contained in:
Jaroslav Kysela 2000-11-30 19:17:55 +00:00
parent 61e95094e7
commit 35cb79860d
12 changed files with 204 additions and 78 deletions

View file

@ -50,29 +50,35 @@ void read_loop(void *handle, int master_ticks, int timeout)
int main(int argc, char *argv[])
{
int idx, err;
int timer = SND_TIMER_GLOBAL(SND_TIMER_GLOBAL_SYSTEM);
int slave = 0;
int slave_type = SND_TIMER_STYPE_SEQUENCER, slave_id = 0;
int type = SND_TIMER_TYPE_GLOBAL;
int stype = SND_TIMER_TYPE_NONE;
int card = 0;
int device = SND_TIMER_GLOBAL_SYSTEM;
int subdevice = 0;
int list = 0;
snd_timer_t *handle;
snd_timer_general_info_t ginfo;
snd_timer_select_t sel;
snd_timer_info_t info;
snd_timer_params_t params;
idx = 1;
while (idx < argc) {
if (!strncmp(argv[idx], "timer=", 6)) {
timer = atoi(argv[idx]+6);
} else if (!strcmp(argv[idx], "slave")) {
slave = 1;
} else if (!strncmp(argv[idx], "slave_type=", 11)) {
slave_type = atoi(argv[idx]+11);
} else if (!strncmp(argv[idx], "slave_id=", 9)) {
slave_id = atoi(argv[idx]+9);
if (!strncmp(argv[idx], "type=", 5)) {
type = atoi(argv[idx]+5);
} else if (!strncmp(argv[idx], "stype=", 6)) {
stype = atoi(argv[idx]+6);
} else if (!strncmp(argv[idx], "card=", 5)) {
card = atoi(argv[idx]+5);
} else if (!strncmp(argv[idx], "device=", 7)) {
device = atoi(argv[idx]+7);
} else if (!strncmp(argv[idx], "subdevice=", 10)) {
subdevice = atoi(argv[idx]+10);
} else if (!strcmp(argv[idx], "list")) {
list = 1;
}
idx++;
}
if (slave && slave_type == SND_TIMER_STYPE_NONE) {
if (type == SND_TIMER_TYPE_SLAVE && stype == SND_TIMER_STYPE_NONE) {
fprintf(stderr, "sync_type is not set\n");
exit(0);
}
@ -80,30 +86,37 @@ int main(int argc, char *argv[])
fprintf(stderr, "timer open %i (%s)\n", err, snd_strerror(err));
exit(0);
}
if (snd_timer_general_info(handle, &ginfo)<0) {
fprintf(stderr, "timer general info %i (%s)\n", err, snd_strerror(err));
exit(0);
if (list) {
bzero(&sel.id, sizeof(sel.id));
sel.id.type = -1;
while (1) {
if ((err = snd_timer_next_device(handle, &sel.id)) < 0) {
fprintf(stderr, "timer next device error: %s\n", snd_strerror(err));
break;
}
if (sel.id.type < 0)
break;
printf("Timer device: type %i, stype %i, card %i, device %i, subdevice %i\n",
sel.id.type, sel.id.stype, sel.id.card, sel.id.device, sel.id.subdevice);
}
}
printf("Global timers = %i\n", ginfo.count);
printf("Using timer %i, slave %i, slave_type %i, slave_id %i\n", timer, slave, slave_type, slave_id);
printf("Using timer type %i, slave type %i, card %i, device %i, subdevice %i\n", type, stype, card, device, subdevice);
bzero(&sel, sizeof(sel));
sel.slave = slave;
if (!sel.slave) {
sel.data.number = timer;
} else {
sel.data.slave.type = slave_type;
sel.data.slave.id = slave_id;
}
sel.id.type = type;
sel.id.stype = stype;
sel.id.card = card;
sel.id.device = device;
sel.id.subdevice = subdevice;
if ((err = snd_timer_select(handle, &sel)) < 0) {
fprintf(stderr, "timer select %i (%s)\n", err, snd_strerror(err));
exit(0);
}
if (!sel.slave) {
if (type != SND_TIMER_TYPE_SLAVE) {
if ((err = snd_timer_info(handle, &info)) < 0) {
fprintf(stderr, "timer info %i (%s)\n", err, snd_strerror(err));
exit(0);
}
printf("Timer %i info:\n", sel.data.number);
printf("Timer info:\n");
printf(" flags = 0x%x\n", info.flags);
printf(" id = '%s'\n", info.id);
printf(" name = '%s'\n", info.name);
@ -125,7 +138,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "timer start %i (%s)\n", err, snd_strerror(err));
exit(0);
}
read_loop(handle, 25, sel.slave ? 10000 : 1);
read_loop(handle, 25, type == SND_TIMER_TYPE_SLAVE ? 10000 : 1);
show_status(handle);
snd_timer_close(handle);
return 0;