Would you use this?
Yes
 33%  [ 1 ]
I do not have a chatpad, otherwise yes
 66%  [ 2 ]
Total Votes : 3

The goal of this project is to make a better driver for the xBox 360's gamepad. The main reason I want to do this is to have chatpad support in Android, Linux, Windows, etc.

I am using libUSB at the moment, but I hope to move to the native usb support on the supported platforms. (ie kernel driver in linux)

I will of course make this open source.

At the moment I am attempting to have libUSB hotplug support but it does not seem to be working.


Code:

#include <signal.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <libusb-1.0/libusb.h>
#include <pthread.h>

/**
 * 045E:028E
 * Class:      0xFF
 * Subclass:   0x5D
 */

#define VID 0x045E
#define PID 0x028E

libusb_context               *libusb         = 0;
libusb_hotplug_callback_handle   callbackHandle      = 0;

void exitDriver(){
   if(callbackHandle != 0){
      libusb_hotplug_deregister_callback(
         libusb,
         callbackHandle
      );
   }
   
   if(libusb != 0){
      libusb_exit(libusb);
   }
   
   exit(0);
}

void sigHandle(int sig){
   printf("Caught signal %d\n", sig);
   exitDriver();
}

int hotplug(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *user_data){
   printf("Blarg\n");
   return 0;
}

int main() {
   struct sigaction sigIntHandler;
   
   sigIntHandler.sa_handler = sigHandle;
   sigemptyset(&sigIntHandler.sa_mask);
   sigIntHandler.sa_flags = 0;
   
   sigaction(SIGINT, &sigIntHandler, 0);
   
   printf("Starting driver...\n");
   
   int rc;
   
   rc = libusb_init(&libusb);
   if(rc != 0){
      printf("%d\n", rc);
      exitDriver();
   }
   
   rc = libusb_hotplug_register_callback(
      libusb,
      LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
      LIBUSB_HOTPLUG_ENUMERATE,
      VID,
      PID,
      LIBUSB_HOTPLUG_MATCH_ANY,
      hotplug,
      NULL,
      &callbackHandle
   );
   
   if(rc != 0){
      printf("%d\n", rc);
      exitDriver();
   }
   
   for(;;){
      usleep(500);
   }
   
   return 0;
}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement