/* 07.08.1999 by Thomas Koch Einfache (externe) lautstaerkereglung... This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1.9.1999: code ueberarbeitet 8.9.1999: nochmals komplett ueberarbeitet. ein und ausfaden moeglich. */ #include #include #include #include #include #include #include #include #define MAXVOL 25700 // maximale lautstaerke #define MINVOL 0 // minimale lautstaerke #define MIXER "/dev/mixer" // mixerdevice #define SERDEV "/dev/ttyS0" // serialdevice // globale variablen int mixerfd, serialfd; // wert lesen int readvalue() { int flags; // daten von device holen ioctl(mixerfd, MIXER_READ(0), &flags); return(flags); } // wert schreiben int writevalue(int flags) { // wert schreiben ioctl(mixerfd, MIXER_WRITE(0), &flags); return(0); } // laut/leise int volume(int volume) { int status; status = readvalue(); if(volume) { if(status < MAXVOL) { status = readvalue(); status += 514; writevalue(status); } } else { if(status > MINVOL) { status = readvalue(); status -= 514; writevalue(status); } } return(0); } int main(int argc, char *argv[]) { int flags, i, status, oldstatus; // mixerdevice oeffnen (/dev/mixer z.b.) if((mixerfd = open(MIXER, O_RDWR | O_NDELAY)) < 0) { printf("mixer konnte nicht geoeffnet werden\n"); exit(1); } // serialdevice oeffnen if((serialfd = open(SERDEV, O_RDWR | O_NDELAY)) < 0) { printf("serial device konnte nicht geoeffnet werden\n"); exit(1); } // into loop... while(1) { ioctl(serialfd, TIOCMGET, &flags); if(flags & TIOCM_CTS) { // leiser volume(0); } if(flags & TIOCM_DSR) { // lauter volume(1); } if(flags & TIOCM_CAR) { // ausfaden oldstatus = readvalue(); // derzeitige lautstaerke besorgen (zum wiederherstellen for(i = 0; i < 50; i++) { // beim wiedereinfaden) volume(0); usleep(10000); } } if(flags & TIOCM_RNG) { // einfaden for(i = 0; i < 50; i++) { status = readvalue(); if(status < MAXVOL) { status = readvalue(); if(status < oldstatus) { // alte lautstaerke wieder herstellen status += 514; writevalue(status); usleep(10000); } } } } usleep(100000); } // end while(1) // devices schliesen close(mixerfd); close(serialfd); return(0); // schrecklich, alles muss immer irgendwas zurueckgeben }