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:
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;
}