2018-08-05 21:51:30 +02:00
|
|
|
#ifndef POS_PRINTER_H
|
|
|
|
#define POS_PRINTER_H
|
|
|
|
|
2018-08-06 16:14:45 +02:00
|
|
|
#include <sale.h>
|
2018-08-06 16:38:55 +02:00
|
|
|
#include <seller.h>
|
2018-08-06 16:14:45 +02:00
|
|
|
|
2018-08-05 21:51:30 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
|
2018-08-15 14:04:56 +02:00
|
|
|
#ifdef DELETE
|
|
|
|
#undef DELETE
|
|
|
|
#endif
|
|
|
|
|
2018-08-06 09:59:06 +02:00
|
|
|
struct SupportedPrinters {
|
2018-08-15 10:51:57 +02:00
|
|
|
std::array<std::tuple<int, int, int>, 2> models{
|
|
|
|
// {Vendor ID, Model ID, Endpoint}
|
|
|
|
std::make_tuple(0x0456, 0x0808, 0x03),
|
2018-08-15 14:07:15 +02:00
|
|
|
std::make_tuple(0x0416, 0x5011, 0x03),
|
2018-08-06 09:59:06 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-08-15 08:02:28 +02:00
|
|
|
struct PrinterDevice {
|
|
|
|
int idVendor{};
|
|
|
|
int idProduct{};
|
2018-08-15 10:51:57 +02:00
|
|
|
int endpoint{};
|
2018-08-15 08:02:28 +02:00
|
|
|
};
|
|
|
|
|
2018-08-05 21:51:30 +02:00
|
|
|
class PosPrinter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PosPrinter();
|
2018-08-15 08:02:28 +02:00
|
|
|
PosPrinter(const PrinterDevice& printerDevice);
|
2018-08-05 21:51:30 +02:00
|
|
|
~PosPrinter();
|
2018-08-06 12:52:45 +02:00
|
|
|
void write(const std::string& text);
|
|
|
|
void printHeader();
|
|
|
|
void printTest();
|
2018-08-06 16:38:55 +02:00
|
|
|
void printSaleReceipt(Sale* sale);
|
2018-08-06 21:24:10 +02:00
|
|
|
void printSellerReceipt(Seller* seller, int percent, int maxFeeInCent);
|
2018-08-06 20:57:12 +02:00
|
|
|
bool isValid();
|
2018-08-06 12:52:45 +02:00
|
|
|
|
|
|
|
struct Command {
|
|
|
|
static const std::string RESET;
|
|
|
|
static const std::string ENCODING;
|
|
|
|
static const std::string CENTERING;
|
2018-08-06 16:14:45 +02:00
|
|
|
static const std::string LEFT_ALIGN;
|
|
|
|
static const std::string RIGHT_ALIGN;
|
2018-08-06 12:52:45 +02:00
|
|
|
static const std::string FONT_SIZE_BIG;
|
|
|
|
static const std::string FONT_SIZE_NORMAL;
|
|
|
|
static const std::string FEED;
|
|
|
|
};
|
2018-08-06 09:59:06 +02:00
|
|
|
|
|
|
|
private:
|
2018-08-05 21:51:30 +02:00
|
|
|
libusb_context* contextPtr_{};
|
|
|
|
libusb_device_handle* devicePtr_{};
|
2018-08-06 09:59:06 +02:00
|
|
|
SupportedPrinters supportedPrinters_;
|
2018-08-15 08:50:46 +02:00
|
|
|
PrinterDevice printerDevice_{};
|
2018-08-15 10:51:57 +02:00
|
|
|
int printerEndpoint_{0x03};
|
2018-08-05 21:51:30 +02:00
|
|
|
};
|
|
|
|
|
2018-08-15 14:04:56 +02:00
|
|
|
#endif
|