Moved graphics classes into own namespace, added unit testing with gtest

This commit is contained in:
2023-09-23 13:29:54 +02:00
parent 7ab817793d
commit c0811df4bb
18 changed files with 334 additions and 136 deletions

View File

@@ -2,6 +2,7 @@
#include <spdlog/spdlog.h>
#include <array>
#include <chrono>
#include <cstdint>
#include <iostream>
@@ -9,6 +10,7 @@
#include <thread>
#include <vector>
#include "graphics/Image.hpp"
#include "libusb.h"
#include "libusbwrap/LibUsbTypes.hpp"
#include "spdlog/fmt/bin_to_hex.h"
@@ -100,11 +102,35 @@ bool P700Printer::detachUsbDevice() {
return true;
}
bool P700Printer::printBitmap(const Bitmap& bitmap) {
bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) {
auto img = graphics::Image();
//uint8_t* imgRef = img.getRaw();
std::array<uint32_t, 4> line;
send(commands["rasterstart"]);
std::vector<uint8_t> buf(64);
buf[0] = 0x47;
for (int i = 0; i < 8; i++) {
if (i % 2) {
line.fill(0xffffffff);
} else {
line.fill(0x00000000);
}
buf[1] = (uint8_t)(8 + 1);
buf[2] = 0;
buf[3] = (uint8_t)(8 - 1);
memcpy(buf.data() + 4, line.data(), line.size());
send(buf);
}
send(commands["eject"]);
return true;
}
bool P700Printer::printText(const std::string& text, uint16_t fontSize) {
send(commands["lf"]);
send(commands["ff"]);
send(commands["eject"]);
return true;
}
@@ -121,4 +147,11 @@ bool P700Printer::send(std::vector<uint8_t>& data) {
return true;
}
bool P700Printer::init() {
std::vector<uint8_t> cmd(102);
cmd[100] = 0x1b; /* ESC */
cmd[101] = 0x40; /* @ */
return send(cmd);
}
} // namespace ptprnt::printer