dont be so verbose

This commit is contained in:
Martin Brodbeck 2018-08-06 21:41:48 +02:00
parent bc35f95a06
commit 205e5eaae3

View file

@ -59,15 +59,16 @@ PosPrinter::PosPrinter()
} }
if (libusb_kernel_driver_active(devicePtr_, 0) == 1) { // find out if kernel driver is attached if (libusb_kernel_driver_active(devicePtr_, 0) == 1) { // find out if kernel driver is attached
std::cout << "Kernel driver active" << std::endl; if (libusb_detach_kernel_driver(devicePtr_, 0) != 0) { // detach it
if (libusb_detach_kernel_driver(devicePtr_, 0) == 0) // detach it libusb_free_device_list(devList, 1);
std::cout << "Kernel driver detached!" << std::endl; libusb_exit(contextPtr_);
throw std::runtime_error("Could not detach kernel printer driver");
}
} }
retValue = libusb_claim_interface( retValue = libusb_claim_interface(
devicePtr_, 0); // claim interface 0 (the first) of device (mine had jsut 1) devicePtr_, 0); // claim interface 0 (the first) of device (mine had jsut 1)
if (retValue < 0) { if (retValue < 0) {
std::cout << "Cannot claim printer interface" << std::endl;
throw std::runtime_error("Cannot claim printer interface"); throw std::runtime_error("Cannot claim printer interface");
} }
@ -80,9 +81,7 @@ PosPrinter::~PosPrinter()
int retValue; int retValue;
retValue = libusb_release_interface(devicePtr_, 0); // release the claimed interface retValue = libusb_release_interface(devicePtr_, 0); // release the claimed interface
if (retValue != 0) { if (retValue != 0) {
std::cout << "Cannot release printer interface" << std::endl; std::cerr << "Cannot release printer interface" << std::endl;
} else {
std::cout << "Printer interface released" << std::endl;
} }
libusb_close(devicePtr_); // close the device we opened libusb_close(devicePtr_); // close the device we opened