Sketching some basic interfaces
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ build/
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
!.vscode/settings.json
|
||||
!.vscode/launch.json
|
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}/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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -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/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
|
||||
)
|
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;
|
||||
};
|
||||
|
||||
}
|
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{""};
|
||||
};
|
||||
|
||||
}
|
47
inc/IDriver.hpp
Normal file
47
inc/IDriver.hpp
Normal file
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
}
|
44
inc/IPrinter.hpp
Normal file
44
inc/IPrinter.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
21
inc/P700Driver.hpp
Normal file
21
inc/P700Driver.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
#include "IDriver.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
26
inc/P700Printer.hpp
Normal file
26
inc/P700Printer.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
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};
|
||||
};
|
||||
|
||||
}
|
32
src/P700Driver.cpp
Normal file
32
src/P700Driver.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "P700Driver.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
31
src/P700Printer.cpp
Normal file
31
src/P700Printer.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "P700Printer.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
12
src/main.cpp
12
src/main.cpp
@@ -1,9 +1,19 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#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<driver::P700Driver>();
|
||||
auto printer = std::make_unique<printer::P700Printer>(std::move(driver));
|
||||
printer::info info = printer->getInfo();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user