Files
ptouch-prnt/src/libusbwrap/interface/IUsbDevice.hpp
Moritz Martinius ad0b2c91ae
All checks were successful
Build ptprnt / build (push) Successful in 1m1s
Add a printer factory to simplify construction of printer drivers (#11)
Co-authored-by: Moritz Martinius <mm@cloudprinters.de>
Reviewed-on: #11
2024-04-20 11:10:30 +00:00

48 lines
1.3 KiB
C++

#pragma once
#include <sys/types.h>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#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 ~IUsbDevice() = default;
virtual bool open() = 0;
virtual void close() = 0;
// libusb wrappers
virtual bool detachKernelDriver(int interfaceNo) = 0;
virtual bool claimInterface(int interfaceNo) = 0;
virtual bool releaseInterface(int interfaceNo) = 0;
virtual bool bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
unsigned int timeout) = 0;
// getters
virtual const usbId getUsbId() = 0;
virtual const device::Speed getSpeed() = 0;
virtual const uint8_t getBusNumber() = 0;
virtual const uint8_t getPortNumber() = 0;
// errors
virtual const Error getLastError() = 0;
virtual const std::string getLastErrorString() = 0;
};
} // namespace libusbwrap