kima2/src/printer/posprinter.h

63 lines
1.6 KiB
C
Raw Normal View History

2018-08-05 21:51:30 +02:00
#ifndef POS_PRINTER_H
#define POS_PRINTER_H
2019-10-10 08:09:16 +02:00
#include <core/sale.h>
#include <core/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>
#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(const std::string& commune = "Musterhausen");
2018-08-06 12:52:45 +02:00
void printTest();
void printSaleReceipt(Sale* sale, const std::string& commune = "Dettingen");
2019-10-07 14:08:01 +02:00
void printSellerReceipt(Seller* seller, const int percent, const int maxFeeInCent,
const std::string& commune = "Dettingen");
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
};
#endif