/* ptrnt - print labels on linux Copyright (C) 2023 Moritz Martinius This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include "interface/IPrinterDriver.hpp" #include "interface/IPrinterTypes.hpp" #include "libusbwrap/LibUsbTypes.hpp" #include "libusbwrap/interface/IUsbDevice.hpp" #pragma once namespace ptprnt::printer { constexpr uint8_t MAX_TRIES_GET_STATUS = 10; class P700Printer : public ::ptprnt::IPrinterDriver { public: P700Printer() = default; ~P700Printer(); // delete copy ctor and assignment P700Printer(const P700Printer&) = default; P700Printer& operator=(const P700Printer&) = default; P700Printer(P700Printer&&) = default; P700Printer& operator=(P700Printer&&) = default; // Printer info has to be static to be accessed without instantiation static const PrinterInfo mInfo; // IPrinterDriver [[nodiscard]] const std::string_view getDriverName() override; [[nodiscard]] const std::string_view getName() override; [[nodiscard]] const libusbwrap::usbId getUsbId() override; [[nodiscard]] const std::string_view getVersion() override; [[nodiscard]] const PrinterInfo getPrinterInfo() override; [[nodiscard]] const PrinterStatus getPrinterStatus() override; bool attachUsbDevice(std::shared_ptr usbHndl) 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& bitmap) override; bool print() override; private: bool send(std::vector& data); bool init(); std::shared_ptr mUsbHndl{nullptr}; std::map> 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