101 lines
2.6 KiB
C
101 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
#include "config.h"
|
|
|
|
static struct libusb_device_handle *devh = NULL;
|
|
|
|
static libusb_device_handle *open_actionpro()
|
|
{
|
|
ssize_t devc;
|
|
libusb_device **dev_list;
|
|
static libusb_device *dev = NULL;
|
|
struct libusb_device_descriptor dev_desc;
|
|
struct libusb_config_descriptor *dev_conf = NULL;
|
|
const struct libusb_interface *iface = NULL;
|
|
const struct libusb_interface_descriptor *iface_desc = NULL;
|
|
|
|
int res = 0;
|
|
|
|
devc = libusb_get_device_list(NULL, &dev_list);
|
|
if (devc < 1) {
|
|
return NULL;
|
|
}
|
|
|
|
for (int i = 0; i < devc; i++) {
|
|
dev = dev_list[i];
|
|
if (libusb_get_device_descriptor(dev, &dev_desc)) {
|
|
continue;
|
|
}
|
|
|
|
if ((dev_desc.idVendor != VENDOR_ID || dev_desc.idProduct != PRODUCT_ID)) {
|
|
continue;
|
|
}
|
|
|
|
res = libusb_open(dev, &devh);
|
|
if (res < 0) {
|
|
perror("libusb_open");
|
|
return(NULL);
|
|
}
|
|
|
|
for (int j = 0; j < dev_desc.bNumConfigurations; j++) {
|
|
if (libusb_get_config_descriptor(dev, j, &dev_conf)) {
|
|
continue;
|
|
}
|
|
|
|
for (int k = 0; k < dev_conf->bNumInterfaces; k++) {
|
|
iface = &dev_conf->interface[k];
|
|
for (int l = 0; l < iface->num_altsetting; l++) {
|
|
iface_desc = &iface->altsetting[l];
|
|
if (libusb_kernel_driver_active(devh, iface_desc->bInterfaceNumber)) {
|
|
libusb_detach_kernel_driver(devh, iface_desc->bInterfaceNumber);
|
|
}
|
|
|
|
libusb_set_configuration(devh, dev_conf->bConfigurationValue);
|
|
libusb_claim_interface(devh, iface_desc->bInterfaceNumber);
|
|
|
|
int e = 0;
|
|
while (libusb_claim_interface(devh, iface_desc->bInterfaceNumber) && (e < 10)) {
|
|
sleep(1);
|
|
e++;
|
|
}
|
|
}
|
|
}
|
|
|
|
libusb_free_config_descriptor(dev_conf);
|
|
}
|
|
|
|
return devh;
|
|
}
|
|
|
|
devh = NULL;
|
|
return NULL;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int res = 0;
|
|
|
|
res = libusb_init(NULL);
|
|
if (res < 0) {
|
|
perror("libusb_init");
|
|
fprintf(stderr, "Error: %s\n", libusb_strerror(res));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if (!open_actionpro()) {
|
|
fprintf(stderr, "Error opening device, no ACTIONPRO X7 found!\n");
|
|
libusb_exit(NULL);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
libusb_exit(NULL);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
}
|