Added Usb Detection using libUsb

This commit is contained in:
2022-11-12 18:29:04 +01:00
parent 2770a2a2cc
commit a706a0d822
8 changed files with 171 additions and 106 deletions

View File

@@ -1,6 +1,7 @@
#include "UsbTypes.hpp"
#include <vector>
#include <optional>
#pragma once
@@ -8,9 +9,9 @@ namespace ptprnt::driver {
class IUsb {
public:
virtual ~IUsb(){};
virtual ~IUsb() = default;
virtual std::vector<UsbDevice> listDevices() = 0;
virtual std::optional<std::vector<UsbDevice>> getDevices() = 0;
};
} // namespace ptprnt::driver

View File

@@ -1,20 +1,29 @@
#include "IDriver.hpp"
#include <cstdint>
#include <memory>
#include "Usb.hpp"
#pragma once
namespace ptprnt::driver {
class P700Driver : public IDriver {
public:
P700Driver(uint16_t UsbDevVendor = 0x04f9, uint16_t UsbDevId = 0x2061);
public:
P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor = 0x04f9, uint16_t usbDevId = 0x2061);
~P700Driver() override;
driver::info getInfo() override;
bool open() override;
bool close() override;
bool command() override;
private:
std::shared_ptr<Usb> mUsbDriver{0};
UsbDevice mUsbDev{0};
bool init();
};
} // namespace ptprnt::driver

View File

@@ -1,4 +1,5 @@
#include "IUsb.hpp"
#include "UsbTypes.hpp"
#include <libusb-1.0/libusb.h>
@@ -8,13 +9,13 @@ namespace ptprnt::driver {
class Usb : public IUsb {
public:
Usb();
~Usb() override;
Usb();
~Usb() override;
std::vector<UsbDevice> listDevices() override;
std::optional<std::vector<UsbDevice>> getDevices() override;
private:
std::vector<UsbDevice> mDevices{};
};
} // namespace ptprnt::driver

View File

@@ -6,6 +6,8 @@
namespace ptprnt::driver {
struct UsbDevice {
uint16_t vendorId{0};
uint16_t productId{0};
libusb_device* dev{nullptr};
libusb_device_handle* hndl{nullptr};
};