support specifying pos printer
This commit is contained in:
parent
4cd0b42072
commit
98ba6db5a3
2 changed files with 25 additions and 3 deletions
|
@ -35,16 +35,26 @@ PosPrinter::PosPrinter()
|
|||
libusb_exit(contextPtr_);
|
||||
throw std::runtime_error("Could not receive device list");
|
||||
}
|
||||
|
||||
int numDevice = -1;
|
||||
|
||||
for (int i = 0; i < devCount; ++i) {
|
||||
libusb_device_descriptor desc;
|
||||
libusb_get_device_descriptor(devList[i], &desc);
|
||||
|
||||
if (printerDevice_.idVendor == 0) {
|
||||
for (const auto& supported : supportedPrinters_.models) {
|
||||
if (desc.idVendor == supported.first && desc.idProduct == supported.second) {
|
||||
numDevice = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (desc.idVendor == printerDevice_.idVendor &&
|
||||
desc.idProduct == printerDevice_.idProduct) {
|
||||
numDevice = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numDevice < 0) {
|
||||
|
@ -75,6 +85,11 @@ PosPrinter::PosPrinter()
|
|||
libusb_free_device_list(devList, 1);
|
||||
}
|
||||
|
||||
PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_{printerDevice}
|
||||
{
|
||||
PosPrinter();
|
||||
}
|
||||
|
||||
PosPrinter::~PosPrinter()
|
||||
{
|
||||
if (devicePtr_) {
|
||||
|
|
|
@ -16,10 +16,16 @@ struct SupportedPrinters {
|
|||
};
|
||||
};
|
||||
|
||||
struct PrinterDevice {
|
||||
int idVendor{};
|
||||
int idProduct{};
|
||||
};
|
||||
|
||||
class PosPrinter
|
||||
{
|
||||
public:
|
||||
PosPrinter();
|
||||
PosPrinter(const PrinterDevice& printerDevice);
|
||||
~PosPrinter();
|
||||
void write(const std::string& text);
|
||||
void printHeader();
|
||||
|
@ -43,6 +49,7 @@ class PosPrinter
|
|||
libusb_context* contextPtr_{};
|
||||
libusb_device_handle* devicePtr_{};
|
||||
SupportedPrinters supportedPrinters_;
|
||||
PrinterDevice printerDevice_;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue