/* Howto compile: gcc -o voht voht.c * To use: * gpm -t ps2 -m /dev/psaux -M -t ps2 -m /dev/voht -R msc * repeats on /dev/gpmdata input from both ps2 port and this program * and set XF86Config: protocol type to "MouseSystems" and * set XF86Config: device to /dev/gpmdata */ #include #include #include #include #include #include #include #include /* usually the parameters fall in this range when estpchirp2m worked */ #define LOWER_THRESHOLD -1.5 #define UPPER_THRESHOLD 1.5 void usage() { fprintf(stderr,"Use: Reads 8 projective chirp parameters from stdin\n" " and moves the mouse accordingly by writing ps2\n" " protocol data on /dev/voht. Parameters are\n" " relative to last frame\n"); } void calc_motion( double *x, double *y, float *params, double *delta_x, double *delta_y); void motion_to_ps2( double delta_x, double delta_y, unsigned char *ps2_out); //static void ser_read (int fd, unsigned char *bytes, int count); int main( int argc, char *argv[] ) { int fifo; int voht_pin_fifo; unsigned char ps2_output_bytes[3]; int i=0; int exit_flag = 0; double x, y, delta_x, delta_y; /* x and y as orbits coords!!*/ fd_set rfds; float pchirp_parameters[8]; x=0.5, y=0,5; if( argc == 2 ) { usage(); exit(1); } /* open serial port for writing, here */ /* open the fifo for reading */ //voht_pin_fifo = open("/dev/voht_pin", O_RDONLY | O_SYNC); /* RDWR seems to keep it from looping too much */ voht_pin_fifo = open("/dev/pwm0", O_RDWR | O_SYNC); if( voht_pin_fifo == -1 ) { perror("open");exit(1); } FD_ZERO(&rfds); FD_SET(voht_pin_fifo, &rfds); while(1) { char buffer[1024]; for( i=0; i<8 ; i++) { int j=0; /* scan and verify input parameters */ while( select( voht_pin_fifo+1, &rfds, NULL, NULL, NULL)==1) { int numread; numread = read( voht_pin_fifo, &(buffer[j++]), 1); //printf("got %d:%c\n", numread, buffer[j-1]); if( buffer[j-1] == '\n' ) { j=0; i=0; continue; } if( !isalnum(buffer[j-1] ) && buffer[j-1] != '.' && buffer[j-1] != '-' ) break; } //if(scanf("%f", &(pchirp_parameters[i]))==0) continue; sscanf(buffer, "%f", &(pchirp_parameters[i])); printf("%f read\n", pchirp_parameters[i]); if( isnan(pchirp_parameters[i]) ) exit_flag = 1; if( pchirp_parameters[i] > UPPER_THRESHOLD || pchirp_parameters[i] < LOWER_THRESHOLD ) { exit_flag = 1; fprintf(stderr, "Crazy big parameters read, ignoring!!\n"); } } // if( exit_flag == 1) exit(1); if( exit_flag == 1) continue; else { fprintf(stderr, "Using: "); for( i=0; i<8; i++ ) fprintf(stderr, "%g ", pchirp_parameters[i]); fprintf(stderr,"\n"); } printf("sending chars!\n"); fflush(stdout); // write(fifo, ps2_output_bytes, 3); // insert ssc_move function call here } } /* example code on how to read from a FIFO serial: static void ser_read (int fd, unsigned char *bytes, int count) { struct timeval tv; fd_set rfds; int num_read = 0; int read_count; FD_ZERO (&rfds); FD_SET (fd, &rfds); tv.tv_sec = 1; tv.tv_usec = 0; while ((select (fd+1, &rfds, NULL, NULL, &tv) == 1) && (num_read < count)) { read_count = read (fd, &bytes [num_read], count - num_read); num_read += read_count; FD_ZERO (&rfds); FD_SET (fd, &rfds); } for (; num_read < count; num_read++) { bytes [num_read] = '\0'; } } */