Add USB stub, add logging using spdlog
This commit is contained in:
5
.vscode/c_cpp_properties.json
vendored
5
.vscode/c_cpp_properties.json
vendored
@@ -5,7 +5,10 @@
|
||||
"compilerPath": "/usr/bin/clang",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"compileCommands": "/builddir/compile_commands.json"
|
||||
"compileCommands": "${workspaceFolder}/builddir/compile_commands.json",
|
||||
"browse": {
|
||||
"path": ["${workspaceFolder}"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -78,6 +78,10 @@
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"valarray": "cpp",
|
||||
"variant": "cpp"
|
||||
"variant": "cpp",
|
||||
"csignal": "cpp",
|
||||
"any": "cpp",
|
||||
"regex": "cpp",
|
||||
"future": "cpp"
|
||||
}
|
||||
}
|
16
inc/IUsb.hpp
Normal file
16
inc/IUsb.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "UsbTypes.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class IUsb {
|
||||
public:
|
||||
virtual ~IUsb(){};
|
||||
|
||||
virtual std::vector<UsbDevice> listDevices() = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
20
inc/Usb.hpp
Normal file
20
inc/Usb.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "IUsb.hpp"
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class Usb : public IUsb {
|
||||
public:
|
||||
Usb();
|
||||
~Usb() override;
|
||||
|
||||
std::vector<UsbDevice> listDevices() override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
13
inc/UsbTypes.hpp
Normal file
13
inc/UsbTypes.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
struct UsbDevice {
|
||||
libusb_device* dev{nullptr};
|
||||
libusb_device_handle* hndl{nullptr};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -1,10 +1,11 @@
|
||||
project('ptprnt', 'cpp',
|
||||
version: '0.1.0',
|
||||
version: 'v0.1.0-'+run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip(),
|
||||
license: 'GPLv3',
|
||||
default_options : ['c_std=c11', 'cpp_std=c++17']
|
||||
)
|
||||
|
||||
usbdep = dependency('libusb-1.0')
|
||||
logdep = dependency('spdlog')
|
||||
|
||||
incdir = include_directories('inc')
|
||||
|
||||
@@ -16,7 +17,9 @@ srcs = [
|
||||
]
|
||||
|
||||
executable(
|
||||
'ptprnt', srcs,
|
||||
'ptprnt',
|
||||
srcs,
|
||||
include_directories : incdir,
|
||||
dependencies : usbdep
|
||||
dependencies : [usbdep, logdep],
|
||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"']
|
||||
)
|
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();
|
||||
@@ -25,3 +27,4 @@ int main(int argc, char** argv) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user