Refactored some of the USB device (libusb wrapper) & interface code
This commit is contained in:
@@ -10,46 +10,26 @@ namespace Bloom::Usb
|
||||
{
|
||||
class Interface
|
||||
{
|
||||
private:
|
||||
libusb_device* USBDevice = nullptr;
|
||||
protected:
|
||||
libusb_device* libUsbDevice = nullptr;
|
||||
libusb_device_handle* libUsbDeviceHandle = nullptr;
|
||||
|
||||
std::uint16_t vendorId = 0;
|
||||
std::uint16_t productId = 0;
|
||||
|
||||
/**
|
||||
* With libusb, we can only claim a single USB interface per device handle. For this reason,
|
||||
* device handles are stored against the interface. Each interface must obtain a new handle before
|
||||
* claiming.
|
||||
*/
|
||||
libusb_device_handle* libUsbDeviceHandle = nullptr;
|
||||
std::uint8_t number = 0;
|
||||
std::string name = "";
|
||||
|
||||
bool initialised = false;
|
||||
bool claimed = false;
|
||||
|
||||
void setInitialised(bool initialised) {
|
||||
this->initialised = initialised;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setClaimed(bool claimed) {
|
||||
this->claimed = claimed;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit Interface(const std::uint8_t& interfaceNumber = 0) {
|
||||
this->setNumber(interfaceNumber);
|
||||
}
|
||||
|
||||
libusb_device* getUSBDevice() const {
|
||||
return this->USBDevice;
|
||||
}
|
||||
|
||||
void setUSBDevice(libusb_device* USBDevice) {
|
||||
this->USBDevice = USBDevice;
|
||||
}
|
||||
|
||||
libusb_device_handle* getLibUsbDeviceHandle() const {
|
||||
return this->libUsbDeviceHandle;
|
||||
void setLibUsbDevice(libusb_device* libUsbDevice) {
|
||||
this->libUsbDevice = libUsbDevice;
|
||||
}
|
||||
|
||||
void setLibUsbDeviceHandle(libusb_device_handle* libUsbDeviceHandle) {
|
||||
@@ -101,8 +81,6 @@ namespace Bloom::Usb
|
||||
*/
|
||||
virtual void init();
|
||||
|
||||
virtual void setConfiguration(int configIndex);
|
||||
|
||||
/**
|
||||
* Releases the interface and closes the device descriptor.
|
||||
*/
|
||||
@@ -112,7 +90,15 @@ namespace Bloom::Usb
|
||||
* Attempts to claim the interface
|
||||
*/
|
||||
void claim();
|
||||
|
||||
/**
|
||||
* If a kernel driver is attached to the interface, this method will detach it.
|
||||
*/
|
||||
void detachKernelDriver();
|
||||
|
||||
/**
|
||||
* Releases the interface, if claimed.
|
||||
*/
|
||||
void release();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user