#pragma once #include #include #include #include #include #include namespace Usb { /** * The UsbInterface provides access to a particular USB interface. */ class UsbInterface { public: std::uint8_t interfaceNumber = 0; UsbInterface( std::uint8_t interfaceNumber, ::libusb_device_handle* deviceHandle ); ~UsbInterface(); UsbInterface(const UsbInterface& other) = delete; UsbInterface& operator = (const UsbInterface& other) = delete; UsbInterface(UsbInterface&& other) = default; UsbInterface& operator = (UsbInterface&& other) = default; /** * Attempts to claim the interface */ void init(); /** * Releases the claimed interface */ void close(); std::vector readBulk( std::uint8_t endpointAddress, std::optional timeout = std::nullopt ); void writeBulk( std::uint8_t endpointAddress, std::span buffer, std::uint16_t maxPacketSize ); private: ::libusb_device_handle* deviceHandle; bool claimed = false; }; }