Sketching some basic interfaces

This commit is contained in:
2022-11-01 20:02:47 +01:00
parent c119a02e2f
commit a059df7f67
13 changed files with 295 additions and 9 deletions

11
inc/Bitmap.hpp Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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};
};
}