Modules-old/xbox/lua_xbox360.cpp
/* Thread function for listening to the controller */
Thread function for listening to the controller
Thread function for listening to the controller
void *xbox360_thread_func(void *) {
	int bytes_transferred;
	int result = 0;
	int i = 0;
 	unsigned char data_in[20]; 
  while (!stopRequest) {
    result = libusb_interrupt_transfer(
        devh,
        INTERRUPT_IN_ENDPOINT,
        data_in,
        MAX_INTERRUPT_OUT_TRANSFER_SIZE,
        &bytes_transferred,
        0); 
    if (result >= 0 && bytes_transferred > 0) {
      for(i=0;i<nbutton;i++) {
  	uint8_t mybyte = i / 8 + 2;
	uint8_t myoffset = i % 8;
	buttons[i] = (data_in[mybyte]>>myoffset)&0x01 ? 1 : 0;
      }
      axes[0] = data_in[4];
      axes[1] = data_in[5];
      axes[2] = data_in[9];
      axes[3] = data_in[7];
      axes[4] = data_in[13];
      axes[5] = data_in[11];
    }
  }
  xbox360_thread_cleanup();
  running = 0;
	return NULL;
}
void * xbox360_thread_func ( void * ) { int bytes_transferred ; int result = 0 ; int i = 0 ; unsigned char data_in [ 20 ] ; while ( ! stopRequest ) { result = libusb_interrupt_transfer ( devh , INTERRUPT_IN_ENDPOINT , data_in , MAX_INTERRUPT_OUT_TRANSFER_SIZE , & bytes_transferred , 0 ) ; if ( result >= 0 && bytes_transferred > 0 ) { for ( i = 0 ; i < nbutton ; i ++ ) { uint8_t mybyte = i / 8 + 2 ; uint8_t myoffset = i % 8 ; buttons [ i ] = ( data_in [ mybyte ] >> myoffset ) & 0x01 ? 1 : 0 ; } axes [ 0 ] = data_in [ 4 ] ; axes [ 1 ] = data_in [ 5 ] ; axes [ 2 ] = data_in [ 9 ] ; axes [ 3 ] = data_in [ 7 ] ; axes [ 4 ] = data_in [ 13 ] ; axes [ 5 ] = data_in [ 11 ] ; } } xbox360_thread_cleanup ( ) ; running = 0 ; return NULL ; }
Thread function for listening to the controller
Thread function for listening to the controller
// Reports are 20 bytes for 360 /*
     sigset_t sigs;
     sigfillset(&sigs);
     pthread_sigmask(SIG_BLOCK, &sigs, NULL);
     */ // Read data from the device. // Timeout of 0 waits forever... //SJ: they are not all uint8's /*
      for(i=0;i<naxis;i++) {
	axes[i] = data_in[i+4];
      }
*/