Re-structured project

This commit is contained in:
2023-08-26 11:53:44 +02:00
parent c3915336dd
commit 61e2352a3c
25 changed files with 257 additions and 257 deletions

View File

@@ -0,0 +1,52 @@
#include "libusbwrap/UsbDeviceFactory.hpp"
#include <spdlog/spdlog.h>
#include <memory>
#include "libusb.h"
#include "libusbwrap/UsbDevice.hpp"
#include "libusbwrap/interface/IUsbDevice.hpp"
namespace libusbwrap {
UsbDeviceFactory::UsbDeviceFactory() {}
UsbDeviceFactory::~UsbDeviceFactory() {
libusb_free_device_list(mLibusbDeviceList, 1);
}
std::vector<std::shared_ptr<IUsbDevice>> UsbDeviceFactory::findAllDevices() {
refreshDeviceList();
return std::vector<std::shared_ptr<IUsbDevice>>({std::make_shared<UsbDevice>()});
}
std::vector<std::shared_ptr<IUsbDevice>> UsbDeviceFactory::findDevices(uint16_t vid, uint16_t pid) {
refreshDeviceList();
return std::vector<std::shared_ptr<IUsbDevice>>({std::make_shared<UsbDevice>()});
}
int UsbDeviceFactory::refreshDeviceList() {
int ret = libusb_get_device_list(mLibusbCtx, &mLibusbDeviceList);
if (ret < 0) {
spdlog::error("Error enumarating USB devices");
} else if (ret == 0) {
spdlog::warn("No USB devices found");
} else {
spdlog::debug("Found {} USB devices", ret);
}
return ret;
}
bool UsbDeviceFactory::init() {
auto err = libusb_init(&mLibusbCtx);
if (err != (int)Error::SUCCESS) {
spdlog::error("Could not intialize libusb");
return false;
}
return true;
}
} // namespace libusbwrap