sustain-pedal-hid-sw/sustain-kbd-config/libusbwrapper.h
2023-08-10 23:00:40 +02:00

48 lines
1.0 KiB
C++

#ifndef LIBUSBWRAPPER_H
#define LIBUSBWRAPPER_H
#include <stdint.h>
#include <vector>
#include <string>
#include <libusb.h>
#include <memory>
void LibUsbInit();
void LibUsbDeInit();
class UsbDeviceHandle {
public:
UsbDeviceHandle(libusb_device_handle *handle);
~UsbDeviceHandle();
libusb_device_handle *m_handle;
};
class UsbDevice {
public:
UsbDevice(libusb_device *device);
UsbDevice(const UsbDevice &d) = default;
UsbDevice(UsbDevice &&d);
~UsbDevice();
static std::vector<UsbDevice> find_devices(uint16_t vendor_id, uint16_t product_id);
bool opened();
int open();
uint16_t get_vendor_id();
uint16_t get_product_id();
int control_transfer(uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *data, uint16_t wLength, unsigned int timeout);
const std::string &get_serial_number();
private:
std::shared_ptr<UsbDeviceHandle> device_handle;
libusb_device *dev;
uint16_t vendor_id;
uint16_t product_id;
std::string serial;
struct libusb_device_descriptor devdesc;
};
#endif // LIBUSBWRAPPER_H