restore USB functionality with altered implementation
This commit is contained in:
22
inc/libusbwrap/LibUsbTypes.hpp
Normal file
22
inc/libusbwrap/LibUsbTypes.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
namespace libusbwrap {
|
||||
enum class Error {
|
||||
SUCCESS = LIBUSB_SUCCESS,
|
||||
IO = LIBUSB_ERROR_IO,
|
||||
INVALID_PARAM = LIBUSB_ERROR_INVALID_PARAM,
|
||||
ACCESS = LIBUSB_ERROR_ACCESS,
|
||||
NO_DEVICE = LIBUSB_ERROR_NO_DEVICE,
|
||||
NOT_FOUND = LIBUSB_ERROR_NOT_FOUND,
|
||||
BUSY = LIBUSB_ERROR_BUSY,
|
||||
TIMEOUT = LIBUSB_ERROR_TIMEOUT,
|
||||
OVERFLOW = LIBUSB_ERROR_OVERFLOW,
|
||||
PIPE = LIBUSB_ERROR_PIPE,
|
||||
INTERRUPTED = LIBUSB_ERROR_INTERRUPTED,
|
||||
NO_MEM = LIBUSB_ERROR_NO_MEM,
|
||||
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
||||
OTHER = LIBUSB_ERROR_OTHER
|
||||
};
|
||||
}
|
34
inc/libusbwrap/UsbDeviceFactory.hpp
Normal file
34
inc/libusbwrap/UsbDeviceFactory.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "libusbwrap/interface/IUsbDeviceFactory.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
public:
|
||||
UsbDeviceFactory();
|
||||
~UsbDeviceFactory();
|
||||
bool init();
|
||||
/**
|
||||
* @brief Gets all devices that are detected by libusb. Will allocate a shared_ptr for each Device
|
||||
*
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of all detected USB devices
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() override;
|
||||
/**
|
||||
* @brief Gets all devices with certain vid/pid combination.
|
||||
* If only one device of certain type is connected, vector is usually only one element
|
||||
*
|
||||
* @param vid VendorId of the devices to find
|
||||
* @param pid ProductId of the devices to find
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of detected USB devices based on vid/pid
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) override;
|
||||
|
||||
private:
|
||||
// methods
|
||||
int refreshDeviceList();
|
||||
// members
|
||||
libusb_context* mLibusbCtx{nullptr};
|
||||
libusb_device** mLibusbDeviceList;
|
||||
};
|
||||
} // namespace libusbwrap
|
34
inc/libusbwrap/interface/IUsbDevice.hpp
Normal file
34
inc/libusbwrap/interface/IUsbDevice.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "libusb.h"
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
namespace device {
|
||||
enum class Speed {
|
||||
UNKNOWN = LIBUSB_SPEED_UNKNOWN,
|
||||
LOW = LIBUSB_SPEED_LOW,
|
||||
FULL = LIBUSB_SPEED_FULL,
|
||||
HIGH = LIBUSB_SPEED_HIGH,
|
||||
SUPER = LIBUSB_SPEED_SUPER,
|
||||
SUPER_PLUS = LIBUSB_SPEED_SUPER_PLUS
|
||||
};
|
||||
} // namespace device
|
||||
|
||||
class IUsbDevice {
|
||||
public:
|
||||
virtual Error open() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
// getters
|
||||
virtual uint16_t getVid() = 0;
|
||||
virtual uint16_t getPid() = 0;
|
||||
virtual device::Speed getSpeed() = 0;
|
||||
virtual uint8_t getBusNumber() = 0;
|
||||
virtual uint8_t getPortNumber() = 0;
|
||||
};
|
||||
} // namespace libusbwrap
|
15
inc/libusbwrap/interface/IUsbDeviceFactory.hpp
Normal file
15
inc/libusbwrap/interface/IUsbDeviceFactory.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
class IUsbDeviceFactory {
|
||||
public:
|
||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
||||
};
|
||||
} // namespace libusbwrap
|
Reference in New Issue
Block a user