/*
speaker_off.c
*/
#include
#include /* open() */
#include /* O_RDONLY */
#include
#include "common.h" /* declarations for our command and status */
int speaker_off()
{
COMMAND_STRUCT command;
STATUS_STRUCT status;
int command_fd;
int status_fd;
int retval;
/*
Open the command and status FIFOs.
*/
if ((command_fd = open(RTF_COMMAND_DEV, O_WRONLY)) < 0) {
fprintf(stderr, "error opening %s\n", RTF_COMMAND_DEV);
return -1;
}
if ((status_fd = open(RTF_STATUS_DEV, O_RDONLY)) < 0) {
fprintf(stderr, "error opening %s\n", RTF_STATUS_DEV);
return -1;
}
/*
We set "off" speaker on at the last set frequency,
*/
retval = 0;
command.command = SOUND_OFF;
if (sizeof(command) != write(command_fd, &command, sizeof(command))) {
fprintf(stderr, "can't write command\n");
retval = -1;
}
/* now check for the reply */
if (sizeof(status) == read(status_fd, &status, sizeof(status))) {
if(status.command==SOUND_OFF)
printf("status: off freq:%d heartbeat:%d\n", status.freq, status.heartbeat);
else
printf("status: on freq:%d heartbeat:%d\n", status.freq, status.heartbeat);
}
close(status_fd);
close(command_fd);
return retval;
}