static int x10codes( char *data ) { static int nCode, nPrevCode = 0; static int fd = 0; static struct timeval tv1={0,0}, tv2; if( (data[0] >= 0x44) && (data[0]<=0x47) && (data[2]==0x3f) ) { /* X10 Mouse Remote *may* be activated! */ /* printf("%02X %02X %02X %02X \n", data[0], data[1], data[2], data[3] ); */ /* Assign the action code and the current time */ nCode = ((int)data[0])*256+data[1]; GET_TIME(tv2); /* If the code is the same as the last one, for some codes do not allow immediate repetition */ if( (nCode!=X10_VOLUP) && (nCode!=X10_VOLDOWN) && (nCode==nPrevCode) && (DIF_TIME(tv1,tv2)<opt_time) ); else { /* Open the pipe to write. Since the reader is creating it, this will fail if the reader is not ready to accept codes */ if(!fd) fd = open("/dev/x10", O_WRONLY ); if( fd > 0 ) { /* Great! Pipe is there and we can write to it */ write(fd, &nCode, sizeof(int) ); } } tv1 = tv2; nPrevCode = nCode; /* Return non-zero to avoid further processing */ return( 1 ); } return( 0 ); }