Compare commits
6 Commits
a706a0d822
...
5a6a268c93
Author | SHA1 | Date | |
---|---|---|---|
5a6a268c93
|
|||
b20fa5ff13
|
|||
de62dd76bf
|
|||
67c4e18f03
|
|||
37b6553e48
|
|||
a059df7f67
|
82
.clang-format
Normal file
82
.clang-format
Normal file
@@ -0,0 +1,82 @@
|
||||
# Google C/C++ Code Style settings
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignOperands: Align
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterStruct: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 80
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
FixNamespaceComments: true
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PointerAlignment: Left
|
||||
ReflowComments: false
|
||||
SeparateDefinitionBlocks: Always
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: c++17
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
2
.clang-format-include
Normal file
2
.clang-format-include
Normal file
@@ -0,0 +1,2 @@
|
||||
inc/*
|
||||
src/*
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
build/
|
||||
builddir/
|
||||
.cache/
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
!.vscode/settings.json
|
||||
!.vscode/settings.json
|
||||
!.vscode/launch.json
|
16
.vscode/c_cpp_properties.json
vendored
16
.vscode/c_cpp_properties.json
vendored
@@ -1 +1,15 @@
|
||||
{}
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"compilerPath": "/usr/bin/clang",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"compileCommands": "${workspaceFolder}/builddir/compile_commands.json",
|
||||
"browse": {
|
||||
"path": ["${workspaceFolder}"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
|
||||
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
|
||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Starten",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/builddir/ptprnt",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
83
.vscode/settings.json
vendored
83
.vscode/settings.json
vendored
@@ -2,5 +2,86 @@
|
||||
"clangd.arguments": [ "-log=verbose",
|
||||
"-pretty",
|
||||
"--background-index",
|
||||
"--compile-commands-dir=${workspaceFolder}/build"]
|
||||
"--compile-commands-dir=${workspaceFolder}/builddir"
|
||||
],
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"strstream": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"cfenv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"source_location": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"valarray": "cpp",
|
||||
"variant": "cpp",
|
||||
"csignal": "cpp",
|
||||
"any": "cpp",
|
||||
"regex": "cpp",
|
||||
"future": "cpp",
|
||||
"charconv": "cpp"
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(ptouch-prnt)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" CACHE STRING "Set C++ Compiler Flags" FORCE)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(ptouch-prnt ${SOURCES})
|
||||
|
||||
target_include_directories(ptouch-prnt
|
||||
PRIVATE
|
||||
${PROJECT_SOURCE_DIR/inc}
|
||||
)
|
11
inc/Bitmap.hpp
Normal file
11
inc/Bitmap.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <vector>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::bitmap {
|
||||
|
||||
struct Bitmap {
|
||||
std::vector<std::vector<int>> map;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::bitmap
|
12
inc/DriverTypes.hpp
Normal file
12
inc/DriverTypes.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <string>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
struct info {
|
||||
std::string name{""};
|
||||
std::string version{""};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
44
inc/IDriver.hpp
Normal file
44
inc/IDriver.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
#include "DriverTypes.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class IDriver {
|
||||
public:
|
||||
virtual ~IDriver(){};
|
||||
|
||||
/**
|
||||
* @brief Get Information struct about this driver
|
||||
*
|
||||
* @return driver::info
|
||||
*/
|
||||
virtual driver::info getInfo() = 0;
|
||||
|
||||
/**
|
||||
* @brief opens up the device specified
|
||||
*
|
||||
* @return true successfully open up device
|
||||
* @return false failed to open device
|
||||
*/
|
||||
virtual bool open() = 0;
|
||||
|
||||
/**
|
||||
* @brief close the device
|
||||
*
|
||||
* @return true successfully closed device
|
||||
* @return false failed to close device
|
||||
*/
|
||||
virtual bool close() = 0;
|
||||
|
||||
/**
|
||||
* @brief Send a command to device
|
||||
*
|
||||
* @return true successfully sent command to device
|
||||
* @return false error sending command
|
||||
*/
|
||||
virtual bool command() = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
43
inc/IPrinter.hpp
Normal file
43
inc/IPrinter.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "PrinterTypes.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Bitmap.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
class IPrinter {
|
||||
public:
|
||||
virtual ~IPrinter(){};
|
||||
|
||||
/**
|
||||
* @brief Get Information struct about the printer
|
||||
*
|
||||
* @return driver::info
|
||||
*/
|
||||
virtual printer::info getInfo() = 0;
|
||||
|
||||
/**
|
||||
* @brief Prints text immediatly
|
||||
*
|
||||
* @param text Text to print
|
||||
* @param fontSize Size of the text to print
|
||||
* @return true Printing succeeded
|
||||
* @return false Printing failed
|
||||
*/
|
||||
virtual bool printText(std::string_view text, uint32_t fontSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief Prints supplied bitmap immediatly
|
||||
*
|
||||
* @param bm Bitmap to print
|
||||
* @return true Printing succeeded
|
||||
* @return false Printing failed
|
||||
*/
|
||||
virtual bool printBitmap(std::shared_ptr<bitmap::Bitmap> bm) = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::printer
|
17
inc/IUsb.hpp
Normal file
17
inc/IUsb.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "UsbTypes.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class IUsb {
|
||||
public:
|
||||
virtual ~IUsb() = default;
|
||||
|
||||
virtual std::optional<std::vector<UsbDevice>> getDevices() = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
29
inc/P700Driver.hpp
Normal file
29
inc/P700Driver.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "IDriver.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "Usb.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class P700Driver : public IDriver {
|
||||
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
|
25
inc/P700Printer.hpp
Normal file
25
inc/P700Printer.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "IPrinter.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "P700Driver.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
class P700Printer : public IPrinter {
|
||||
public:
|
||||
P700Printer(std::unique_ptr<driver::P700Driver> driver);
|
||||
~P700Printer() override;
|
||||
|
||||
printer::info getInfo() override;
|
||||
bool printText(std::string_view text, uint32_t fontSize) override;
|
||||
bool printBitmap(std::shared_ptr<bitmap::Bitmap> bm) override;
|
||||
|
||||
private:
|
||||
static info mPrinterInfo;
|
||||
std::unique_ptr<driver::P700Driver> mDriver;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::printer
|
21
inc/PrinterTypes.hpp
Normal file
21
inc/PrinterTypes.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <string>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
enum class colorMode {
|
||||
monochrome = 0,
|
||||
color = 0,
|
||||
};
|
||||
|
||||
struct info {
|
||||
std::string name{""};
|
||||
std::string revision{""};
|
||||
uint32_t xres = {0};
|
||||
uint32_t yres = {0};
|
||||
colorMode color = {colorMode::monochrome};
|
||||
bool cutter = {false};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::printer
|
21
inc/Usb.hpp
Normal file
21
inc/Usb.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "IUsb.hpp"
|
||||
#include "UsbTypes.hpp"
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class Usb : public IUsb {
|
||||
public:
|
||||
Usb();
|
||||
~Usb() override;
|
||||
|
||||
std::optional<std::vector<UsbDevice>> getDevices() override;
|
||||
|
||||
private:
|
||||
std::vector<UsbDevice> mDevices{};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
15
inc/UsbTypes.hpp
Normal file
15
inc/UsbTypes.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
struct UsbDevice {
|
||||
uint16_t vendorId{0};
|
||||
uint16_t productId{0};
|
||||
libusb_device* dev{nullptr};
|
||||
libusb_device_handle* hndl{nullptr};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
25
meson.build
Normal file
25
meson.build
Normal file
@@ -0,0 +1,25 @@
|
||||
project('ptprnt', 'cpp',
|
||||
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')
|
||||
|
||||
srcs = [
|
||||
'src/main.cpp',
|
||||
'src/P700Driver.cpp',
|
||||
'src/P700Printer.cpp',
|
||||
'src/Usb.cpp'
|
||||
]
|
||||
|
||||
executable(
|
||||
'ptprnt',
|
||||
srcs,
|
||||
include_directories : incdir,
|
||||
dependencies : [usbdep, logdep],
|
||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"']
|
||||
)
|
66
src/P700Driver.cpp
Normal file
66
src/P700Driver.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "P700Driver.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
P700Driver::P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor, uint16_t usbProductId)
|
||||
: mUsbDriver{std::move(usbDriver)}
|
||||
, mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId}
|
||||
|
||||
{
|
||||
spdlog::debug("P700Driver constructing");
|
||||
if(!init()) {
|
||||
spdlog::error("Could not find any P700 Printers.");
|
||||
}
|
||||
else {
|
||||
spdlog::info("Found P700 Printer :-).");
|
||||
}
|
||||
}
|
||||
|
||||
P700Driver::~P700Driver() {
|
||||
spdlog::debug("P700Driver destructing");
|
||||
}
|
||||
|
||||
driver::info P700Driver::getInfo() {
|
||||
return driver::info{};
|
||||
}
|
||||
|
||||
bool P700Driver::open() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool P700Driver::close() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool P700Driver::command() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool P700Driver::init() {
|
||||
auto devs = mUsbDriver->getDevices();
|
||||
|
||||
if(!devs.has_value()) {
|
||||
spdlog::error("No USB devices found");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto devIt = std::find_if(devs.value().begin(), devs.value().end(),
|
||||
[=] (auto dev) { return mUsbDev.vendorId == dev.vendorId && mUsbDev.productId == dev.productId;}
|
||||
);
|
||||
|
||||
if(devIt == devs.value().end()) {
|
||||
spdlog::error("No device with {0:04X}:{1:04X}", mUsbDev.vendorId, mUsbDev.productId);
|
||||
return false;
|
||||
}
|
||||
|
||||
mUsbDev = *devIt;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ptprnt::driver
|
32
src/P700Printer.cpp
Normal file
32
src/P700Printer.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "P700Printer.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
P700Printer::P700Printer(std::unique_ptr<driver::P700Driver> driver) {
|
||||
if (!driver->open()) {
|
||||
throw std::invalid_argument("Could not open driver!");
|
||||
}
|
||||
}
|
||||
|
||||
P700Printer::~P700Printer() {
|
||||
if (!mDriver->close()) {
|
||||
std::cerr << "Could not close driver properly!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
printer::info P700Printer::getInfo() {
|
||||
return printer::info{};
|
||||
}
|
||||
|
||||
bool P700Printer::printText(std::string_view text, uint32_t fontSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool P700Printer::printBitmap(std::shared_ptr<bitmap::Bitmap> bm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ptprnt::printer
|
46
src/Usb.cpp
Normal file
46
src/Usb.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <optional>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
Usb::Usb() {
|
||||
spdlog::debug("Usb constructing");
|
||||
libusb_init(NULL);
|
||||
}
|
||||
Usb::~Usb() {
|
||||
spdlog::debug("Usb destructing");
|
||||
}
|
||||
|
||||
std::optional<std::vector<UsbDevice>> Usb::getDevices() {
|
||||
libusb_device ** devs;
|
||||
libusb_device *dev;
|
||||
struct libusb_device_descriptor desc;
|
||||
int r,i=0;
|
||||
|
||||
mDevices.clear();
|
||||
|
||||
libusb_get_device_list(NULL, &devs);
|
||||
|
||||
while ((dev=devs[i++]) != NULL) {
|
||||
UsbDevice newDev;
|
||||
|
||||
if ((r=libusb_get_device_descriptor(dev, &desc)) < 0) {
|
||||
spdlog::error("failed to open device");
|
||||
libusb_free_device_list(devs, 1);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
newDev.vendorId = desc.idVendor;
|
||||
newDev.productId = desc.idProduct;
|
||||
|
||||
mDevices.push_back(newDev);
|
||||
}
|
||||
|
||||
return mDevices;
|
||||
}
|
||||
|
||||
} // namespace ptprnt::driver
|
32
src/main.cpp
32
src/main.cpp
@@ -1,9 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "IPrinter.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace ptprnt;
|
||||
|
||||
void setupLogger() {
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
spdlog::info("Starting ptprnt {}", PROJ_VERSION);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
setupLogger();
|
||||
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
auto usb = std::make_shared<driver::Usb>();
|
||||
auto maybeDevs = usb->getDevices();
|
||||
if(!maybeDevs.has_value()) {
|
||||
spdlog::error("No USB devices found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto driver = std::make_unique<driver::P700Driver>(usb);
|
||||
//auto printer = std::make_unique<printer::P700Printer>(std::move(driver));
|
||||
//printer::info info = printer->getInfo();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user