Skip to content

Commit

Permalink
Debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Apr 28, 2024
1 parent 1a829e5 commit 3f39b1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions ch340.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,20 @@ int CH340::init_usb(int vendor, int product) {
for (ssize_t i = 0; i < num_devices; i++) {
libusb_device_descriptor desc;
if (libusb_get_device_descriptor(dev_list[i], &desc) == 0) {
std::cout << "Product ID: " << desc.idProduct << std::endl;
std::cout << "Vendor: " << desc.idVendor << std::endl;
std::cout << "Manufacturer: " << desc.iManufacturer << std::endl;
std::cout << "serial Num: " << desc.iSerialNumber << std::endl;
std::cout << "Product: " << desc.iProduct << std::endl;
if (DEBUG) {
std::cout << "Product ID: " << desc.idProduct << std::endl;
std::cout << "Vendor: " << desc.idVendor << std::endl;
std::cout << "Manufacturer: " << desc.iManufacturer << std::endl;
std::cout << "serial Num: " << desc.iSerialNumber << std::endl;
std::cout << "Product: " << desc.iProduct << std::endl;
}
if (desc.idVendor == vendor && desc.idProduct == product) {
std::cout << "Device found" << std::endl;
dev_handle = libusb_open_device_with_vid_pid(ctx, desc.idVendor, desc.idProduct);
if (dev_handle) {
std::cout << "Device opened" << std::endl;
libusb_config_descriptor *config;
libusb_get_active_config_descriptor(dev_list[i], &config);

int interfaceNum = config->interface[0].altsetting[0].bInterfaceNumber;
std::cout << "Interface number: " << interfaceNum << std::endl;

if (libusb_kernel_driver_active(dev_handle, interfaceNum)) {
err = libusb_detach_kernel_driver(dev_handle, interfaceNum);
Expand Down
1 change: 1 addition & 0 deletions ch340.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>

#define BAUDRATE 115200
#define DEBUG 0

#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
Expand Down

0 comments on commit 3f39b1e

Please sign in to comment.