Noolite::sendCommand was implemented

This commit is contained in:
2024-05-29 09:45:57 +02:00
parent 7055206fb1
commit 49b0e8d0cc
8 changed files with 83 additions and 50 deletions

View File

@@ -6,11 +6,13 @@
namespace noolitelib
{
constexpr auto DefaultTimeout = 1000;
LibUsbDevice::LibUsbDevice()
{
auto status = libusb_init(&m_context);
if (status) {
std::cout << "Error initializing context: " << libusb_strerror(status) << std::endl;
std::cerr << "Error initializing context: " << libusb_strerror(status) << std::endl;
}
}
@@ -33,10 +35,10 @@ void LibUsbDevice::close()
}
}
bool LibUsbDevice::sendDataToDevice(const Data &data, std::chrono::milliseconds timeout)
bool LibUsbDevice::sendDataToDevice(const Data &data)
{
if (!m_device) {
std::cout << "Device not opened" << std::endl;
std::cerr << "Device not opened" << std::endl;
}
auto requestType = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE;
@@ -45,10 +47,10 @@ bool LibUsbDevice::sendDataToDevice(const Data &data, std::chrono::milliseconds
unsigned char package[data.size()];
std::copy(data.begin(), data.end(), package);
auto status = libusb_control_transfer(m_device, requestType, request, 0, 0, package, data.size(), timeout.count());
auto status = libusb_control_transfer(m_device, requestType, request, 0, 0, package, data.size(), DefaultTimeout);
if (status) {
std::cout << "Sending data error: " << libusb_strerror(status) << std::endl;
std::cerr << "Sending data error: " << libusb_strerror(status) << std::endl;
return false;
}