use new pos printer settings
This commit is contained in:
parent
dc74c59287
commit
f0078647d4
9 changed files with 144 additions and 47 deletions
|
@ -46,8 +46,9 @@ PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(prin
|
|||
|
||||
if (printerDevice_.idVendor == 0) {
|
||||
for (const auto& supported : supportedPrinters_.models) {
|
||||
if (desc.idVendor == supported.first && desc.idProduct == supported.second) {
|
||||
if (desc.idVendor == std::get<0>(supported) && desc.idProduct == std::get<1>(supported)) {
|
||||
numDevice = i;
|
||||
printerEndpoint_ = std::get<2>(supported);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +56,7 @@ PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(prin
|
|||
if (desc.idVendor == printerDevice_.idVendor &&
|
||||
desc.idProduct == printerDevice_.idProduct) {
|
||||
numDevice = i;
|
||||
printerEndpoint_ = printerDevice.endpoint;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +124,7 @@ void PosPrinter::write(const std::string& text)
|
|||
int length = text_escaped.length();
|
||||
int actual{0};
|
||||
int retValue =
|
||||
libusb_bulk_transfer(devicePtr_, (0x03 | LIBUSB_ENDPOINT_OUT),
|
||||
libusb_bulk_transfer(devicePtr_, (printerEndpoint_ | LIBUSB_ENDPOINT_OUT),
|
||||
(unsigned char*)text_escaped.c_str(), length, &actual, 10000);
|
||||
if (retValue != 0 || actual != length)
|
||||
std::cerr << "Write Error" << std::endl;
|
||||
|
|
|
@ -9,16 +9,17 @@
|
|||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
struct SupportedPrinters {
|
||||
std::array<std::pair<int, int>, 2> models{
|
||||
// {Vendor ID, Model ID}
|
||||
std::make_pair(0x0456, 0x0808),
|
||||
std::make_pair(0x0416, 0x5011),
|
||||
std::array<std::tuple<int, int, int>, 2> models{
|
||||
// {Vendor ID, Model ID, Endpoint}
|
||||
std::make_tuple(0x0456, 0x0808, 0x03),
|
||||
std::tuple(0x0416, 0x5011, 0x03),
|
||||
};
|
||||
};
|
||||
|
||||
struct PrinterDevice {
|
||||
int idVendor{};
|
||||
int idProduct{};
|
||||
int endpoint{};
|
||||
};
|
||||
|
||||
class PosPrinter
|
||||
|
@ -50,6 +51,7 @@ class PosPrinter
|
|||
libusb_device_handle* devicePtr_{};
|
||||
SupportedPrinters supportedPrinters_;
|
||||
PrinterDevice printerDevice_{};
|
||||
int printerEndpoint_{0x03};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue