commands restructured to be const vectors

This commit is contained in:
2024-04-20 12:03:20 +02:00
parent 5a38600e2a
commit 6857de7b1f
8 changed files with 46 additions and 32 deletions

View File

@@ -37,7 +37,7 @@
#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 {
@@ -71,15 +71,14 @@ const PrinterInfo P700Printer::getPrinterInfo() {
const PrinterStatus P700Printer::getPrinterStatus() {
using namespace std::chrono_literals;
std::vector<uint8_t> getStatusCmd({0x1b, 0x69, 0x53}); // status info request
send(getStatusCmd);
send(p700::commands::GET_STATUS);
int tx = 0;
int tries = 0;
std::vector<uint8_t> recvBuf(32);
while (tries++ < MAX_TRIES_GET_STATUS) {
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]};
@@ -132,7 +131,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
}
#endif
send(commands["rasterstart"]);
send(p700::commands::RASTER_START);
std::vector<uint8_t> rastercmd(4);
rastercmd[0] = 0x47;
rastercmd[1] = 0x00; // size +1
@@ -159,7 +158,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
};
}
send(commands["eject"]);
send(p700::commands::EJECT);
return true;
}
@@ -184,13 +183,13 @@ bool P700Printer::setVAlign(VAlignPosition vpos) {
}
bool P700Printer::print() {
send(commands["lf"]);
send(commands["ff"]);
send(commands["eject"]);
send(p700::commands::LF);
send(p700::commands::FF);
send(p700::commands::EJECT);
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) {
spdlog::error("Invalid device handle or invalid data.");
@@ -210,8 +209,7 @@ bool P700Printer::send(std::vector<uint8_t>& data) {
#endif
if (tx != static_cast<int>(data.size())) {
spdlog::error("Could not transfer all data via USB bulk transfer. Only sent {} of {} bytes",
tx, data.size());
spdlog::error("Could not transfer all data via USB bulk transfer. Only sent {} of {} bytes", tx, data.size());
return false;
}