88 lines
3.3 KiB
C++
88 lines
3.3 KiB
C++
/*
|
|
ptrnt - print labels on linux
|
|
Copyright (C) 2025 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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <spdlog/spdlog.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "interface/IPrinterDriver.hpp"
|
|
#include "interface/IPrinterTypes.hpp"
|
|
#include "libusbwrap/LibUsbTypes.hpp"
|
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
|
|
|
namespace ptprnt::printer {
|
|
namespace p700::commands {
|
|
const cmd_T INITIALIZE{0x1b, 0x40}; // ESC @ - Initialize
|
|
const cmd_T GET_STATUS{0x1b, 0x69, 0x53}; // ESC i S - Status query
|
|
const cmd_T PRINT_MODE{0x4d, 0x02}; // M 0x02 - Print mode
|
|
const cmd_T AUTO_STATUS{0x1b, 0x69, 0x61, 0x01}; // ESC i a - Auto status
|
|
const cmd_T MODE_SETTING{0x1b, 0x69, 0x4d, 0x40}; // ESC i M @ - Advanced mode
|
|
const cmd_T RASTER_START{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
const cmd_T INFO{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
const cmd_T PACKBITSON{0x02};
|
|
const cmd_T LF{0x5a};
|
|
const cmd_T FF{0x0c};
|
|
const cmd_T EJECT{0x1a};
|
|
const cmd_T PRINTER_INFO{0x81};
|
|
} // namespace p700::commands
|
|
|
|
constexpr uint8_t MAX_TRIES_GET_STATUS = 10;
|
|
|
|
// TODO:
|
|
// Remove Text-layout specific parts, add them to label
|
|
|
|
class P700Printer : public ::ptprnt::IPrinterDriver {
|
|
public:
|
|
P700Printer() = default;
|
|
~P700Printer() override;
|
|
|
|
// 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<libusbwrap::IUsbDevice> usbHndl) override;
|
|
bool detachUsbDevice() override;
|
|
bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) override;
|
|
bool printMonochromeData(const graphics::MonochromeData& data) override;
|
|
bool printLabel(const std::unique_ptr<graphics::ILabel> label) override;
|
|
bool print() override;
|
|
|
|
private:
|
|
bool send(const std::vector<uint8_t>& data);
|
|
bool init();
|
|
|
|
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
|
};
|
|
} // namespace ptprnt::printer
|