diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index 3a63ffd..f7f6bf9 100644 --- a/src/P700Printer.cpp +++ b/src/P700Printer.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -141,7 +140,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap& bitmap) rastercmd[1] = 0x00; // size +1 rastercmd[2] = 0x00; rastercmd[3] = 0x00; // size -1 - for (unsigned int i = 0; i < 8; i++) { + for (unsigned int i = 0; i < bm.getWidth(); i++) { auto bmcol = bm.getCol(i); if (!bmcol) { spdlog::error("Out of bounds bitmap access"); @@ -156,7 +155,9 @@ bool P700Printer::printBitmap(const graphics::Bitmap& bitmap) buf[1] = col.size() + 1; buf[3] = col.size() - 1; - send(buf); + if (!send(buf)) { + break; + }; } send(commands["eject"]); @@ -177,15 +178,24 @@ bool P700Printer::send(std::vector& data) { return false; } + int tx = 0; + #ifndef DRYRUN - if (!mUsbHndl->bulkTransfer(0x02, data, nullptr, 0)) { + if (!mUsbHndl->bulkTransfer(0x02, data, &tx, 0)) { spdlog::error("Error writing command to Printer: {}", mUsbHndl->getLastErrorString()); return false; } #else + tx = data.size(); spdlog::debug("USB raw data(len {}): {}", data.size(), spdlog::to_hex(data)); #endif + if (tx != static_cast(data.size())) { + spdlog::error("Could not transfer all data via USB bulk transfer. Only send {} of {} bytes", + tx, data.size()); + return false; + } + return true; } diff --git a/src/P700Printer.hpp b/src/P700Printer.hpp index 4b54ef1..4154638 100644 --- a/src/P700Printer.hpp +++ b/src/P700Printer.hpp @@ -65,7 +65,9 @@ class P700Printer : public ::ptprnt::IPrinterDriver { .vid = 0x04f9, .pid = 0x2061}; std::map> commands{ - {"rasterstart", {0x1b, 0x69, 0x52, 0x01}}, + {"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}}, diff --git a/src/graphics/Bitmap.cpp b/src/graphics/Bitmap.cpp index 72a2d7f..f646089 100644 --- a/src/graphics/Bitmap.cpp +++ b/src/graphics/Bitmap.cpp @@ -73,11 +73,13 @@ std::optional> Bitmap::getCol(uint16_t col) { // first pixel is always beginning of the col std::vector colPixels(mHeight); - auto it = mPixels.begin() + col; + auto it = std::next(mPixels.begin(), col); for (auto& colElement : colPixels) { + int offset = std::distance(mPixels.begin(), it); + //spdlog::debug("Distance {}: {}", offset, *it); colElement = *it; - it += mWidth; + std::advance(it, mWidth); } return colPixels; diff --git a/src/graphics/Image.cpp b/src/graphics/Image.cpp index bf57153..c28e8c0 100644 --- a/src/graphics/Image.cpp +++ b/src/graphics/Image.cpp @@ -19,29 +19,34 @@ #include "Image.hpp" +#include + #include "pango/pango-font.h" namespace ptprnt::graphics { Image::Image() { - mSurface = cairo_image_surface_create(CAIRO_FORMAT_A1, 512, 128); + mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128); cairo_t* cr = cairo_create(mSurface); mFontDescription = pango_font_description_new(); pango_font_description_set_family(mFontDescription, "sans"); pango_font_description_set_weight(mFontDescription, PANGO_WEIGHT_SEMIBOLD); pango_font_description_set_size(mFontDescription, 60 * PANGO_SCALE); + std::string printThis("Mist 💩"); + mLayout = pango_cairo_create_layout(cr); pango_layout_set_font_description(mLayout, mFontDescription); - pango_layout_set_text(mLayout, "Hello, world", -1); + pango_layout_set_text(mLayout, printThis.c_str(), -1); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_move_to(cr, 10.0, 94.0); + cairo_move_to(cr, 0.0, 94.0); pango_cairo_show_layout_line(cr, pango_layout_get_line(mLayout, 0)); - //cairo_surface_write_to_png(mSurface, "hello.png"); + cairo_surface_write_to_png(mSurface, "hello.png"); } uint8_t* Image::getRaw() { + cairo_surface_flush(mSurface); return cairo_image_surface_get_data(mSurface); }