Compare commits
2 Commits
0462ba4d34
...
fix-logger
Author | SHA1 | Date | |
---|---|---|---|
3fd6671048
|
|||
a08f6167b3
|
@@ -14,7 +14,7 @@ jobs:
|
|||||||
- name: install meson
|
- name: install meson
|
||||||
run: apt-get -yq install meson
|
run: apt-get -yq install meson
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev gcovr
|
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev gcovr
|
||||||
- name: setup builddir
|
- name: setup builddir
|
||||||
run: meson setup builddir -Db_coverage=true
|
run: meson setup builddir -Db_coverage=true
|
||||||
- name: build all targets
|
- name: build all targets
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,7 +6,6 @@ subprojects/*
|
|||||||
coverageReport/
|
coverageReport/
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
ptprnt.log
|
|
||||||
!subprojects/*.wrap
|
!subprojects/*.wrap
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/c_cpp_properties.json
|
!.vscode/c_cpp_properties.json
|
||||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -85,6 +85,5 @@
|
|||||||
},
|
},
|
||||||
"clang-tidy.buildPath": "builddir/",
|
"clang-tidy.buildPath": "builddir/",
|
||||||
"clangd.onConfigChanged": "restart",
|
"clangd.onConfigChanged": "restart",
|
||||||
"C_Cpp.default.compileCommands": "builddir/compile_commands.json",
|
"C_Cpp.default.compileCommands": "builddir/compile_commands.json"
|
||||||
"mesonbuild.configureOnOpen": true
|
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ pacman -S libusb spdlog pango cairo meson gcovr
|
|||||||
|
|
||||||
Install dependencies on Debian/Ubuntu
|
Install dependencies on Debian/Ubuntu
|
||||||
``` bash
|
``` bash
|
||||||
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson gcovr
|
apt-get install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev meson gcovr
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
@@ -6,7 +6,6 @@ project('ptprnt', 'cpp',
|
|||||||
|
|
||||||
usb_dep = dependency('libusb-1.0')
|
usb_dep = dependency('libusb-1.0')
|
||||||
log_dep = dependency('spdlog')
|
log_dep = dependency('spdlog')
|
||||||
fmt_dep = dependency('fmt')
|
|
||||||
pangocairo_dep = dependency('pangocairo')
|
pangocairo_dep = dependency('pangocairo')
|
||||||
|
|
||||||
# CLI11
|
# CLI11
|
||||||
@@ -24,7 +23,7 @@ ptprnt_exe = executable(
|
|||||||
'ptprnt',
|
'ptprnt',
|
||||||
'src/main.cpp',
|
'src/main.cpp',
|
||||||
install: true,
|
install: true,
|
||||||
dependencies : [usb_dep, log_dep, fmt_dep, pangocairo_dep, cli11_dep],
|
dependencies : [usb_dep, log_dep, pangocairo_dep, cli11_dep],
|
||||||
include_directories: incdir,
|
include_directories: incdir,
|
||||||
sources: [ptprnt_srcs],
|
sources: [ptprnt_srcs],
|
||||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
||||||
|
@@ -41,11 +41,6 @@
|
|||||||
|
|
||||||
namespace ptprnt::printer {
|
namespace ptprnt::printer {
|
||||||
|
|
||||||
const PrinterInfo P700Printer::mInfo = {.driverName = "P700",
|
|
||||||
.name = "Brother P-touch P700",
|
|
||||||
.version = "v1.0",
|
|
||||||
.usbId{0x04f9, 0x2061}};
|
|
||||||
|
|
||||||
P700Printer::~P700Printer() {
|
P700Printer::~P700Printer() {
|
||||||
detachUsbDevice();
|
detachUsbDevice();
|
||||||
if (mUsbHndl) {
|
if (mUsbHndl) {
|
||||||
@@ -85,8 +80,12 @@ const PrinterStatus P700Printer::getPrinterStatus() {
|
|||||||
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
||||||
}
|
}
|
||||||
|
|
||||||
const libusbwrap::usbId P700Printer::getUsbId() {
|
const uint16_t P700Printer::getVid() {
|
||||||
return mInfo.usbId;
|
return mInfo.vid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint16_t P700Printer::getPid() {
|
||||||
|
return mInfo.pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P700Printer::attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) {
|
bool P700Printer::attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) {
|
||||||
|
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "interface/IPrinterDriver.hpp"
|
#include "interface/IPrinterDriver.hpp"
|
||||||
#include "interface/IPrinterTypes.hpp"
|
#include "interface/IPrinterTypes.hpp"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -45,13 +44,11 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
P700Printer(P700Printer&&) = default;
|
P700Printer(P700Printer&&) = default;
|
||||||
P700Printer& operator=(P700Printer&&) = default;
|
P700Printer& operator=(P700Printer&&) = default;
|
||||||
|
|
||||||
// Printer info has to be static to be accessed without instantiation
|
|
||||||
static const PrinterInfo mInfo;
|
|
||||||
|
|
||||||
// IPrinterDriver
|
// IPrinterDriver
|
||||||
const std::string_view getDriverName() override;
|
const std::string_view getDriverName() override;
|
||||||
const std::string_view getName() override;
|
const std::string_view getName() override;
|
||||||
const libusbwrap::usbId getUsbId() override;
|
const uint16_t getPid() override;
|
||||||
|
const uint16_t getVid() override;
|
||||||
const std::string_view getVersion() override;
|
const std::string_view getVersion() override;
|
||||||
const PrinterInfo getPrinterInfo() override;
|
const PrinterInfo getPrinterInfo() override;
|
||||||
const PrinterStatus getPrinterStatus() override;
|
const PrinterStatus getPrinterStatus() override;
|
||||||
@@ -65,6 +62,12 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
||||||
|
|
||||||
|
static constexpr PrinterInfo mInfo{.driverName = "P700",
|
||||||
|
.name = "Brother P-touch P700",
|
||||||
|
.version = "v1.0",
|
||||||
|
.vid = 0x04f9,
|
||||||
|
.pid = 0x2061};
|
||||||
std::map<std::string, std::vector<uint8_t>> commands{
|
std::map<std::string, std::vector<uint8_t>> commands{
|
||||||
{"rasterstart",
|
{"rasterstart",
|
||||||
{0x1b, 0x69, 0x61,
|
{0x1b, 0x69, 0x61,
|
||||||
|
@@ -1,22 +0,0 @@
|
|||||||
#include "PrinterDriverFactory.hpp"
|
|
||||||
#include <memory>
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
#include "P700Printer.hpp"
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
namespace ptprnt {
|
|
||||||
|
|
||||||
std::shared_ptr<IPrinterDriver> PrinterDriverFactory::create(libusbwrap::usbId id) {
|
|
||||||
|
|
||||||
if(printer::P700Printer::mInfo.usbId == id) {
|
|
||||||
spdlog::debug("Printer is P700!");
|
|
||||||
return std::make_shared<printer::P700Printer>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
spdlog::debug("{:04x}:{:04x} is not a compatible printer", id.first, id.second);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,22 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
#include "interface/IPrinterDriver.hpp"
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
|
|
||||||
namespace ptprnt {
|
|
||||||
|
|
||||||
class PrinterDriverFactory {
|
|
||||||
public:
|
|
||||||
PrinterDriverFactory() = default;
|
|
||||||
~PrinterDriverFactory() = default;
|
|
||||||
|
|
||||||
PrinterDriverFactory(const PrinterDriverFactory&) = delete;
|
|
||||||
PrinterDriverFactory& operator=(const PrinterDriverFactory&) = delete;
|
|
||||||
PrinterDriverFactory(PrinterDriverFactory&&) = delete;
|
|
||||||
PrinterDriverFactory& operator=(PrinterDriverFactory&&) = delete;
|
|
||||||
|
|
||||||
std::shared_ptr<IPrinterDriver> create(libusbwrap::usbId id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@@ -16,28 +16,17 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
|
||||||
#define SPDLOG_DEBUG_ON
|
|
||||||
#define SPDLOG_TRACE_ON
|
|
||||||
|
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
|
|
||||||
#include <CLI/App.hpp>
|
#include <CLI/App.hpp>
|
||||||
#include <fmt/core.h>
|
|
||||||
#include <spdlog/common.h>
|
#include <spdlog/common.h>
|
||||||
#include <spdlog/details/synchronous_factory.h>
|
|
||||||
#include <spdlog/logger.h>
|
|
||||||
#include <spdlog/sinks/base_sink.h>
|
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "CLI/Option.hpp"
|
#include "CLI/Option.hpp"
|
||||||
#include "PrinterDriverFactory.hpp"
|
#include "P700Printer.hpp"
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||||
|
|
||||||
@@ -56,35 +45,32 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mVerboseFlag) {
|
if (mVerboseFlag) {
|
||||||
setupLogger(spdlog::level::debug);
|
setupLogger(spdlog::level::trace);
|
||||||
} else {
|
} else {
|
||||||
setupLogger(spdlog::level::err);
|
setupLogger(spdlog::level::critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mUsbDeviceFactory.init()) {
|
if (!mUsbDeviceFactory.init()) {
|
||||||
spdlog::error("Could not initialize libusb");
|
spdlog::error("Could not initialize libusb");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
mCompatiblePrinters = {std::make_shared<ptprnt::printer::P700Printer>()};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PtouchPrint::run() {
|
int PtouchPrint::run() {
|
||||||
spdlog::debug("ptprnt version {}", mVersionString);
|
auto numFoundPrinters = getCompatiblePrinters();
|
||||||
SPDLOG_TRACE("testing trace");
|
|
||||||
mDetectedPrinters = getCompatiblePrinters();
|
|
||||||
auto numFoundPrinters = mDetectedPrinters.size();
|
|
||||||
if (numFoundPrinters == 0) {
|
if (numFoundPrinters == 0) {
|
||||||
spdlog::error(
|
spdlog::error(
|
||||||
"No compatible printers found, please make sure that they are turned on and connected");
|
"No compatible printers found, please make sure if they are turned on and connected");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (numFoundPrinters > 1) {
|
} else if (numFoundPrinters > 1) {
|
||||||
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto printer = mDetectedPrinters[0];
|
auto printer = mCompatiblePrinters[0];
|
||||||
const auto printerUsbId = printer->getUsbId();
|
auto devices = mUsbDeviceFactory.findDevices(printer->getVid(), printer->getPid());
|
||||||
auto devices = mUsbDeviceFactory.findDevices(printerUsbId.first, printerUsbId.second);
|
|
||||||
if (devices.size() != 1) {
|
if (devices.size() != 1) {
|
||||||
spdlog::warn(
|
spdlog::warn(
|
||||||
"Found more than one device of the same printer on bus. Currently not supported");
|
"Found more than one device of the same printer on bus. Currently not supported");
|
||||||
@@ -98,44 +84,42 @@ int PtouchPrint::run() {
|
|||||||
//printer->printText("wurst", 1);
|
//printer->printText("wurst", 1);
|
||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
spdlog::debug("Command: {}", cmd.second);
|
std::cout << cmd.second << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters() {
|
unsigned int PtouchPrint::getCompatiblePrinters() {
|
||||||
|
|
||||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers {};
|
|
||||||
|
|
||||||
for (auto usbDev : usbDevs) {
|
for (auto usbDev : usbDevs) {
|
||||||
auto driver = driverFactory->create(usbDev->getUsbId());
|
auto foundPrinterIt =
|
||||||
if(driver != nullptr) {
|
std::find_if(mCompatiblePrinters.begin(), mCompatiblePrinters.end(),
|
||||||
foundPrinterDrivers.push_back(driver);
|
[usbDev](const std::shared_ptr<ptprnt::IPrinterDriver>& printer) {
|
||||||
|
return printer->getPid() == usbDev->getPid() &&
|
||||||
|
printer->getVid() == usbDev->getVid();
|
||||||
|
});
|
||||||
|
if (foundPrinterIt == mCompatiblePrinters.end()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
auto foundPrinter = *foundPrinterIt;
|
||||||
|
spdlog::info("Found Printer {}", foundPrinter->getName());
|
||||||
|
mDetectedPrinters.push_back(foundPrinter);
|
||||||
}
|
}
|
||||||
return foundPrinterDrivers;
|
// we can delete all instantiated printers that are not compatible
|
||||||
|
mCompatiblePrinters.clear();
|
||||||
|
return mDetectedPrinters.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
spdlog::set_level(lvl);
|
||||||
consoleSink->set_level(lvl);
|
spdlog::debug("Starting ptprnt {}", mVersionString);
|
||||||
consoleSink->set_pattern("%^%L:%$ %v");
|
|
||||||
|
|
||||||
auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("ptprnt.log", true);
|
|
||||||
fileSink->set_level(spdlog::level::trace);
|
|
||||||
fileSink->set_pattern("%Y-%m-%d %H:%m:%S:%e [pid:%P tid:%t] [%^%l%$] %v (%@)");
|
|
||||||
std::vector<spdlog::sink_ptr> sinks{consoleSink, fileSink};
|
|
||||||
auto logger = std::make_shared<spdlog::logger>("default_logger", sinks.begin(), sinks.end());
|
|
||||||
logger->set_level(spdlog::level::trace);
|
|
||||||
spdlog::set_default_logger(logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupCliParser() {
|
void PtouchPrint::setupCliParser() {
|
||||||
auto printVersion = [this](std::size_t) {
|
auto printVersion = [this](std::size_t) {
|
||||||
fmt::print("ptprnt version: {}\n", mVersionString);
|
std::cout << "ptprnt version: " << mVersionString << std::endl;
|
||||||
};
|
};
|
||||||
|
|
||||||
// General options
|
// General options
|
||||||
|
@@ -49,12 +49,13 @@ class PtouchPrint {
|
|||||||
// methods
|
// methods
|
||||||
void setupLogger(spdlog::level::level_enum lvl);
|
void setupLogger(spdlog::level::level_enum lvl);
|
||||||
void setupCliParser();
|
void setupCliParser();
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> getCompatiblePrinters();
|
unsigned int getCompatiblePrinters();
|
||||||
|
|
||||||
// member variables
|
// member variables
|
||||||
CLI::App mApp{ptprnt::APP_DESC};
|
CLI::App mApp{ptprnt::APP_DESC};
|
||||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> mDetectedPrinters{};
|
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mCompatiblePrinters{};
|
||||||
|
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mDetectedPrinters{};
|
||||||
std::vector<CliCmd> mCommands{};
|
std::vector<CliCmd> mCommands{};
|
||||||
std::string mVersionString = "";
|
std::string mVersionString = "";
|
||||||
|
|
||||||
|
@@ -30,11 +30,11 @@ namespace ptprnt {
|
|||||||
|
|
||||||
class IPrinterDriver {
|
class IPrinterDriver {
|
||||||
public:
|
public:
|
||||||
virtual ~IPrinterDriver() = default;
|
|
||||||
virtual const std::string_view getDriverName() = 0;
|
virtual const std::string_view getDriverName() = 0;
|
||||||
virtual const std::string_view getName() = 0;
|
virtual const std::string_view getName() = 0;
|
||||||
virtual const std::string_view getVersion() = 0;
|
virtual const std::string_view getVersion() = 0;
|
||||||
virtual const libusbwrap::usbId getUsbId() = 0;
|
virtual const uint16_t getVid() = 0;
|
||||||
|
virtual const uint16_t getPid() = 0;
|
||||||
virtual const PrinterInfo getPrinterInfo() = 0;
|
virtual const PrinterInfo getPrinterInfo() = 0;
|
||||||
virtual const PrinterStatus getPrinterStatus() = 0;
|
virtual const PrinterStatus getPrinterStatus() = 0;
|
||||||
virtual bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) = 0;
|
virtual bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) = 0;
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
|
|
||||||
@@ -29,7 +28,8 @@ struct PrinterInfo {
|
|||||||
std::string_view driverName = "";
|
std::string_view driverName = "";
|
||||||
std::string_view name = "";
|
std::string_view name = "";
|
||||||
std::string_view version = "";
|
std::string_view version = "";
|
||||||
libusbwrap::usbId usbId {0x00, 0x00};
|
uint16_t vid = 0x00;
|
||||||
|
uint16_t pid = 0x00;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PrinterStatus {
|
struct PrinterStatus {
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <memory>
|
||||||
|
|
||||||
#include "libusb.h"
|
#include "libusb.h"
|
||||||
|
|
||||||
@@ -40,7 +40,4 @@ enum class Error {
|
|||||||
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
||||||
OTHER = LIBUSB_ERROR_OTHER
|
OTHER = LIBUSB_ERROR_OTHER
|
||||||
};
|
};
|
||||||
|
}
|
||||||
using usbId = std::pair<uint16_t, uint16_t>;
|
|
||||||
|
|
||||||
} // namespace libusbwrap
|
|
@@ -104,8 +104,12 @@ bool UsbDevice::bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int*
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usbId UsbDevice::getUsbId() {
|
const uint16_t UsbDevice::getVid() {
|
||||||
return {mLibusbDevDesc.idVendor, mLibusbDevDesc.idProduct};
|
return mLibusbDevDesc.idVendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint16_t UsbDevice::getPid() {
|
||||||
|
return mLibusbDevDesc.idProduct;
|
||||||
}
|
}
|
||||||
|
|
||||||
const device::Speed UsbDevice::getSpeed() {
|
const device::Speed UsbDevice::getSpeed() {
|
||||||
|
@@ -29,8 +29,8 @@
|
|||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
class UsbDevice : public IUsbDevice {
|
class UsbDevice : public IUsbDevice {
|
||||||
public:
|
public:
|
||||||
explicit UsbDevice(libusb_context* ctx, libusb_device* dev);
|
UsbDevice(libusb_context* ctx, libusb_device* dev);
|
||||||
~UsbDevice() override;
|
~UsbDevice();
|
||||||
|
|
||||||
// delete copy ctor and assignment
|
// delete copy ctor and assignment
|
||||||
UsbDevice(const UsbDevice&) = delete;
|
UsbDevice(const UsbDevice&) = delete;
|
||||||
@@ -47,7 +47,8 @@ class UsbDevice : public IUsbDevice {
|
|||||||
unsigned int timeout) override;
|
unsigned int timeout) override;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
const usbId getUsbId() override;
|
const uint16_t getVid() override;
|
||||||
|
const uint16_t getPid() override;
|
||||||
const device::Speed getSpeed() override;
|
const device::Speed getSpeed() override;
|
||||||
const uint8_t getBusNumber() override;
|
const uint8_t getBusNumber() override;
|
||||||
const uint8_t getPortNumber() override;
|
const uint8_t getPortNumber() override;
|
||||||
|
@@ -24,9 +24,8 @@ enum class Speed {
|
|||||||
|
|
||||||
class IUsbDevice {
|
class IUsbDevice {
|
||||||
public:
|
public:
|
||||||
virtual ~IUsbDevice() = default;
|
virtual bool open() = 0;
|
||||||
virtual bool open() = 0;
|
virtual void close() = 0;
|
||||||
virtual void close() = 0;
|
|
||||||
|
|
||||||
// libusb wrappers
|
// libusb wrappers
|
||||||
virtual bool detachKernelDriver(int interfaceNo) = 0;
|
virtual bool detachKernelDriver(int interfaceNo) = 0;
|
||||||
@@ -36,7 +35,8 @@ class IUsbDevice {
|
|||||||
unsigned int timeout) = 0;
|
unsigned int timeout) = 0;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
virtual const usbId getUsbId() = 0;
|
virtual const uint16_t getVid() = 0;
|
||||||
|
virtual const uint16_t getPid() = 0;
|
||||||
virtual const device::Speed getSpeed() = 0;
|
virtual const device::Speed getSpeed() = 0;
|
||||||
virtual const uint8_t getBusNumber() = 0;
|
virtual const uint8_t getBusNumber() = 0;
|
||||||
virtual const uint8_t getPortNumber() = 0;
|
virtual const uint8_t getPortNumber() = 0;
|
||||||
|
@@ -9,8 +9,7 @@
|
|||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
class IUsbDeviceFactory {
|
class IUsbDeviceFactory {
|
||||||
public:
|
public:
|
||||||
virtual ~IUsbDeviceFactory() = default;
|
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
||||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
|
||||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
||||||
};
|
};
|
||||||
} // namespace libusbwrap
|
} // namespace libusbwrap
|
@@ -8,7 +8,6 @@ ptprnt_hpps = files (
|
|||||||
'interface/IPrinterTypes.hpp',
|
'interface/IPrinterTypes.hpp',
|
||||||
'P700Printer.hpp',
|
'P700Printer.hpp',
|
||||||
'PtouchPrint.hpp',
|
'PtouchPrint.hpp',
|
||||||
'PrinterDriverFactory.hpp',
|
|
||||||
'graphics/Bitmap.hpp',
|
'graphics/Bitmap.hpp',
|
||||||
'graphics/Image.hpp',
|
'graphics/Image.hpp',
|
||||||
'graphics/Monochrome.hpp'
|
'graphics/Monochrome.hpp'
|
||||||
@@ -16,7 +15,6 @@ ptprnt_hpps = files (
|
|||||||
|
|
||||||
ptprnt_srcs = files (
|
ptprnt_srcs = files (
|
||||||
'PtouchPrint.cpp',
|
'PtouchPrint.cpp',
|
||||||
'PrinterDriverFactory.cpp',
|
|
||||||
'P700Printer.cpp',
|
'P700Printer.cpp',
|
||||||
'graphics/Image.cpp',
|
'graphics/Image.cpp',
|
||||||
'graphics/Bitmap.cpp',
|
'graphics/Bitmap.cpp',
|
||||||
|
Reference in New Issue
Block a user