greed Posted January 7, 2007 at 03:09 AM Report #74945 Posted January 7, 2007 at 03:09 AM #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/kd.h> #define MAXLINE 255 int main(int argc, char *argv[]) { int fd, arg, arg1, freq, time; char * pch; FILE * in; char data[MAXLINE]; fd = open("/dev/tty0", O_RDONLY); if(fd == NULL){ printf("Error opening /dev/tty0\n"); return 0; } if (argc == 2 && argv[1] != NULL){ in = fopen(argv[1],"r"); if (in != NULL) while (fgets(data,MAXLINE,in) != NULL){ pch = strtok (data," "); freq = atoi(pch); pch = strtok (NULL, " "); time = atoi(pch); arg = (time<<16)+(1193180/freq); ioctl(fd,KDMKTONE,arg); usleep(time * 1000); bzero(data, sizeof(data)); } else printf("Error opening file %s\n",argv[1]); } else printf("Wrong arguments!\n"); close(in); return 0; } Recebe de um ficheiro de texto (.txt) as frequências e o tempo de cada som. Por exemplo: 440 200 333 200 700 200 Primeiro as frequências e dps o tempo de cada uma delas. Agora podem brincar e se tiverem cão/gato em casa...podem-lhe atrufiar o juízo, check the following table: http://www.lsu.edu/deafness/HearingRange.html -- @pcbo
Triton Posted January 10, 2007 at 06:35 PM Report #75633 Posted January 10, 2007 at 06:35 PM Muito fixe o código. 🙂 O que faz a linha de código: arg = (time<<16)+(1193180/freq); <3 life
greed Posted January 10, 2007 at 08:31 PM Author Report #75644 Posted January 10, 2007 at 08:31 PM Muito fixe o código. 🙂 O que faz a linha de código: arg = (time<<16)+(1193180/freq); N faço ideia. Saquei esse pedaço de código aqui: http://www.developer.com/open/article.php/10930_631191_3 que por sua vez sacaram de um gajo kker chamado : Matan Ziv-Av que e' um programming guru, portanto se ele e' um programming guru quem sou eu para dizer q ta mal?? 😁 EDIT: The argument d (primeiro argumento) must be an open file descriptor. The second argument is a device-dependent request code. The third argument is an untyped pointer to memory. Com cada frequencia diferente posso ter um tom diferente, se o terceiro argumento aponta para a posicao da memoria, deve ser pq tem la **kker m****** com o som de cada tecla por exemplo. -- @pcbo
Hipnoted Posted January 10, 2007 at 09:04 PM Report #75645 Posted January 10, 2007 at 09:04 PM Muito fixe o código. 🙂 O que faz a linha de código: arg = (time<<16)+(1193180/freq); Segundo aquilo que sei, arg é uma variável que vai ser usada para definir se o socket é bloqueante ou não. Se for igual a 0 desactiva o socket bloqueante senão activa. Ou seja, toma o valor da soma de dezasseis bits à esquerda da variável time mais a divisão desse número. "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now