Fix issues after rebase
This commit is contained in:
@@ -19,32 +19,28 @@
|
||||
|
||||
#include "P700Printer.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ratio>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#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();
|
||||
|
@@ -20,7 +20,6 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -81,22 +80,5 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||
bool init();
|
||||
|
||||
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
|
@@ -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<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters(
|
||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers{};
|
||||
|
||||
for (auto usbDev : usbDevs) {
|
||||
for (auto& usbDev : usbDevs) {
|
||||
auto driver = driverFactory->create(usbDev->getUsbId());
|
||||
if (driver != nullptr) {
|
||||
foundPrinterDrivers.push_back(driver);
|
||||
|
@@ -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<uint8_t>& data, int* tx,
|
||||
unsigned int timeout) {
|
||||
bool UsbDevice::bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& 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<unsigned char*>(data.data()),
|
||||
data.size(), tx, timeout);
|
||||
if (bulkTransferStatus != 0) {
|
||||
mLastError = static_cast<Error>(bulkTransferStatus);
|
||||
return false;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#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<uint8_t>& data, int* tx,
|
||||
unsigned int timeout) override;
|
||||
bool bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) override;
|
||||
|
||||
// getters
|
||||
const usbId getUsbId() override;
|
||||
|
@@ -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<uint8_t>& 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<uint8_t>& data, int* tx, unsigned int timeout) = 0;
|
||||
|
||||
// getters
|
||||
virtual const usbId getUsbId() = 0;
|
||||
|
Reference in New Issue
Block a user