Compare commits
9 Commits
d98399949c
...
35f768d589
| Author | SHA1 | Date | |
|---|---|---|---|
|
35f768d589
|
|||
|
4f5af6722e
|
|||
|
b2971d15dc
|
|||
|
ca4cdc3fd9
|
|||
|
13a308ffa5
|
|||
|
ab9573bee8
|
|||
|
79e533bd6f
|
|||
|
f32079fe46
|
|||
|
3d5b1ae7b6
|
@@ -19,29 +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",
|
|
||||||
.name = "Brother P-touch P700",
|
|
||||||
.version = "v1.0",
|
|
||||||
.usbId{0x04f9, 0x2061},
|
|
||||||
.pixelLines = 128};
|
|
||||||
|
|
||||||
P700Printer::~P700Printer() {
|
P700Printer::~P700Printer() {
|
||||||
detachUsbDevice();
|
detachUsbDevice();
|
||||||
if (mUsbHndl) {
|
if (mUsbHndl) {
|
||||||
@@ -74,14 +73,18 @@ const PrinterStatus P700Printer::getPrinterStatus() {
|
|||||||
std::vector<uint8_t> recvBuf(32);
|
std::vector<uint8_t> recvBuf(32);
|
||||||
while (tries++ < MAX_TRIES_GET_STATUS) {
|
while (tries++ < MAX_TRIES_GET_STATUS) {
|
||||||
std::this_thread::sleep_for(100ms);
|
std::this_thread::sleep_for(100ms);
|
||||||
mUsbHndl->bulkTransfer(p700::commands::PRINTER_INFO[0], recvBuf, &tx, 0);
|
mUsbHndl->bulkTransfer(p700::commands::INFO[0], recvBuf, &tx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
||||||
}
|
}
|
||||||
|
|
||||||
const libusbwrap::usbId P700Printer::getUsbId() {
|
const uint16_t P700Printer::getVid() {
|
||||||
return mInfo.usbId;
|
return mInfo.vid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint16_t P700Printer::getPid() {
|
||||||
|
return mInfo.pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P700Printer::attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) {
|
bool P700Printer::attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) {
|
||||||
@@ -158,27 +161,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P700Printer::setText(const std::string& text) {
|
bool P700Printer::printText(const std::string& text, uint16_t fontSize) {
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool P700Printer::setFont(const std::string& text) {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool P700Printer::setFontSize(uint8_t fontSize) {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool P700Printer::setHAlign(HAlignPosition hpos) {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool P700Printer::setVAlign(VAlignPosition vpos) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool P700Printer::print() {
|
|
||||||
send(p700::commands::LF);
|
send(p700::commands::LF);
|
||||||
send(p700::commands::FF);
|
send(p700::commands::FF);
|
||||||
send(p700::commands::EJECT);
|
send(p700::commands::EJECT);
|
||||||
|
|||||||
@@ -20,12 +20,12 @@
|
|||||||
#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>
|
||||||
|
|
||||||
#include "interface/IPrinterDriver.hpp"
|
#include "interface/IPrinterDriver.hpp"
|
||||||
#include "interface/IPrinterTypes.hpp"
|
#include "interface/IPrinterTypes.hpp"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -55,30 +55,31 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
P700Printer(P700Printer&&) = default;
|
P700Printer(P700Printer&&) = default;
|
||||||
P700Printer& operator=(P700Printer&&) = default;
|
P700Printer& operator=(P700Printer&&) = default;
|
||||||
|
|
||||||
// Printer info has to be static to be accessed without instantiation
|
|
||||||
static const PrinterInfo mInfo;
|
|
||||||
|
|
||||||
// IPrinterDriver
|
// IPrinterDriver
|
||||||
[[nodiscard]] const std::string_view getDriverName() override;
|
const std::string_view getDriverName() override;
|
||||||
[[nodiscard]] const std::string_view getName() override;
|
const std::string_view getName() override;
|
||||||
[[nodiscard]] const libusbwrap::usbId getUsbId() override;
|
const uint16_t getPid() override;
|
||||||
[[nodiscard]] const std::string_view getVersion() override;
|
const uint16_t getVid() override;
|
||||||
[[nodiscard]] const PrinterInfo getPrinterInfo() override;
|
const std::string_view getVersion() override;
|
||||||
[[nodiscard]] const PrinterStatus getPrinterStatus() override;
|
const PrinterInfo getPrinterInfo() override;
|
||||||
|
const PrinterStatus getPrinterStatus() override;
|
||||||
bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) override;
|
bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) override;
|
||||||
bool detachUsbDevice() override;
|
bool detachUsbDevice() override;
|
||||||
bool setText(const std::string& text) override;
|
|
||||||
bool setFont(const std::string& text) override;
|
|
||||||
bool setFontSize(uint8_t fontSize) override;
|
|
||||||
bool setHAlign(HAlignPosition hpos) override;
|
|
||||||
bool setVAlign(VAlignPosition vpos) override;
|
|
||||||
bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) override;
|
bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) override;
|
||||||
bool print() override;
|
bool printText(const std::string& text, uint16_t fontSize) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool send(const std::vector<uint8_t>& data);
|
bool send(const std::vector<uint8_t>& data);
|
||||||
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};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ptprnt::printer
|
} // namespace ptprnt::printer
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#include "PrinterDriverFactory.hpp"
|
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "P700Printer.hpp"
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
|
|
||||||
namespace ptprnt {
|
|
||||||
|
|
||||||
std::shared_ptr<IPrinterDriver> PrinterDriverFactory::create(libusbwrap::usbId id) {
|
|
||||||
|
|
||||||
if (printer::P700Printer::mInfo.usbId == id) {
|
|
||||||
spdlog::info("Found printer P700!");
|
|
||||||
return std::make_shared<printer::P700Printer>();
|
|
||||||
} else {
|
|
||||||
spdlog::trace("{:04x}:{:04x} is not a compatible printer", id.first, id.second);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ptprnt
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
#include "interface/IPrinterDriver.hpp"
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
|
|
||||||
namespace ptprnt {
|
|
||||||
|
|
||||||
class PrinterDriverFactory {
|
|
||||||
public:
|
|
||||||
PrinterDriverFactory() = default;
|
|
||||||
~PrinterDriverFactory() = default;
|
|
||||||
|
|
||||||
PrinterDriverFactory(const PrinterDriverFactory&) = delete;
|
|
||||||
PrinterDriverFactory& operator=(const PrinterDriverFactory&) = delete;
|
|
||||||
PrinterDriverFactory(PrinterDriverFactory&&) = delete;
|
|
||||||
PrinterDriverFactory& operator=(PrinterDriverFactory&&) = delete;
|
|
||||||
|
|
||||||
std::shared_ptr<IPrinterDriver> create(libusbwrap::usbId id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "graphics/Monochrome.hpp"
|
||||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||||
#define SPDLOG_DEBUG_ON
|
#define SPDLOG_DEBUG_ON
|
||||||
#define SPDLOG_TRACE_ON
|
#define SPDLOG_TRACE_ON
|
||||||
@@ -36,7 +38,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "CLI/Option.hpp"
|
#include "CLI/Option.hpp"
|
||||||
#include "PrinterDriverFactory.hpp"
|
#include "P700Printer.hpp"
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "graphics/Label.hpp"
|
#include "graphics/Label.hpp"
|
||||||
@@ -66,27 +68,28 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
spdlog::error("Could not initialize libusb");
|
spdlog::error("Could not initialize libusb");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
mCompatiblePrinters = {std::make_shared<ptprnt::printer::P700Printer>()};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PtouchPrint::run() {
|
int PtouchPrint::run() {
|
||||||
spdlog::info("ptprnt version {}", mVersionString);
|
SPDLOG_DEBUG("ptprnt version {}", mVersionString);
|
||||||
SPDLOG_TRACE("testing trace");
|
SPDLOG_TRACE("testing trace");
|
||||||
mDetectedPrinters = getCompatiblePrinters();
|
auto numFoundPrinters = getCompatiblePrinters();
|
||||||
auto numFoundPrinters = mDetectedPrinters.size();
|
|
||||||
if (numFoundPrinters == 0) {
|
if (numFoundPrinters == 0) {
|
||||||
spdlog::error("No compatible printers found, please make sure that they are turned on and connected");
|
spdlog::error(
|
||||||
|
"No compatible printers found, please make sure that they are turned on and connected");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (numFoundPrinters > 1) {
|
} else if (numFoundPrinters > 1) {
|
||||||
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto printer = mDetectedPrinters[0];
|
auto printer = mCompatiblePrinters[0];
|
||||||
const auto printerUsbId = printer->getUsbId();
|
auto devices = mUsbDeviceFactory.findDevices(printer->getVid(), printer->getPid());
|
||||||
auto devices = mUsbDeviceFactory.findDevices(printerUsbId.first, printerUsbId.second);
|
|
||||||
if (devices.size() != 1) {
|
if (devices.size() != 1) {
|
||||||
spdlog::warn("Found more than one device of the same printer on bus. Currently not supported");
|
spdlog::warn(
|
||||||
|
"Found more than one device of the same printer on bus. Currently not supported");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printer->attachUsbDevice(std::move(devices[0]));
|
printer->attachUsbDevice(std::move(devices[0]));
|
||||||
@@ -99,52 +102,44 @@ int PtouchPrint::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
switch (cmd.first) {
|
SPDLOG_DEBUG("Command: {}", cmd.second);
|
||||||
case CliCmdType::Text:
|
if (cmd.first == CliCmdType::Text) {
|
||||||
spdlog::debug("Setting text to {}", cmd.second);
|
auto label{graphics::Label()};
|
||||||
printer->setText(cmd.second);
|
label.create(cmd.second, printer->getPrinterInfo().pixelLines);
|
||||||
break;
|
auto bm = graphics::Bitmap<graphics::ALPHA8>(label.getLayoutWidth(),
|
||||||
case CliCmdType::Font:;
|
printer->getPrinterInfo().pixelLines);
|
||||||
spdlog::debug("Setting font to {}", cmd.second);
|
if (!bm.setPixels(label.getRaw())) {
|
||||||
printer->setFont(cmd.second);
|
spdlog::error("Non-matching bitmap size");
|
||||||
break;
|
|
||||||
case CliCmdType::FontSize:;
|
|
||||||
spdlog::debug("Setting font size to {}", cmd.second);
|
|
||||||
printer->setFontSize(static_cast<uint8_t>(std::atoi(cmd.second.c_str())));
|
|
||||||
break;
|
|
||||||
case CliCmdType::HAlign:;
|
|
||||||
spdlog::debug("[Not implemented] Setting text horizontal alignment to {}", cmd.second);
|
|
||||||
break;
|
|
||||||
case CliCmdType::VAlign:;
|
|
||||||
spdlog::debug("[Not implemented] Setting text vertical alignment to {}", cmd.second);
|
|
||||||
break;
|
|
||||||
case CliCmdType::None:;
|
|
||||||
[[fallthrough]];
|
|
||||||
default:
|
|
||||||
spdlog::warn("This command is currently not supported.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*if (!printer->print()) {
|
|
||||||
spdlog::error("An error occured while printing");
|
|
||||||
return -1;
|
return -1;
|
||||||
}*/
|
}
|
||||||
|
label.writeToPng("salat.png");
|
||||||
|
//printer->printBitmap(bm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters() {
|
unsigned int PtouchPrint::getCompatiblePrinters() {
|
||||||
|
|
||||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||||
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());
|
auto foundPrinterIt =
|
||||||
if (driver != nullptr) {
|
std::find_if(mCompatiblePrinters.begin(), mCompatiblePrinters.end(),
|
||||||
foundPrinterDrivers.push_back(driver);
|
[&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);
|
||||||
}
|
}
|
||||||
return foundPrinterDrivers;
|
// we can delete all instantiated printers that are not compatible
|
||||||
|
mCompatiblePrinters.clear();
|
||||||
|
return mDetectedPrinters.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||||
@@ -205,6 +200,7 @@ void PtouchPrint::setupCliParser() {
|
|||||||
->each([this](std::string halign) { mCommands.emplace_back(CliCmdType::HAlign, halign); });
|
->each([this](std::string halign) { mCommands.emplace_back(CliCmdType::HAlign, halign); });
|
||||||
|
|
||||||
// Image options
|
// Image options
|
||||||
mApp.add_option("-i,--image", "Image to print. Excludes all text printing ")->group("Image printing");
|
mApp.add_option("-i,--image", "Image to print. Excludes all text printing ")
|
||||||
|
->group("Image printing");
|
||||||
}
|
}
|
||||||
} // namespace ptprnt
|
} // namespace ptprnt
|
||||||
@@ -49,12 +49,13 @@ class PtouchPrint {
|
|||||||
// methods
|
// methods
|
||||||
void setupLogger(spdlog::level::level_enum lvl);
|
void setupLogger(spdlog::level::level_enum lvl);
|
||||||
void setupCliParser();
|
void setupCliParser();
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> getCompatiblePrinters();
|
unsigned int getCompatiblePrinters();
|
||||||
|
|
||||||
// member variables
|
// member variables
|
||||||
CLI::App mApp{ptprnt::APP_DESC};
|
CLI::App mApp{ptprnt::APP_DESC};
|
||||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
||||||
std::vector<std::shared_ptr<IPrinterDriver>> mDetectedPrinters{};
|
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mCompatiblePrinters{};
|
||||||
|
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mDetectedPrinters{};
|
||||||
std::vector<CliCmd> mCommands{};
|
std::vector<CliCmd> mCommands{};
|
||||||
std::string mVersionString = "";
|
std::string mVersionString = "";
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
@@ -31,21 +30,17 @@ namespace ptprnt {
|
|||||||
class IPrinterDriver {
|
class IPrinterDriver {
|
||||||
public:
|
public:
|
||||||
virtual ~IPrinterDriver() = default;
|
virtual ~IPrinterDriver() = default;
|
||||||
[[nodiscard]] virtual const std::string_view getDriverName() = 0;
|
virtual const std::string_view getDriverName() = 0;
|
||||||
[[nodiscard]] virtual const std::string_view getName() = 0;
|
virtual const std::string_view getName() = 0;
|
||||||
[[nodiscard]] virtual const std::string_view getVersion() = 0;
|
virtual const std::string_view getVersion() = 0;
|
||||||
[[nodiscard]] virtual const libusbwrap::usbId getUsbId() = 0;
|
virtual const uint16_t getVid() = 0;
|
||||||
[[nodiscard]] virtual const PrinterInfo getPrinterInfo() = 0;
|
virtual const uint16_t getPid() = 0;
|
||||||
[[nodiscard]] virtual const PrinterStatus getPrinterStatus() = 0;
|
virtual const PrinterInfo getPrinterInfo() = 0;
|
||||||
|
virtual const PrinterStatus getPrinterStatus() = 0;
|
||||||
virtual bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) = 0;
|
virtual bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) = 0;
|
||||||
virtual bool detachUsbDevice() = 0;
|
virtual bool detachUsbDevice() = 0;
|
||||||
virtual bool setText(const std::string& text) = 0;
|
|
||||||
virtual bool setFont(const std::string& text) = 0;
|
|
||||||
virtual bool setFontSize(uint8_t fontSize) = 0;
|
|
||||||
virtual bool setHAlign(HAlignPosition hpos) = 0;
|
|
||||||
virtual bool setVAlign(VAlignPosition vpos) = 0;
|
|
||||||
virtual bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) = 0;
|
virtual bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) = 0;
|
||||||
virtual bool print() = 0;
|
virtual bool printText(const std::string& text, uint16_t fontSize) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ptprnt
|
} // namespace ptprnt
|
||||||
@@ -20,19 +20,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
|
|
||||||
struct PrinterInfo {
|
struct PrinterInfo {
|
||||||
std::string_view driverName = "";
|
std::string_view driverName = "";
|
||||||
std::string_view name = "";
|
std::string_view name = "";
|
||||||
std::string_view version = "";
|
std::string_view version = "";
|
||||||
libusbwrap::usbId usbId{0x00, 0x00};
|
uint16_t vid = 0x00;
|
||||||
|
uint16_t pid = 0x00;
|
||||||
uint16_t pixelLines = 0;
|
uint16_t pixelLines = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,27 +41,4 @@ struct PrinterStatus {
|
|||||||
|
|
||||||
using cmd_T = std::vector<uint8_t>;
|
using cmd_T = std::vector<uint8_t>;
|
||||||
|
|
||||||
enum class HAlignPosition {
|
|
||||||
UNKNOWN = 0,
|
|
||||||
LEFT = 1,
|
|
||||||
CENTER = 2,
|
|
||||||
RIGHT = 3,
|
|
||||||
JUSTIFY = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class VAlignPosition {
|
|
||||||
UNKNOWN = 0,
|
|
||||||
TOP = 1,
|
|
||||||
MIDDLE = 2,
|
|
||||||
BOTTOM = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PrintableText {
|
|
||||||
std::string text{""};
|
|
||||||
std::string font{"Noto"};
|
|
||||||
uint8_t fontSize{0};
|
|
||||||
HAlignPosition hAlign{HAlignPosition::LEFT};
|
|
||||||
VAlignPosition vAlign{VAlignPosition::MIDDLE};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ptprnt
|
} // namespace ptprnt
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <memory>
|
||||||
|
|
||||||
#include "libusb.h"
|
#include "libusb.h"
|
||||||
|
|
||||||
@@ -40,7 +40,4 @@ enum class Error {
|
|||||||
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
NOT_SUPPORTED = LIBUSB_ERROR_NOT_SUPPORTED,
|
||||||
OTHER = LIBUSB_ERROR_OTHER
|
OTHER = LIBUSB_ERROR_OTHER
|
||||||
};
|
};
|
||||||
|
}
|
||||||
using usbId = std::pair<uint16_t, uint16_t>;
|
|
||||||
|
|
||||||
} // namespace libusbwrap
|
|
||||||
@@ -27,7 +27,8 @@
|
|||||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||||
|
|
||||||
namespace libusbwrap {
|
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) {
|
if (mLibusbCtx == nullptr || mLibusbDev == nullptr) {
|
||||||
throw std::invalid_argument("ctx or device are nullptr");
|
throw std::invalid_argument("ctx or device are nullptr");
|
||||||
}
|
}
|
||||||
@@ -90,12 +91,13 @@ bool UsbDevice::releaseInterface(int interfaceNo) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UsbDevice::bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) {
|
bool UsbDevice::bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
||||||
|
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 = libusb_bulk_transfer(mLibusbDevHandle, endpoint, const_cast<unsigned char*>(data.data()),
|
bulkTransferStatus =
|
||||||
data.size(), tx, timeout);
|
libusb_bulk_transfer(mLibusbDevHandle, endpoint, data.data(), data.size(), tx, timeout);
|
||||||
if (bulkTransferStatus != 0) {
|
if (bulkTransferStatus != 0) {
|
||||||
mLastError = static_cast<Error>(bulkTransferStatus);
|
mLastError = static_cast<Error>(bulkTransferStatus);
|
||||||
return false;
|
return false;
|
||||||
@@ -103,8 +105,12 @@ bool UsbDevice::bulkTransfer(uint8_t endpoint, const std::vector<uint8_t>& data,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usbId UsbDevice::getUsbId() {
|
const uint16_t UsbDevice::getVid() {
|
||||||
return {mLibusbDevDesc.idVendor, mLibusbDevDesc.idProduct};
|
return mLibusbDevDesc.idVendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint16_t UsbDevice::getPid() {
|
||||||
|
return mLibusbDevDesc.idProduct;
|
||||||
}
|
}
|
||||||
|
|
||||||
const device::Speed UsbDevice::getSpeed() {
|
const device::Speed UsbDevice::getSpeed() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "libusb.h"
|
#include "libusb.h"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
#include "libusbwrap/LibUsbTypes.hpp"
|
||||||
@@ -56,10 +56,12 @@ 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, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) override;
|
bool bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
||||||
|
unsigned int timeout) override;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
const usbId getUsbId() override;
|
const uint16_t getVid() override;
|
||||||
|
const uint16_t getPid() override;
|
||||||
const device::Speed getSpeed() override;
|
const device::Speed getSpeed() override;
|
||||||
const uint8_t getBusNumber() override;
|
const uint8_t getBusNumber() override;
|
||||||
const uint8_t getPortNumber() override;
|
const uint8_t getPortNumber() override;
|
||||||
|
|||||||
@@ -32,10 +32,12 @@ 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, const std::vector<uint8_t>& data, int* tx, unsigned int timeout) = 0;
|
virtual bool bulkTransfer(uint8_t endpoint, std::vector<uint8_t>& data, int* tx,
|
||||||
|
unsigned int timeout) = 0;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
virtual const usbId getUsbId() = 0;
|
virtual const uint16_t getVid() = 0;
|
||||||
|
virtual const uint16_t getPid() = 0;
|
||||||
virtual const device::Speed getSpeed() = 0;
|
virtual const device::Speed getSpeed() = 0;
|
||||||
virtual const uint8_t getBusNumber() = 0;
|
virtual const uint8_t getBusNumber() = 0;
|
||||||
virtual const uint8_t getPortNumber() = 0;
|
virtual const uint8_t getPortNumber() = 0;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ ptprnt_hpps = files (
|
|||||||
'interface/IPrinterTypes.hpp',
|
'interface/IPrinterTypes.hpp',
|
||||||
'P700Printer.hpp',
|
'P700Printer.hpp',
|
||||||
'PtouchPrint.hpp',
|
'PtouchPrint.hpp',
|
||||||
'PrinterDriverFactory.hpp',
|
|
||||||
'graphics/Bitmap.hpp',
|
'graphics/Bitmap.hpp',
|
||||||
'graphics/Label.hpp',
|
'graphics/Label.hpp',
|
||||||
'graphics/Monochrome.hpp'
|
'graphics/Monochrome.hpp'
|
||||||
@@ -16,7 +15,6 @@ ptprnt_hpps = files (
|
|||||||
|
|
||||||
ptprnt_srcs = files (
|
ptprnt_srcs = files (
|
||||||
'PtouchPrint.cpp',
|
'PtouchPrint.cpp',
|
||||||
'PrinterDriverFactory.cpp',
|
|
||||||
'P700Printer.cpp',
|
'P700Printer.cpp',
|
||||||
'graphics/Label.cpp',
|
'graphics/Label.cpp',
|
||||||
'graphics/Bitmap.cpp',
|
'graphics/Bitmap.cpp',
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
TEST(basic_test, Label_smokeTest_succeeds) {
|
TEST(basic_test, Label_smokeTest_succeeds) {
|
||||||
auto im = ptprnt::graphics::Label();
|
auto im = ptprnt::graphics::Label();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,14 @@
|
|||||||
tests = [
|
tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']],
|
||||||
[
|
['label_test', 'label_test_exe', ptprnt_srcs +['label_test/label_test.cpp']],
|
||||||
'bitmap_test',
|
['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']]
|
||||||
'bitmap_test_exe',
|
|
||||||
['../src/graphics/Bitmap.cpp', 'bitmap_test/bitmap_test.cpp'],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'label_test',
|
|
||||||
'label_test_exe',
|
|
||||||
['../src/graphics/Label.cpp', 'label_test/label_test.cpp'],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'monochrome_test',
|
|
||||||
'monochrome_test_exe',
|
|
||||||
[
|
|
||||||
'../src/graphics/Monochrome.cpp',
|
|
||||||
'monochrome_test/monochrome_test.cpp',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach test : tests
|
foreach test : tests
|
||||||
test(
|
test(test.get(0),
|
||||||
test.get(0),
|
executable(test.get(1),
|
||||||
executable(
|
|
||||||
test.get(1),
|
|
||||||
sources: test.get(2),
|
sources: test.get(2),
|
||||||
include_directories: incdir,
|
include_directories: incdir,
|
||||||
dependencies: [
|
dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep]
|
||||||
gtest_dep,
|
)
|
||||||
usb_dep,
|
|
||||||
log_dep,
|
|
||||||
pangocairo_dep,
|
|
||||||
cli11_dep,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ TEST(basic_test, Monochrome_convertWithCustomThreshhold_yieldsMonochromeRespecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(basic_test, Monochrome_convertNonAlignedPixels_spillsOverIntoNewByte) {
|
TEST(basic_test, Monochrome_convertNonAlignedPixels_spillsOverIntoNewByte) {
|
||||||
// TODO: We need to find to access the vector without the possiblity of out-of-bounds access
|
|
||||||
// Ideas: constexpr? compile time check?
|
|
||||||
GTEST_SKIP() << "Skipping this test, as ASAN will halt as this is an out-of-bounds access";
|
|
||||||
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
||||||
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF});
|
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user