diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d5f2d07 --- /dev/null +++ b/.clang-format @@ -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: 2 +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 diff --git a/.clang-format-include b/.clang-format-include new file mode 100644 index 0000000..ab8a1e7 --- /dev/null +++ b/.clang-format-include @@ -0,0 +1,2 @@ +inc/* +src/* diff --git a/.gitignore b/.gitignore index 2298a4a..7b016fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -build/ +builddir/ .cache/ .vscode/* !.vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 9e26dfe..1dad740 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1 +1,12 @@ -{} \ No newline at end of file +{ + "configurations": [ + { + "name": "Linux", + "compilerPath": "/usr/bin/clang", + "cStandard": "c11", + "cppStandard": "c++17", + "compileCommands": "/builddir/compile_commands.json" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 6db939e..0a9c556 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,7 @@ "clangd.arguments": [ "-log=verbose", "-pretty", "--background-index", - "--compile-commands-dir=${workspaceFolder}/build"] + "--compile-commands-dir=${workspaceFolder}/builddir", + "-std=c++17" + ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 2279a87..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -project(ptprnt LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "Set C++ Compiler Flags" FORCE) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - - -set(SOURCES - src/P700Printer.cpp - src/P700Driver.cpp - src/main.cpp -) - -add_executable(${PROJECT_NAME} ${SOURCES}) - -target_include_directories(${PROJECT_NAME} - PUBLIC - ${PROJECT_SOURCE_DIR}/inc -) \ No newline at end of file diff --git a/inc/Bitmap.hpp b/inc/Bitmap.hpp index 80706f4..d83cb66 100644 --- a/inc/Bitmap.hpp +++ b/inc/Bitmap.hpp @@ -5,7 +5,7 @@ namespace ptprnt::bitmap { struct Bitmap { - std::vector> map; + std::vector> map; }; -} \ No newline at end of file +} // namespace ptprnt::bitmap \ No newline at end of file diff --git a/inc/DriverTypes.hpp b/inc/DriverTypes.hpp index bde447f..6a101ac 100644 --- a/inc/DriverTypes.hpp +++ b/inc/DriverTypes.hpp @@ -5,8 +5,8 @@ namespace ptprnt::driver { struct info { - std::string name{""}; - std::string version{""}; + std::string name{""}; + std::string version{""}; }; -} \ No newline at end of file +} // namespace ptprnt::driver \ No newline at end of file diff --git a/inc/IDriver.hpp b/inc/IDriver.hpp index f90aa12..4eee07f 100644 --- a/inc/IDriver.hpp +++ b/inc/IDriver.hpp @@ -5,43 +5,40 @@ namespace ptprnt::driver { -class IDriver -{ -public: - virtual ~IDriver() {}; +class IDriver { + public: + virtual ~IDriver(){}; - /** + /** * @brief Get Information struct about this driver * * @return driver::info */ - virtual driver::info getInfo() = 0; - - /** + 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; + virtual bool open() = 0; - - /** + /** * @brief close the device * * @return true successfully closed device * @return false failed to close device */ - virtual bool close() = 0; + 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; - + virtual bool command() = 0; }; -} \ No newline at end of file +} // namespace ptprnt::driver \ No newline at end of file diff --git a/inc/IPrinter.hpp b/inc/IPrinter.hpp index d3eaa68..0ea9dda 100644 --- a/inc/IPrinter.hpp +++ b/inc/IPrinter.hpp @@ -9,19 +9,18 @@ namespace ptprnt::printer { -class IPrinter -{ -public: - virtual ~IPrinter() {}; +class IPrinter { + public: + virtual ~IPrinter(){}; - /** + /** * @brief Get Information struct about the printer * * @return driver::info */ - virtual printer::info getInfo() = 0; + virtual printer::info getInfo() = 0; - /** + /** * @brief Prints text immediatly * * @param text Text to print @@ -29,16 +28,16 @@ public: * @return true Printing succeeded * @return false Printing failed */ - virtual bool printText(std::string_view text, uint32_t fontSize) = 0; + 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 bm) = 0; + virtual bool printBitmap(std::shared_ptr bm) = 0; }; -} \ No newline at end of file +} // namespace ptprnt::printer \ No newline at end of file diff --git a/inc/P700Driver.hpp b/inc/P700Driver.hpp index 6403e23..0d4d308 100644 --- a/inc/P700Driver.hpp +++ b/inc/P700Driver.hpp @@ -1,21 +1,22 @@ - #include "IDriver.hpp" + #include +#include + #pragma once namespace ptprnt::driver { -class P700Driver : public IDriver -{ -public: - P700Driver(uint16_t UsbDevVendor = 0x04f9, uint16_t UsbDevId = 0x2061); - ~P700Driver() override; +class P700Driver : public IDriver { + public: + P700Driver(uint16_t UsbDevVendor = 0x04f9, uint16_t UsbDevId = 0x2061); + ~P700Driver() override; - driver::info getInfo() override; - bool open() override; - bool close() override; - bool command() override; + driver::info getInfo() override; + bool open() override; + bool close() override; + bool command() override; }; -} \ No newline at end of file +} // namespace ptprnt::driver \ No newline at end of file diff --git a/inc/P700Printer.hpp b/inc/P700Printer.hpp index 5540704..e0061b7 100644 --- a/inc/P700Printer.hpp +++ b/inc/P700Printer.hpp @@ -8,19 +8,18 @@ namespace ptprnt::printer { -class P700Printer : public IPrinter -{ -public: - P700Printer(std::unique_ptr driver); - ~P700Printer() override; +class P700Printer : public IPrinter { + public: + P700Printer(std::unique_ptr driver); + ~P700Printer() override; - printer::info getInfo() override; - bool printText(std::string_view text, uint32_t fontSize) override; - bool printBitmap(std::shared_ptr bm) override; + printer::info getInfo() override; + bool printText(std::string_view text, uint32_t fontSize) override; + bool printBitmap(std::shared_ptr bm) override; -private: - static info mPrinterInfo; - std::unique_ptr mDriver; + private: + static info mPrinterInfo; + std::unique_ptr mDriver; }; -} \ No newline at end of file +} // namespace ptprnt::printer \ No newline at end of file diff --git a/inc/PrinterTypes.hpp b/inc/PrinterTypes.hpp index ce46a4a..10137ee 100644 --- a/inc/PrinterTypes.hpp +++ b/inc/PrinterTypes.hpp @@ -5,17 +5,17 @@ namespace ptprnt::printer { enum class colorMode { - monochrome = 0, - color = 0, + 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}; + std::string name{""}; + std::string revision{""}; + uint32_t xres = {0}; + uint32_t yres = {0}; + colorMode color = {colorMode::monochrome}; + bool cutter = {false}; }; -} \ No newline at end of file +} // namespace ptprnt::printer \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..d97ae9e --- /dev/null +++ b/meson.build @@ -0,0 +1,21 @@ +project('ptprnt', 'cpp', + version: '0.1.0', + license: 'GPLv3', + default_options : ['c_std=c11', 'cpp_std=c++17'] +) + +usbdep = dependency('libusb-1.0') + +incdir = include_directories('inc') + +srcs = [ + 'src/main.cpp', + 'src/P700Driver.cpp', + 'src/P700Printer.cpp' +] + +executable( + 'ptprnt', srcs, + include_directories : incdir, + dependencies : usbdep +) \ No newline at end of file diff --git a/src/P700Driver.cpp b/src/P700Driver.cpp index bd9d548..4026329 100644 --- a/src/P700Driver.cpp +++ b/src/P700Driver.cpp @@ -1,32 +1,28 @@ #include "P700Driver.hpp" -#include #include +#include namespace ptprnt::driver { -P700Driver::P700Driver(uint16_t UsbDevVendor, uint16_t UsbDevId) { +P700Driver::P700Driver(uint16_t UsbDevVendor, uint16_t UsbDevId) {} -} - -P700Driver::~P700Driver() { - -} +P700Driver::~P700Driver() {} driver::info P700Driver::getInfo() { - return driver::info{}; + return driver::info{}; } bool P700Driver::open() { - return false; + return false; } bool P700Driver::close() { - return false; + return false; } bool P700Driver::command() { - return false; + return false; } -} \ No newline at end of file +} // namespace ptprnt::driver \ No newline at end of file diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index dbd4cf1..4b9f1af 100644 --- a/src/P700Printer.cpp +++ b/src/P700Printer.cpp @@ -1,31 +1,32 @@ #include "P700Printer.hpp" -#include #include +#include namespace ptprnt::printer { P700Printer::P700Printer(std::unique_ptr driver) { - if(!driver->open()) { - throw std::invalid_argument("Could not open 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; - } + if (!mDriver->close()) { + std::cerr << "Could not close driver properly!" << std::endl; + } } printer::info P700Printer::getInfo() { - return printer::info{}; + return printer::info{}; } + bool P700Printer::printText(std::string_view text, uint32_t fontSize) { - return false; + return false; } bool P700Printer::printBitmap(std::shared_ptr bm) { - return false; + return false; } -} \ No newline at end of file +} // namespace ptprnt::printer \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 40a50f0..b3e7d88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,16 +4,16 @@ #include "IPrinter.hpp" #include "P700Printer.hpp" +#include using namespace ptprnt; int main(int argc, char** argv) { - std::cout << "Hello ptprnt!" << std::endl; + std::cout << "Hello ptprnt!" << std::endl; + libusb_init(NULL); + auto driver = std::make_unique(); + auto printer = std::make_unique(std::move(driver)); + printer::info info = printer->getInfo(); - auto driver = std::make_unique(); - auto printer = std::make_unique(std::move(driver)); - printer::info info = printer->getInfo(); - - - return 0; + return 0; } \ No newline at end of file