80 lines
2.7 KiB
C++
80 lines
2.7 KiB
C++
/*
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#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
|
|
const std::string_view getDriverName() override;
|
|
const std::string_view getName() override;
|
|
const libusbwrap::usbId getUsbId() override;
|
|
const std::string_view getVersion() override;
|
|
const PrinterInfo getPrinterInfo() override;
|
|
const PrinterStatus getPrinterStatus() override;
|
|
bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) override;
|
|
bool detachUsbDevice() override;
|
|
bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) override;
|
|
bool printText(const std::string& text, uint16_t fontSize) override;
|
|
|
|
private:
|
|
bool send(std::vector<uint8_t>& data);
|
|
bool init();
|
|
|
|
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
|
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
|