2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
|
|
|
|
|
|
#include "src/DebugToolDrivers/DebugTool.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Bloom::Usb
|
|
|
|
|
{
|
|
|
|
|
class UsbDevice
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-10-06 21:12:31 +01:00
|
|
|
UsbDevice(std::uint16_t vendorId, std::uint16_t productId): vendorId(vendorId), productId(productId) {};
|
2021-04-04 21:04:12 +01:00
|
|
|
~UsbDevice() = default;
|
|
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
void init();
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
[[nodiscard]] libusb_device* getLibUsbDevice() const {
|
|
|
|
|
return this->libUsbDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setLibUsbDevice(libusb_device* libUsbDevice) {
|
|
|
|
|
this->libUsbDevice = libUsbDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
[[nodiscard]] std::uint16_t getVendorId() const {
|
2021-04-04 21:04:12 +01:00
|
|
|
return this->vendorId;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
[[nodiscard]] std::uint16_t getProductId() const {
|
2021-04-04 21:04:12 +01:00
|
|
|
return this->productId;
|
|
|
|
|
}
|
2021-04-07 23:30:01 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects a specific configuration on the device, using the configuration index.
|
|
|
|
|
*
|
|
|
|
|
* @param configIndex
|
|
|
|
|
*/
|
|
|
|
|
virtual void setConfiguration(int configIndex);
|
2021-10-06 21:12:31 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
libusb_context* libUsbContext = nullptr;
|
|
|
|
|
libusb_device* libUsbDevice = nullptr;
|
|
|
|
|
libusb_device_handle* libUsbDeviceHandle = nullptr;
|
|
|
|
|
std::uint16_t vendorId;
|
|
|
|
|
std::uint16_t productId;
|
|
|
|
|
|
|
|
|
|
std::vector<libusb_device*> findMatchingDevices(
|
|
|
|
|
std::optional<std::uint16_t> vendorId = std::nullopt, std::optional<std::uint16_t> productId = std::nullopt
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void close();
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|