Exemplo n.º 1
0
int TankChassis::prepare_usb_device()
{
	if (libusb_init(0) < 0) {
		fprintf(stderr, "libusb_init\n");
		return -1;
	}

	if (find_lvr_hidusb(vendor_id, product_id) < 0) {
		fprintf(stderr, "find_lvr_hidusb\n");
		return -1;
	}

	libusb_detach_kernel_driver(devh, 0);

	if (libusb_set_configuration(devh, 1) < 0) {
		fprintf(stderr, "libusb_set_configuration\n");
		return -1;
	}

	if (libusb_claim_interface(devh, 0) < 0) {
		fprintf(stderr, "libusb_claim_interface\n");
		return -1;
	}

	return 0;
}
Exemplo n.º 2
0
int main(void)
{
	struct sigaction sigact;
	int r = 1;

	r = libusb_init(NULL);
	if (r < 0) {
		fprintf(stderr, "Failed to initialise libusb\n");
		exit(1);
	}

	r = find_lvr_hidusb();
	if (r < 0) {
		fprintf(stderr, "Could not find/open LVR Generic HID device\n");
		goto out;
	}
	printf("Successfully find the LVR Generic HID device\n");

#ifdef LINUX
 	libusb_detach_kernel_driver(devh, 0); 	
#endif

	r = libusb_set_configuration(devh, 1);
	if (r < 0) {
		fprintf(stderr, "libusb_set_configuration error %d\n", r);
		goto out;
	}
	printf("Successfully set usb configuration 1\n");
	r = libusb_claim_interface(devh, 0);
	if (r < 0) {
		fprintf(stderr, "libusb_claim_interface error %d\n", r);
		goto out;
	}
	printf("Successfully claimed interface\n");

//	test_control_transfer();
	test_interrupt_transfer();
	libusb_release_interface(devh, 0);
out:
//	libusb_reset_device(devh);
	libusb_close(devh);
	libusb_exit(NULL);
	return r >= 0 ? r : -r;
}
Exemplo n.º 3
0
TankChassis::TankChassis(int vendor, int product):
	vendor_id(vendor), product_id(product)
{
	ok = false;

	if (libusb_init(0) < 0)
		throw std::runtime_error("init");

	libusb_set_debug(0, 0);

	if (find_lvr_hidusb(vendor_id, product_id) < 0)
		throw std::runtime_error("Unable to openusb device!");

	libusb_detach_kernel_driver(devh, 0);

	if (libusb_set_configuration(devh, 1) < 0)
		throw std::runtime_error("libusb_set_configuration");

	if (libusb_claim_interface(devh, 0) < 0)
		throw std::runtime_error("libusb_claim_interface");

	ok = true;
}