diff --git a/.gitignore b/.gitignore index 1a673be..2298a4a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build/ .cache/ .vscode/* !.vscode/c_cpp_properties.json -!.vscode/settings.json \ No newline at end of file +!.vscode/settings.json +!.vscode/launch.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..de2a0ca --- /dev/null +++ b/.vscode/launch.json @@ -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}/build/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 + } + ] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index af8b1c7..2279a87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,21 @@ cmake_minimum_required(VERSION 3.5) -project(ptouch-prnt) +project(ptprnt LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" CACHE STRING "Set C++ Compiler Flags" FORCE) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "Set C++ Compiler Flags" FORCE) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + set(SOURCES - src/main.cpp + src/P700Printer.cpp + src/P700Driver.cpp + src/main.cpp ) -add_executable(ptouch-prnt ${SOURCES}) +add_executable(${PROJECT_NAME} ${SOURCES}) -target_include_directories(ptouch-prnt - PRIVATE - ${PROJECT_SOURCE_DIR/inc} +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 new file mode 100644 index 0000000..80706f4 --- /dev/null +++ b/inc/Bitmap.hpp @@ -0,0 +1,11 @@ +#include + +#pragma once + +namespace ptprnt::bitmap { + +struct Bitmap { + std::vector> map; +}; + +} \ No newline at end of file diff --git a/inc/DriverTypes.hpp b/inc/DriverTypes.hpp new file mode 100644 index 0000000..bde447f --- /dev/null +++ b/inc/DriverTypes.hpp @@ -0,0 +1,12 @@ +#include + +#pragma once + +namespace ptprnt::driver { + +struct info { + std::string name{""}; + std::string version{""}; +}; + +} \ No newline at end of file diff --git a/inc/IDriver.hpp b/inc/IDriver.hpp new file mode 100644 index 0000000..f90aa12 --- /dev/null +++ b/inc/IDriver.hpp @@ -0,0 +1,47 @@ + +#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; + +}; + +} \ No newline at end of file diff --git a/inc/IPrinter.hpp b/inc/IPrinter.hpp new file mode 100644 index 0000000..d3eaa68 --- /dev/null +++ b/inc/IPrinter.hpp @@ -0,0 +1,44 @@ + +#include "PrinterTypes.hpp" + +#include + +#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 bm) = 0; +}; + +} \ No newline at end of file diff --git a/inc/P700Driver.hpp b/inc/P700Driver.hpp new file mode 100644 index 0000000..6403e23 --- /dev/null +++ b/inc/P700Driver.hpp @@ -0,0 +1,21 @@ + +#include "IDriver.hpp" +#include + +#pragma once + +namespace ptprnt::driver { + +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; +}; + +} \ No newline at end of file diff --git a/inc/P700Printer.hpp b/inc/P700Printer.hpp new file mode 100644 index 0000000..5540704 --- /dev/null +++ b/inc/P700Printer.hpp @@ -0,0 +1,26 @@ +#include "IPrinter.hpp" + +#include + +#include "P700Driver.hpp" + +#pragma once + +namespace ptprnt::printer { + +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; + +private: + static info mPrinterInfo; + std::unique_ptr mDriver; +}; + +} \ No newline at end of file diff --git a/inc/PrinterTypes.hpp b/inc/PrinterTypes.hpp new file mode 100644 index 0000000..ce46a4a --- /dev/null +++ b/inc/PrinterTypes.hpp @@ -0,0 +1,21 @@ +#include + +#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}; +}; + +} \ No newline at end of file diff --git a/src/P700Driver.cpp b/src/P700Driver.cpp new file mode 100644 index 0000000..bd9d548 --- /dev/null +++ b/src/P700Driver.cpp @@ -0,0 +1,32 @@ +#include "P700Driver.hpp" + +#include +#include + +namespace ptprnt::driver { + +P700Driver::P700Driver(uint16_t UsbDevVendor, uint16_t UsbDevId) { + +} + +P700Driver::~P700Driver() { + +} + +driver::info P700Driver::getInfo() { + return driver::info{}; +} + +bool P700Driver::open() { + return false; +} + +bool P700Driver::close() { + return false; +} + +bool P700Driver::command() { + return false; +} + +} \ No newline at end of file diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp new file mode 100644 index 0000000..dbd4cf1 --- /dev/null +++ b/src/P700Printer.cpp @@ -0,0 +1,31 @@ +#include "P700Printer.hpp" + +#include +#include + +namespace ptprnt::printer { + +P700Printer::P700Printer(std::unique_ptr 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 bm) { + return false; +} + +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8063fb9..40a50f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,19 @@ #include +#include +#include "IPrinter.hpp" +#include "P700Printer.hpp" + +using namespace ptprnt; int main(int argc, char** argv) { - std::cout << "Hello World!" << std::endl; + std::cout << "Hello ptprnt!" << std::endl; + + auto driver = std::make_unique(); + auto printer = std::make_unique(std::move(driver)); + printer::info info = printer->getInfo(); + return 0; } \ No newline at end of file