diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index 0ab0688..7efa210 100644 --- a/src/P700Printer.cpp +++ b/src/P700Printer.cpp @@ -19,32 +19,28 @@ #include "P700Printer.hpp" -#include #include #include -#include #include -#include #include #include #include "graphics/Bitmap.hpp" -#include "graphics/Label.hpp" #include "graphics/Monochrome.hpp" -#include "libusb.h" #include "libusbwrap/LibUsbTypes.hpp" #include "spdlog/fmt/bin_to_hex.h" // as long as DRYRUN is defined, no data is actually send to the printer, we need to save some tape ;) -#define DRYRUN +//#define DRYRUN namespace ptprnt::printer { const PrinterInfo P700Printer::mInfo = {.driverName = "P700", .name = "Brother P-touch P700", .version = "v1.0", - .usbId{0x04f9, 0x2061}}; + .usbId{0x04f9, 0x2061}, + .pixelLines = 128}; P700Printer::~P700Printer() { detachUsbDevice(); diff --git a/src/P700Printer.hpp b/src/P700Printer.hpp index 9c1d06e..20b2d66 100644 --- a/src/P700Printer.hpp +++ b/src/P700Printer.hpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -81,22 +80,5 @@ class P700Printer : public ::ptprnt::IPrinterDriver { bool init(); std::shared_ptr mUsbHndl{nullptr}; - - static constexpr PrinterInfo mInfo{.driverName = "P700", - .name = "Brother P-touch P700", - .version = "v1.0", - .vid = 0x04f9, - .pid = 0x2061, - .pixelLines = 128}; - std::map> commands{ - {"rasterstart", - {0x1b, 0x69, 0x61, 0x01}}, // unique for P700, other printers have the 2 byte set to 0x52 instead of 0x61 - {"info", {0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, - {"packbitson", {0x02}}, - {"lf", {0x5a}}, - {"ff", {0x0c}}, - {"eject", {0x1a}}, - {"printerinfo", {0x81}}}; }; - } // namespace ptprnt::printer \ No newline at end of file diff --git a/src/PtouchPrint.cpp b/src/PtouchPrint.cpp index e9d8fa2..0e55db4 100644 --- a/src/PtouchPrint.cpp +++ b/src/PtouchPrint.cpp @@ -125,10 +125,10 @@ int PtouchPrint::run() { break; } } - if (!printer->print()) { + /*if (!printer->print()) { spdlog::error("An error occured while printing"); return -1; - } + }*/ return 0; } @@ -138,7 +138,7 @@ std::vector> PtouchPrint::getCompatiblePrinters( auto driverFactory = std::make_unique(); std::vector> foundPrinterDrivers{}; - for (auto usbDev : usbDevs) { + for (auto& usbDev : usbDevs) { auto driver = driverFactory->create(usbDev->getUsbId()); if (driver != nullptr) { foundPrinterDrivers.push_back(driver); diff --git a/src/libusbwrap/UsbDevice.cpp b/src/libusbwrap/UsbDevice.cpp index 1c74b41..c3c632f 100644 --- a/src/libusbwrap/UsbDevice.cpp +++ b/src/libusbwrap/UsbDevice.cpp @@ -27,8 +27,7 @@ #include "libusbwrap/interface/IUsbDevice.hpp" namespace libusbwrap { -UsbDevice::UsbDevice(libusb_context* ctx, usbDevice_ptr dev) - : mLibusbCtx(ctx), mLibusbDev(std::move(dev)) { +UsbDevice::UsbDevice(libusb_context* ctx, usbDevice_ptr dev) : mLibusbCtx(ctx), mLibusbDev(std::move(dev)) { if (mLibusbCtx == nullptr || mLibusbDev == nullptr) { throw std::invalid_argument("ctx or device are nullptr"); } @@ -91,13 +90,12 @@ bool UsbDevice::releaseInterface(int interfaceNo) { return true; } -bool UsbDevice::bulkTransfer(uint8_t endpoint, std::vector& data, int* tx, - unsigned int timeout) { +bool UsbDevice::bulkTransfer(uint8_t endpoint, const std::vector& data, int* tx, unsigned int timeout) { // TODO: implement error handling for incomplete transactions (tx length != data length) int bulkTransferStatus = 0; - bulkTransferStatus = - libusb_bulk_transfer(mLibusbDevHandle, endpoint, data.data(), data.size(), tx, timeout); + bulkTransferStatus = libusb_bulk_transfer(mLibusbDevHandle, endpoint, const_cast(data.data()), + data.size(), tx, timeout); if (bulkTransferStatus != 0) { mLastError = static_cast(bulkTransferStatus); return false; diff --git a/src/libusbwrap/UsbDevice.hpp b/src/libusbwrap/UsbDevice.hpp index 02d0b25..8daa52a 100644 --- a/src/libusbwrap/UsbDevice.hpp +++ b/src/libusbwrap/UsbDevice.hpp @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include "libusb.h" #include "libusbwrap/LibUsbTypes.hpp" @@ -56,8 +56,7 @@ class UsbDevice : public IUsbDevice { bool detachKernelDriver(int interfaceNo) override; bool claimInterface(int interfaceNo) override; bool releaseInterface(int interfaceNo) override; - bool bulkTransfer(uint8_t endpoint, std::vector& data, int* tx, - unsigned int timeout) override; + bool bulkTransfer(uint8_t endpoint, const std::vector& data, int* tx, unsigned int timeout) override; // getters const usbId getUsbId() override; diff --git a/src/libusbwrap/interface/IUsbDevice.hpp b/src/libusbwrap/interface/IUsbDevice.hpp index e547beb..335e2ca 100644 --- a/src/libusbwrap/interface/IUsbDevice.hpp +++ b/src/libusbwrap/interface/IUsbDevice.hpp @@ -29,11 +29,10 @@ class IUsbDevice { virtual void close() = 0; // libusb wrappers - virtual bool detachKernelDriver(int interfaceNo) = 0; - virtual bool claimInterface(int interfaceNo) = 0; - virtual bool releaseInterface(int interfaceNo) = 0; - virtual bool bulkTransfer(uint8_t endpoint, std::vector& data, int* tx, - unsigned int timeout) = 0; + virtual bool detachKernelDriver(int interfaceNo) = 0; + virtual bool claimInterface(int interfaceNo) = 0; + virtual bool releaseInterface(int interfaceNo) = 0; + virtual bool bulkTransfer(uint8_t endpoint, const std::vector& data, int* tx, unsigned int timeout) = 0; // getters virtual const usbId getUsbId() = 0;