cli-parser-cleanup #15
@@ -23,10 +23,10 @@
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "PrinterDriverFactory.hpp"
|
||||
#include "cli/CliParser.hpp"
|
||||
#include "cli/interface/ICliParser.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "core/PrinterDriverFactory.hpp"
|
||||
#include "core/PrinterService.hpp"
|
||||
#include "core/interface/IPrinterService.hpp"
|
||||
#include "graphics/LabelBuilder.hpp"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "PrinterDriverFactory.hpp"
|
||||
#include "core/PrinterDriverFactory.hpp"
|
||||
|
||||
namespace ptprnt::core {
|
||||
|
||||
@@ -38,7 +38,7 @@ bool PrinterService::initialize() {
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> PrinterService::detectPrinters() {
|
||||
spdlog::debug("Detecting printers...");
|
||||
|
||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||
mDetectedPrinters.clear();
|
||||
|
||||
@@ -57,7 +57,7 @@ std::shared_ptr<IPrinterDriver> PrinterService::selectPrinter(const std::string&
|
||||
// If a specific printer is requested by name (not "auto"), try to create it directly
|
||||
if (printerName != "auto") {
|
||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||
auto printer = driverFactory->createByName(printerName);
|
||||
auto printer = driverFactory->createByName(printerName);
|
||||
if (printer) {
|
||||
mCurrentPrinter = printer;
|
||||
spdlog::info("Using explicitly selected printer: {}", printerName);
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../printers/interface/IPrinterDriver.hpp"
|
||||
#include "interface/IPrinterService.hpp"
|
||||
#include "../libusbwrap/UsbDeviceFactory.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
#include "printers/interface/IPrinterDriver.hpp"
|
||||
|
||||
namespace ptprnt::core {
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../../printers/interface/IPrinterDriver.hpp"
|
||||
#include "../../graphics/interface/ILabel.hpp"
|
||||
#include "graphics/interface/ILabel.hpp"
|
||||
#include "printers/interface/IPrinterDriver.hpp"
|
||||
|
||||
namespace ptprnt::core {
|
||||
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
ptprnt_hpps = files (
|
||||
'libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'libusbwrap/interface/IUsbDevice.hpp',
|
||||
'libusbwrap/UsbDeviceFactory.hpp',
|
||||
'libusbwrap/LibUsbTypes.hpp',
|
||||
'libusbwrap/UsbDevice.hpp',
|
||||
'interface/IPrinterDriver.hpp',
|
||||
'interface/IPrinterTypes.hpp',
|
||||
'printers/P700Printer.hpp',
|
||||
'printers/FakePrinter.hpp',
|
||||
'PtouchPrint.hpp',
|
||||
'PrinterDriverFactory.hpp',
|
||||
ptprnt_hpps = files(
|
||||
'cli/CliParser.hpp',
|
||||
'core/PrinterDriverFactory.hpp',
|
||||
'core/PrinterService.hpp',
|
||||
'graphics/Bitmap.hpp',
|
||||
'graphics/Label.hpp',
|
||||
'graphics/LabelBuilder.hpp',
|
||||
'graphics/Monochrome.hpp',
|
||||
'cli/CliParser.hpp',
|
||||
'core/PrinterService.hpp'
|
||||
'libusbwrap/LibUsbTypes.hpp',
|
||||
'libusbwrap/UsbDevice.hpp',
|
||||
'libusbwrap/UsbDeviceFactory.hpp',
|
||||
'libusbwrap/interface/IUsbDevice.hpp',
|
||||
'libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'printers/FakePrinter.hpp',
|
||||
'printers/P700Printer.hpp',
|
||||
'printers/interface/IPrinterDriver.hpp',
|
||||
'printers/interface/IPrinterTypes.hpp',
|
||||
'PtouchPrint.hpp',
|
||||
)
|
||||
|
||||
ptprnt_srcs = files (
|
||||
'PtouchPrint.cpp',
|
||||
'PrinterDriverFactory.cpp',
|
||||
'printers/P700Printer.cpp',
|
||||
'printers/FakePrinter.cpp',
|
||||
ptprnt_srcs = files(
|
||||
'cli/CliParser.cpp',
|
||||
'core/PrinterDriverFactory.cpp',
|
||||
'core/PrinterService.cpp',
|
||||
'graphics/Bitmap.cpp',
|
||||
'graphics/Label.cpp',
|
||||
'graphics/LabelBuilder.cpp',
|
||||
'graphics/Bitmap.cpp',
|
||||
'graphics/Monochrome.cpp',
|
||||
'libusbwrap/UsbDeviceFactory.cpp',
|
||||
'libusbwrap/UsbDevice.cpp',
|
||||
'cli/CliParser.cpp',
|
||||
'core/PrinterService.cpp'
|
||||
'libusbwrap/UsbDeviceFactory.cpp',
|
||||
'printers/FakePrinter.cpp',
|
||||
'printers/P700Printer.cpp',
|
||||
'PtouchPrint.cpp',
|
||||
)
|
||||
@@ -19,27 +19,25 @@
|
||||
|
||||
#include "FakePrinter.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <cairo.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "../graphics/Monochrome.hpp"
|
||||
#include "graphics/Monochrome.hpp"
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
const PrinterInfo FakePrinter::mInfo = {
|
||||
.driverName = "FakePrinter",
|
||||
.name = "Virtual Test Printer",
|
||||
.version = "v1.0",
|
||||
.usbId{0x0000, 0x0000}, // No USB ID - virtual printer created explicitly
|
||||
.pixelLines = 128
|
||||
};
|
||||
const PrinterInfo FakePrinter::mInfo = {.driverName = "FakePrinter",
|
||||
.name = "Virtual Test Printer",
|
||||
.version = "v1.0",
|
||||
.usbId{0x0000, 0x0000}, // No USB ID - virtual printer created explicitly
|
||||
.pixelLines = 128};
|
||||
|
||||
const std::string_view FakePrinter::getDriverName() {
|
||||
return mInfo.driverName;
|
||||
@@ -80,8 +78,8 @@ bool FakePrinter::detachUsbDevice() {
|
||||
|
||||
bool FakePrinter::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) {
|
||||
// Convert bitmap to MonochromeData and delegate
|
||||
auto pixels = bitmap.getPixelsCpy();
|
||||
auto mono = graphics::Monochrome(pixels, bitmap.getWidth(), bitmap.getHeight());
|
||||
auto pixels = bitmap.getPixelsCpy();
|
||||
auto mono = graphics::Monochrome(pixels, bitmap.getWidth(), bitmap.getHeight());
|
||||
auto monoData = mono.get();
|
||||
|
||||
return printMonochromeData(monoData);
|
||||
@@ -92,10 +90,10 @@ bool FakePrinter::printMonochromeData(const graphics::MonochromeData& data) {
|
||||
|
||||
// Simulate the printing process by reconstructing the bitmap
|
||||
auto printed = simulatePrinting(data);
|
||||
mLastPrint = std::make_unique<graphics::Bitmap<graphics::ALPHA8>>(std::move(printed));
|
||||
mLastPrint = std::make_unique<graphics::Bitmap<graphics::ALPHA8>>(std::move(printed));
|
||||
|
||||
spdlog::info("FakePrinter: Successfully 'printed' label ({}x{} pixels)",
|
||||
mLastPrint->getWidth(), mLastPrint->getHeight());
|
||||
spdlog::info("FakePrinter: Successfully 'printed' label ({}x{} pixels)", mLastPrint->getWidth(),
|
||||
mLastPrint->getHeight());
|
||||
|
||||
// Save to timestamped PNG file
|
||||
std::string filename = generateTimestampedFilename();
|
||||
@@ -120,7 +118,8 @@ bool FakePrinter::printLabel(const std::unique_ptr<graphics::ILabel> label) {
|
||||
// Transform to portrait orientation for printing
|
||||
monoData.transformTo(graphics::Orientation::PORTRAIT);
|
||||
|
||||
spdlog::debug("FakePrinter: Label surface is {}x{}, transformed to portrait", label->getWidth(), label->getHeight());
|
||||
spdlog::debug("FakePrinter: Label surface is {}x{}, transformed to portrait", label->getWidth(),
|
||||
label->getHeight());
|
||||
|
||||
return printMonochromeData(monoData);
|
||||
}
|
||||
@@ -160,7 +159,7 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
|
||||
|
||||
// Now "print" this column by unpacking the bytes back to pixels
|
||||
for (size_t byteIdx = 0; byteIdx < columnBytes.size(); byteIdx++) {
|
||||
uint8_t byte = columnBytes[byteIdx];
|
||||
uint8_t byte = columnBytes[byteIdx];
|
||||
uint32_t baseRow = byteIdx * 8;
|
||||
|
||||
for (int bit = 0; bit < 8 && (baseRow + bit) < data.height; bit++) {
|
||||
@@ -168,7 +167,7 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
|
||||
uint32_t row = baseRow + bit;
|
||||
|
||||
// Write to output bitmap
|
||||
size_t pixelIdx = row * data.width + col;
|
||||
size_t pixelIdx = row * data.width + col;
|
||||
pixels[pixelIdx] = pixelOn ? 255 : 0; // 255 = black, 0 = white
|
||||
}
|
||||
}
|
||||
@@ -177,8 +176,8 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
|
||||
// Set the pixels in the result bitmap
|
||||
result.setPixels(pixels);
|
||||
|
||||
spdlog::debug("FakePrinter: Simulation complete, reconstructed {}x{} bitmap",
|
||||
result.getWidth(), result.getHeight());
|
||||
spdlog::debug("FakePrinter: Simulation complete, reconstructed {}x{} bitmap", result.getWidth(),
|
||||
result.getHeight());
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -201,8 +200,8 @@ bool FakePrinter::saveLastPrintToPng(const std::string& filename) const {
|
||||
|
||||
bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitmap, const std::string& filename) const {
|
||||
// Create Cairo surface from bitmap data
|
||||
auto pixels = bitmap.getPixelsCpy();
|
||||
uint16_t width = bitmap.getWidth();
|
||||
auto pixels = bitmap.getPixelsCpy();
|
||||
uint16_t width = bitmap.getWidth();
|
||||
uint16_t height = bitmap.getHeight();
|
||||
|
||||
// Cairo expects ARGB32 format, but we have ALPHA8
|
||||
@@ -217,14 +216,9 @@ bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitm
|
||||
}
|
||||
|
||||
// Create Cairo surface
|
||||
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
||||
cairo_surface_t* surface = cairo_image_surface_create_for_data(
|
||||
reinterpret_cast<unsigned char*>(argbPixels.data()),
|
||||
CAIRO_FORMAT_ARGB32,
|
||||
width,
|
||||
height,
|
||||
stride
|
||||
);
|
||||
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
||||
cairo_surface_t* surface = cairo_image_surface_create_for_data(reinterpret_cast<unsigned char*>(argbPixels.data()),
|
||||
CAIRO_FORMAT_ARGB32, width, height, stride);
|
||||
|
||||
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
|
||||
spdlog::error("FakePrinter: Failed to create Cairo surface: {}",
|
||||
@@ -248,14 +242,12 @@ bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitm
|
||||
|
||||
std::string FakePrinter::generateTimestampedFilename() const {
|
||||
// Get current time
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto time = std::chrono::system_clock::to_time_t(now);
|
||||
|
||||
// Format: fakelabel_YYYYMMDD_HHMMSS.png
|
||||
std::stringstream ss;
|
||||
ss << "fakelabel_"
|
||||
<< std::put_time(std::localtime(&time), "%Y%m%d_%H%M%S")
|
||||
<< ".png";
|
||||
ss << "fakelabel_" << std::put_time(std::localtime(&time), "%Y%m%d_%H%M%S") << ".png";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "interface/IPrinterDriver.hpp"
|
||||
#include "interface/IPrinterTypes.hpp"
|
||||
#include "../libusbwrap/LibUsbTypes.hpp"
|
||||
#include "../libusbwrap/interface/IUsbDevice.hpp"
|
||||
#include "../graphics/Bitmap.hpp"
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace ptprnt::printer {
|
||||
*/
|
||||
class FakePrinter : public ::ptprnt::IPrinterDriver {
|
||||
public:
|
||||
FakePrinter() = default;
|
||||
FakePrinter() = default;
|
||||
~FakePrinter() override = default;
|
||||
|
||||
FakePrinter(const FakePrinter&) = delete;
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "../graphics/Bitmap.hpp"
|
||||
#include "../graphics/Monochrome.hpp"
|
||||
#include "../libusbwrap/LibUsbTypes.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "graphics/Monochrome.hpp"
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
|
||||
#include "interface/IPrinterDriver.hpp"
|
||||
#include "interface/IPrinterTypes.hpp"
|
||||
#include "../libusbwrap/LibUsbTypes.hpp"
|
||||
#include "../libusbwrap/interface/IUsbDevice.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 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};
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include "../../graphics/Bitmap.hpp"
|
||||
#include "../../graphics/Monochrome.hpp"
|
||||
#include "../../graphics/interface/ILabel.hpp"
|
||||
#include "../../libusbwrap/interface/IUsbDevice.hpp"
|
||||
#include "IPrinterTypes.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "graphics/Monochrome.hpp"
|
||||
#include "graphics/interface/ILabel.hpp"
|
||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
class IPrinterDriver {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -35,6 +35,4 @@ foreach test : tests
|
||||
],
|
||||
),
|
||||
)
|
||||
endforeach
|
||||
|
||||
|
||||
endforeach
|
||||
Reference in New Issue
Block a user