Re-structured project
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
#include <vector>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::bitmap {
|
||||
|
||||
struct Bitmap {
|
||||
std::vector<std::vector<int>> map;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::bitmap
|
@@ -1,14 +0,0 @@
|
||||
#include <string>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
struct info {
|
||||
std::string name{""};
|
||||
std::string version{""};
|
||||
uint32_t busNo{0};
|
||||
uint32_t flags{0};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -1,44 +0,0 @@
|
||||
|
||||
#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
|
@@ -1,43 +0,0 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include "Bitmap.hpp"
|
||||
#include "PrinterTypes.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
|
19
inc/IUsb.hpp
19
inc/IUsb.hpp
@@ -1,19 +0,0 @@
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "UsbTypes.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
class IUsb {
|
||||
public:
|
||||
virtual ~IUsb() = default;
|
||||
|
||||
virtual std::optional<std::vector<UsbDevice>> getDevices() = 0;
|
||||
virtual std::optional<UsbDevice> open(UsbDevice) = 0;
|
||||
virtual bool close(UsbDevice) = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -1,29 +0,0 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "IDriver.hpp"
|
||||
#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};
|
||||
driver::info mInfo{};
|
||||
|
||||
bool init();
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -1,24 +0,0 @@
|
||||
#include <memory>
|
||||
|
||||
#include "IPrinter.hpp"
|
||||
#include "P700Driver.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
class P700Printer : public IPrinter {
|
||||
public:
|
||||
P700Printer(std::shared_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::shared_ptr<driver::P700Driver> mDriver;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::printer
|
@@ -1,21 +0,0 @@
|
||||
#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
|
@@ -1,24 +0,0 @@
|
||||
#include <memory>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
struct libusb_device_list_ptr_deleter {
|
||||
void operator()(libusb_device** usbdevicelistptr) {
|
||||
libusb_free_device_list(usbdevicelistptr, 1);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<libusb_device**, libusb_device_list_ptr_deleter> libusb_device_list_ptr;
|
||||
|
||||
struct UsbDevice {
|
||||
uint16_t vendorId{0};
|
||||
uint16_t productId{0};
|
||||
libusb_device* device{nullptr};
|
||||
libusb_device_handle* hndl{nullptr};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::driver
|
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
namespace libusbwrap {
|
||||
enum class Error {
|
||||
SUCCESS = LIBUSB_SUCCESS,
|
||||
IO = LIBUSB_ERROR_IO,
|
||||
INVALID_PARAM = LIBUSB_ERROR_INVALID_PARAM,
|
||||
ACCESS = LIBUSB_ERROR_ACCESS,
|
||||
NO_DEVICE = LIBUSB_ERROR_NO_DEVICE,
|
||||
NOT_FOUND = LIBUSB_ERROR_NOT_FOUND,
|
||||
BUSY = LIBUSB_ERROR_BUSY,
|
||||
TIMEOUT = LIBUSB_ERROR_TIMEOUT,
|
||||
OVERFLOW = LIBUSB_ERROR_OVERFLOW,
|
||||
PIPE = LIBUSB_ERROR_PIPE,
|
||||
INTERRUPTED = LIBUSB_ERROR_INTERRUPTED,
|
||||
NO_MEM = LIBUSB_ERROR_NO_MEM,
|
||||
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
||||
OTHER = LIBUSB_ERROR_OTHER
|
||||
};
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "libusbwrap/interface/IUsbDeviceFactory.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
public:
|
||||
UsbDeviceFactory();
|
||||
~UsbDeviceFactory();
|
||||
bool init();
|
||||
/**
|
||||
* @brief Gets all devices that are detected by libusb. Will allocate a shared_ptr for each Device
|
||||
*
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of all detected USB devices
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() override;
|
||||
/**
|
||||
* @brief Gets all devices with certain vid/pid combination.
|
||||
* If only one device of certain type is connected, vector is usually only one element
|
||||
*
|
||||
* @param vid VendorId of the devices to find
|
||||
* @param pid ProductId of the devices to find
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of detected USB devices based on vid/pid
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) override;
|
||||
|
||||
private:
|
||||
// methods
|
||||
int refreshDeviceList();
|
||||
// members
|
||||
libusb_context* mLibusbCtx{nullptr};
|
||||
libusb_device** mLibusbDeviceList;
|
||||
};
|
||||
} // namespace libusbwrap
|
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "libusb.h"
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
namespace device {
|
||||
enum class Speed {
|
||||
UNKNOWN = LIBUSB_SPEED_UNKNOWN,
|
||||
LOW = LIBUSB_SPEED_LOW,
|
||||
FULL = LIBUSB_SPEED_FULL,
|
||||
HIGH = LIBUSB_SPEED_HIGH,
|
||||
SUPER = LIBUSB_SPEED_SUPER,
|
||||
SUPER_PLUS = LIBUSB_SPEED_SUPER_PLUS
|
||||
};
|
||||
} // namespace device
|
||||
|
||||
class IUsbDevice {
|
||||
public:
|
||||
virtual Error open() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
// getters
|
||||
virtual uint16_t getVid() = 0;
|
||||
virtual uint16_t getPid() = 0;
|
||||
virtual device::Speed getSpeed() = 0;
|
||||
virtual uint8_t getBusNumber() = 0;
|
||||
virtual uint8_t getPortNumber() = 0;
|
||||
};
|
||||
} // namespace libusbwrap
|
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
class IUsbDeviceFactory {
|
||||
public:
|
||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
||||
};
|
||||
} // namespace libusbwrap
|
Reference in New Issue
Block a user