Add USB stub, add logging using spdlog
This commit is contained in:
37
src/Usb.cpp
Normal file
37
src/Usb.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
Usb::Usb() {
|
||||
std::cout << "Usb starting" << std::endl;
|
||||
libusb_init(NULL);
|
||||
}
|
||||
Usb::~Usb() {
|
||||
std::cout << "Usb stopping" << std::endl;
|
||||
}
|
||||
|
||||
std::vector<UsbDevice> Usb::listDevices() {
|
||||
libusb_device ** devs;
|
||||
libusb_device *dev;
|
||||
struct libusb_device_descriptor desc;
|
||||
int r,i=0;
|
||||
|
||||
libusb_get_device_list(NULL, &devs);
|
||||
|
||||
while ((dev=devs[i++]) != NULL) {
|
||||
if ((r=libusb_get_device_descriptor(dev, &desc)) < 0) {
|
||||
std::cerr << "failed to open device" << std::endl;
|
||||
libusb_free_device_list(devs, 1);
|
||||
}
|
||||
|
||||
std::cout << std::hex << std::setw(4) << desc.idVendor << ":" << desc.idProduct;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return std::vector<UsbDevice>();
|
||||
}
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -6,11 +6,13 @@
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace ptprnt;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
std::cout << "Hello ptprnt!" << std::endl;
|
||||
spdlog::info("Starting ptprnt {}", PROJ_VERSION);
|
||||
|
||||
auto usb = std::make_unique<driver::Usb>();
|
||||
auto devs = usb->listDevices();
|
||||
@@ -24,4 +26,5 @@ int main(int argc, char** argv) {
|
||||
printer::info info = printer->getInfo();*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user