Simplified driver interface and moved application logic to a seperate application class
This commit is contained in:
44
src/PtouchPrint.cpp
Normal file
44
src/PtouchPrint.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "P700Printer.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
PtouchPrint::PtouchPrint() {}
|
||||
|
||||
PtouchPrint::~PtouchPrint() {}
|
||||
|
||||
void PtouchPrint::init() {
|
||||
mUsbDeviceFactory.init();
|
||||
mCompatiblePrinters = {std::make_shared<ptprnt::printer::P700Printer>()};
|
||||
}
|
||||
|
||||
void PtouchPrint::run() {
|
||||
if (getCompatiblePrinters() == 0) {
|
||||
spdlog::error(
|
||||
"No compatible printers found, please make sure if they are turned on and connected");
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int PtouchPrint::getCompatiblePrinters() {
|
||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||
|
||||
for (auto usbDev : usbDevs) {
|
||||
auto foundPrinterIt =
|
||||
std::find_if(mCompatiblePrinters.begin(), mCompatiblePrinters.end(),
|
||||
[usbDev](const std::shared_ptr<ptprnt::IPrinterDriver>& printer) {
|
||||
return printer->getPid() == usbDev->getPid() &&
|
||||
printer->getVid() == usbDev->getVid();
|
||||
});
|
||||
if (foundPrinterIt == mCompatiblePrinters.end()) {
|
||||
continue;
|
||||
}
|
||||
auto foundPrinter = *foundPrinterIt;
|
||||
spdlog::info("Found Printer {}", foundPrinter->getName());
|
||||
mDetectedPrinters.push_back(foundPrinter);
|
||||
}
|
||||
// we can delete all instantiated printers that are not compatible
|
||||
mCompatiblePrinters.clear();
|
||||
return mDetectedPrinters.size();
|
||||
}
|
Reference in New Issue
Block a user