commands restructured to be const vectors
Some checks failed
Build ptprnt / build (push) Failing after 1m1s
Some checks failed
Build ptprnt / build (push) Failing after 1m1s
This commit is contained in:
@@ -41,7 +41,7 @@ BreakBeforeBinaryOperators: None
|
|||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
BreakInheritanceList: BeforeColon
|
BreakInheritanceList: BeforeColon
|
||||||
ColumnLimit: 100
|
ColumnLimit: 120
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
|
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@@ -85,6 +85,9 @@
|
|||||||
},
|
},
|
||||||
"clang-tidy.buildPath": "builddir/",
|
"clang-tidy.buildPath": "builddir/",
|
||||||
"clangd.onConfigChanged": "restart",
|
"clangd.onConfigChanged": "restart",
|
||||||
"C_Cpp.default.compileCommands": "/home/moritz/Projekte/ptouch-prnt/builddir/compile_commands.json",
|
"C_Cpp.default.compileCommands": "/home/moritz/src/ptouch-prnt/builddir/compile_commands.json",
|
||||||
"gcovViewer.buildDirectories": ["/home/moritz/Projekte/ptouch-prnt/builddir"]
|
"gcovViewer.buildDirectories": [
|
||||||
|
"/home/moritz/Projekte/ptouch-prnt/builddir"
|
||||||
|
],
|
||||||
|
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild"
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
project('ptprnt', 'cpp',
|
project('ptprnt', 'cpp',
|
||||||
version: 'v0.1.0-'+run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip(),
|
version: 'v0.1.0-'+run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip(),
|
||||||
license: 'GPLv3',
|
license: 'GPLv3',
|
||||||
default_options : ['c_std=c11', 'cpp_std=c++17', 'b_sanitize=none', 'b_lto=true', 'b_lto_mode=thin', 'b_thinlto_cache=true']
|
default_options : ['c_std=c11', 'cpp_std=c++20', 'b_sanitize=none', 'b_lto=true', 'b_lto_mode=thin', 'b_thinlto_cache=true']
|
||||||
)
|
)
|
||||||
|
|
||||||
usb_dep = dependency('libusb-1.0')
|
usb_dep = dependency('libusb-1.0')
|
||||||
|
@@ -37,7 +37,7 @@
|
|||||||
#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 {
|
||||||
|
|
||||||
@@ -66,15 +66,14 @@ const PrinterInfo P700Printer::getPrinterInfo() {
|
|||||||
|
|
||||||
const PrinterStatus P700Printer::getPrinterStatus() {
|
const PrinterStatus P700Printer::getPrinterStatus() {
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
std::vector<uint8_t> getStatusCmd({0x1b, 0x69, 0x53}); // status info request
|
send(p700::commands::GET_STATUS);
|
||||||
send(getStatusCmd);
|
|
||||||
|
|
||||||
int tx = 0;
|
int tx = 0;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
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(commands["printerinfo"][0], recvBuf, &tx, 0);
|
mUsbHndl->bulkTransfer(p700::commands::INFO[0], recvBuf, &tx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
||||||
@@ -131,7 +130,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
send(commands["rasterstart"]);
|
send(p700::commands::RASTER_START);
|
||||||
std::vector<uint8_t> rastercmd(4);
|
std::vector<uint8_t> rastercmd(4);
|
||||||
rastercmd[0] = 0x47;
|
rastercmd[0] = 0x47;
|
||||||
rastercmd[1] = 0x00; // size +1
|
rastercmd[1] = 0x00; // size +1
|
||||||
@@ -158,18 +157,18 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
send(commands["eject"]);
|
send(p700::commands::EJECT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P700Printer::printText(const std::string& text, uint16_t fontSize) {
|
bool P700Printer::printText(const std::string& text, uint16_t fontSize) {
|
||||||
send(commands["lf"]);
|
send(p700::commands::LF);
|
||||||
send(commands["ff"]);
|
send(p700::commands::FF);
|
||||||
send(commands["eject"]);
|
send(p700::commands::EJECT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P700Printer::send(std::vector<uint8_t>& data) {
|
bool P700Printer::send(const std::vector<uint8_t>& data) {
|
||||||
|
|
||||||
if (mUsbHndl == nullptr || data.size() > 128) {
|
if (mUsbHndl == nullptr || data.size() > 128) {
|
||||||
spdlog::error("Invalid device handle or invalid data.");
|
spdlog::error("Invalid device handle or invalid data.");
|
||||||
@@ -189,8 +188,7 @@ bool P700Printer::send(std::vector<uint8_t>& data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tx != static_cast<int>(data.size())) {
|
if (tx != static_cast<int>(data.size())) {
|
||||||
spdlog::error("Could not transfer all data via USB bulk transfer. Only sent {} of {} bytes",
|
spdlog::error("Could not transfer all data via USB bulk transfer. Only sent {} of {} bytes", tx, data.size());
|
||||||
tx, data.size());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,13 +31,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace ptprnt::printer {
|
namespace ptprnt::printer {
|
||||||
|
namespace p700::commands {
|
||||||
|
const cmd_T GET_STATUS{0x1b, 0x69, 0x53};
|
||||||
|
const cmd_T RASTER_START{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
const cmd_T INFO{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
const cmd_T PACKBITSON{0x02};
|
||||||
|
const cmd_T LF{0x5a};
|
||||||
|
const cmd_T FF{0x0c};
|
||||||
|
const cmd_T EJECT{0x1a};
|
||||||
|
const cmd_T PRINTER_INFO{0x81};
|
||||||
|
} // namespace p700::commands
|
||||||
|
|
||||||
constexpr uint8_t MAX_TRIES_GET_STATUS = 10;
|
constexpr uint8_t MAX_TRIES_GET_STATUS = 10;
|
||||||
|
|
||||||
class P700Printer : public ::ptprnt::IPrinterDriver {
|
class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||||
public:
|
public:
|
||||||
P700Printer() = default;
|
P700Printer() = default;
|
||||||
~P700Printer();
|
~P700Printer() override;
|
||||||
|
|
||||||
// delete copy ctor and assignment
|
// delete copy ctor and assignment
|
||||||
P700Printer(const P700Printer&) = default;
|
P700Printer(const P700Printer&) = default;
|
||||||
@@ -59,7 +69,7 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
bool printText(const std::string& text, uint16_t fontSize) override;
|
bool printText(const std::string& text, uint16_t fontSize) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool send(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};
|
||||||
@@ -70,16 +80,6 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
|||||||
.vid = 0x04f9,
|
.vid = 0x04f9,
|
||||||
.pid = 0x2061,
|
.pid = 0x2061,
|
||||||
.pixelLines = 128};
|
.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
|
@@ -113,7 +113,7 @@ int PtouchPrint::run() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
label.writeToPng("salat.png");
|
label.writeToPng("salat.png");
|
||||||
printer->printBitmap(bm);
|
//printer->printBitmap(bm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
|
|
||||||
class IPrinterDriver {
|
class IPrinterDriver {
|
||||||
public:
|
public:
|
||||||
virtual ~IPrinterDriver() = default;
|
virtual ~IPrinterDriver() = default;
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
|
|
||||||
@@ -38,4 +39,6 @@ struct PrinterStatus {
|
|||||||
unsigned int tapeWidthMm = 0.0;
|
unsigned int tapeWidthMm = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using cmd_T = std::vector<uint8_t>;
|
||||||
|
|
||||||
} // namespace ptprnt
|
} // namespace ptprnt
|
Reference in New Issue
Block a user