85 lines
3.0 KiB
C++
85 lines
3.0 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 <spdlog/spdlog.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "interface/IPrinterDriver.hpp"
|
|
#include "interface/IPrinterTypes.hpp"
|
|
#include "libusbwrap/interface/IUsbDevice.hpp"
|
|
|
|
#pragma once
|
|
|
|
namespace ptprnt::printer {
|
|
namespace p700::commands {
|
|
const cmd_T GET_STATUS{0x1b, 0x69, 0x53};
|
|
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;
|
|
|
|
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;
|
|
|
|
// IPrinterDriver
|
|
const std::string_view getDriverName() override;
|
|
const std::string_view getName() override;
|
|
const uint16_t getPid() override;
|
|
const uint16_t getVid() 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(const std::vector<uint8_t>& data);
|
|
bool init();
|
|
|
|
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
|
|
|
static constexpr PrinterInfo mInfo{.driverName = "P700",
|
|
.name = "Brother P-touch P700",
|
|
.version = "v1.0",
|
|
.vid = 0x04f9,
|
|
.pid = 0x2061,
|
|
.pixelLines = 128};
|
|
};
|
|
|
|
} // namespace ptprnt::printer
|