/* Ring -- Rings the internal speaker on x86 Linux * Copyright (C) 2003 Nick Thompson * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include // brrrr, brrrr int ring1[][2]={ { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 200, 0 }, { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 40, 770 }, { 40, 880 }, { 0, 0 } }; // derdler, derdler int ring2[][2]={ { 100, 990 }, { 100, 880 }, { 100, 770 }, { 200, 0 }, { 100, 990 }, { 100, 880 }, { 100, 770 }, { 0, 0 } }; int ring3[][2]={ { 20, 299 }, { 20, 250 }, { 20, 300 }, { 20, 350 }, { 20, 400 }, { 20, 450 }, { 20, 500 }, { 20, 550 }, { 20, 600 }, { 20, 650 }, { 20, 700 }, { 20, 750 }, { 20, 800 }, { 20, 850 }, { 20, 900 }, { 20, 950 }, { 20, 1000 }, { 0, 0 } }; char *console="/dev/console"; // ring tone player void ring(int fd, int ring[][2]) { int i=0; int duration; do { duration = ring[i][0]; ioctl(fd, KDMKTONE, (duration<<16) | ring[i][1]); usleep(duration*1000); i++; } while(duration); } // main control code int main(int argc, char **argv) { int fd; // check user really has access if (access(console, R_OK|W_OK)) { // no they don't printf("%s: %s\n", argv[0], strerror(errno)); return errno; } // dont want to hold up caller so fork out of here if (fork() == 0) { // Child opens up console... fd = open (console, O_RDWR); // ...and if successful... if (fd >= 0) { // ...makes a ring tone if (argc < 2 || argv[1][0] == '1') { ring(fd, ring1); } else if (argv[1][0] == '2') { ring(fd, ring2); } else if (argv[1][0] == '3') { ring(fd, ring3); } // close console when done close (fd); } } return 0; }