Fix issues after rebase
This commit is contained in:
@@ -19,32 +19,28 @@
|
|||||||
|
|
||||||
#include "P700Printer.hpp"
|
#include "P700Printer.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <ratio>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "graphics/Label.hpp"
|
|
||||||
#include "graphics/Monochrome.hpp"
|
#include "graphics/Monochrome.hpp"
|
||||||
#include "libusb.h"
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
#include "libusbwrap/LibUsbTypes.hpp"
|
||||||
#include "spdlog/fmt/bin_to_hex.h"
|
#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 ;)
|
// 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 {
|
namespace ptprnt::printer {
|
||||||
|
|
||||||
const PrinterInfo P700Printer::mInfo = {.driverName = "P700",
|
const PrinterInfo P700Printer::mInfo = {.driverName = "P700",
|
||||||
.name = "Brother P-touch P700",
|
.name = "Brother P-touch P700",
|
||||||
.version = "v1.0",
|
.version = "v1.0",
|
||||||
.usbId{0x04f9, 0x2061}};
|
.usbId{0x04f9, 0x2061},
|
||||||
|
.pixelLines = 128};
|
||||||
|
|
||||||
P700Printer::~P700Printer() {
|
P700Printer::~P700Printer() {
|
||||||
detachUsbDevice();
|
detachUsbDevice();
|
||||||
|
@@ -20,7 +20,6 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -81,22 +80,5 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
||||||
|
|
||||||
static constexpr PrinterInfo mInfo{.driverName = "P700",
|
|
||||||
.name = "Brother P-touch P700",
|
|
||||||
.version = "v1.0",
|
|
||||||
.vid = 0x04f9,
|
|
||||||
.pid = 0x2061,
|
|
||||||
.pixelLines = 128};
|
|
||||||
std::map<std::string, std::vector<uint8_t>> 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
|
} // namespace ptprnt::printer
|
@@ -125,10 +125,10 @@ int PtouchPrint::run() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!printer->print()) {
|
/*if (!printer->print()) {
|
||||||
spdlog::error("An error occured while printing");
|
spdlog::error("An error occured while printing");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ std::vector<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters(
|
|||||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers{};
|
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers{};
|
||||||
|
|
||||||
for (auto usbDev : usbDevs) {
|
for (auto& usbDev : usbDevs) {
|
||||||
auto driver = driverFactory->create(usbDev->getUsbId());
|
auto driver = driverFactory->create(usbDev->getUsbId());
|
||||||
if (driver != nullptr) {
|
if (driver != nullptr) {
|
||||||
foundPrinterDrivers.push_back(driver);
|
foundPrinterDrivers.push_back(driver);
|
||||||
|
@@ -27,8 +27,7 @@
|
|||||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||||
|
|
||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
UsbDevice::UsbDevice(libusb_context* ctx, usbDevice_ptr dev)
|
UsbDevice::UsbDevice(libusb_context* ctx, usbDevice_ptr dev) : mLibusbCtx(ctx), mLibusbDev(std::move(dev)) {
|
||||||
: mLibusbCtx(ctx), mLibusbDev(std::move(dev)) {
|
|
||||||
if (mLibusbCtx == nullptr || mLibusbDev == nullptr) {
|
if (mLibusbCtx == nullptr || mLibusbDev == nullptr) {
|
||||||
throw std::invalid_argument("ctx or device are nullptr");
|
throw std::invalid_argument("ctx or device are nullptr");
|
||||||
}
|
}
|
||||||
@@ -91,13 +90,12 @@ bool UsbDevice::releaseInterface(int interfaceNo) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UsbDevice::bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
bool UsbDevice::bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) {
|
||||||
unsigned int timeout) {
|
|
||||||
// TODO: implement error handling for incomplete transactions (tx length != data length)
|
// TODO: implement error handling for incomplete transactions (tx length != data length)
|
||||||
int bulkTransferStatus = 0;
|
int bulkTransferStatus = 0;
|
||||||
|
|
||||||
bulkTransferStatus =
|
bulkTransferStatus = libusb_bulk_transfer(mLibusbDevHandle, endpoint, const_cast<unsigned char*>(data.data()),
|
||||||
libusb_bulk_transfer(mLibusbDevHandle, endpoint, data.data(), data.size(), tx, timeout);
|
data.size(), tx, timeout);
|
||||||
if (bulkTransferStatus != 0) {
|
if (bulkTransferStatus != 0) {
|
||||||
mLastError = static_cast<Error>(bulkTransferStatus);
|
mLastError = static_cast<Error>(bulkTransferStatus);
|
||||||
return false;
|
return false;
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstddef>
|
#include <memory>
|
||||||
|
|
||||||
#include "libusb.h"
|
#include "libusb.h"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
#include "libusbwrap/LibUsbTypes.hpp"
|
||||||
@@ -56,8 +56,7 @@ class UsbDevice : public IUsbDevice {
|
|||||||
bool detachKernelDriver(int interfaceNo) override;
|
bool detachKernelDriver(int interfaceNo) override;
|
||||||
bool claimInterface(int interfaceNo) override;
|
bool claimInterface(int interfaceNo) override;
|
||||||
bool releaseInterface(int interfaceNo) override;
|
bool releaseInterface(int interfaceNo) override;
|
||||||
bool bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
bool bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) override;
|
||||||
unsigned int timeout) override;
|
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
const usbId getUsbId() override;
|
const usbId getUsbId() override;
|
||||||
|
@@ -32,8 +32,7 @@ class IUsbDevice {
|
|||||||
virtual bool detachKernelDriver(int interfaceNo) = 0;
|
virtual bool detachKernelDriver(int interfaceNo) = 0;
|
||||||
virtual bool claimInterface(int interfaceNo) = 0;
|
virtual bool claimInterface(int interfaceNo) = 0;
|
||||||
virtual bool releaseInterface(int interfaceNo) = 0;
|
virtual bool releaseInterface(int interfaceNo) = 0;
|
||||||
virtual bool bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
virtual bool bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) = 0;
|
||||||
unsigned int timeout) = 0;
|
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
virtual const usbId getUsbId() = 0;
|
virtual const usbId getUsbId() = 0;
|
||||||
|
Reference in New Issue
Block a user