Compare commits
1 Commits
master
...
1b52fb0458
Author | SHA1 | Date | |
---|---|---|---|
|
1b52fb0458 |
@@ -15,40 +15,13 @@ jobs:
|
||||
run: apt-get -yq install meson
|
||||
- name: Install build dependencies
|
||||
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev gcovr
|
||||
- name: get build environment versions
|
||||
run: |
|
||||
echo "=== Start meson version ==="
|
||||
gcc --version
|
||||
echo "=== End meson version ==="
|
||||
echo "=== Start supported c/cpp standards: ==="
|
||||
gcc -v --help 2> /dev/null | sed -n '/^ *-std=\([^<][^ ]\+\).*/ {s//\1/p}'
|
||||
echo "=== End supported c/cpp standards ==="
|
||||
echo "=== Start meson version ==="
|
||||
meson --version
|
||||
echo "=== End meson version ==="
|
||||
echo "=== Start ninja version ==="
|
||||
ninja --version
|
||||
echo "=== End ninja version ==="
|
||||
echo "=== Start dependency package version ==="
|
||||
apt-cache policy libpango1.0-dev
|
||||
apt-cache policy libcairo2-dev
|
||||
apt-cache policy libfmt-dev
|
||||
apt-cache policy libspdlog-dev
|
||||
apt-cache policy libusb-1.0-0-dev
|
||||
echo "=== End dependency package version ==="
|
||||
- name: setup builddir
|
||||
run: meson setup builddir -Db_coverage=true
|
||||
- name: build and test dist package
|
||||
run: ninja -C builddir dist
|
||||
- name: build all targets
|
||||
run: ninja -C builddir
|
||||
- name: run unit tests
|
||||
run: ninja -C builddir test
|
||||
- name: calculate coverage
|
||||
run: ninja -C builddir coverage-text
|
||||
- name: Coverage report
|
||||
run: cat ./builddir/meson-logs/coverage.txt
|
||||
- name: upload dist package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ptprnt-dist
|
||||
path: ./builddir/meson-dist/*
|
||||
if-no-files-found: error
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,7 +6,6 @@ subprojects/*
|
||||
coverageReport/
|
||||
|
||||
# Files
|
||||
ptprnt.log
|
||||
!subprojects/*.wrap
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
|
19
.vscode/launch.json
vendored
19
.vscode/launch.json
vendored
@@ -6,13 +6,22 @@
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ptprnt_debug",
|
||||
"type": "lldb",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/builddir/ptprnt",
|
||||
"args": [
|
||||
"-t Hello"
|
||||
],
|
||||
"args": ["-t Hello"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -85,6 +85,5 @@
|
||||
},
|
||||
"clang-tidy.buildPath": "builddir/",
|
||||
"clangd.onConfigChanged": "restart",
|
||||
"C_Cpp.default.compileCommands": "/home/moritz/src/ptouch-prnt/builddir/compile_commands.json",
|
||||
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild"
|
||||
"C_Cpp.default.compileCommands": "builddir/compile_commands.json"
|
||||
}
|
||||
|
@@ -160,27 +160,7 @@ bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool P700Printer::setText(const std::string& text) {
|
||||
return true;
|
||||
};
|
||||
|
||||
bool P700Printer::setFont(const std::string& text) {
|
||||
return true;
|
||||
};
|
||||
|
||||
bool P700Printer::setFontSize(uint8_t fontSize) {
|
||||
return true;
|
||||
};
|
||||
|
||||
bool P700Printer::setHAlign(HAlignPosition hpos) {
|
||||
return true;
|
||||
};
|
||||
|
||||
bool P700Printer::setVAlign(VAlignPosition vpos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool P700Printer::print() {
|
||||
bool P700Printer::printText(const std::string& text, uint16_t fontSize) {
|
||||
send(commands["lf"]);
|
||||
send(commands["ff"]);
|
||||
send(commands["eject"]);
|
||||
|
@@ -49,21 +49,16 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||
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;
|
||||
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 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<graphics::ALPHA8>& bitmap) override;
|
||||
bool print() override;
|
||||
bool printText(const std::string& text, uint16_t fontSize) override;
|
||||
|
||||
private:
|
||||
bool send(std::vector<uint8_t>& data);
|
||||
|
@@ -1,23 +1,22 @@
|
||||
#include "PrinterDriverFactory.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "P700Printer.hpp"
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ptprnt {
|
||||
|
||||
std::shared_ptr<IPrinterDriver> PrinterDriverFactory::create(libusbwrap::usbId id) {
|
||||
|
||||
if (printer::P700Printer::mInfo.usbId == id) {
|
||||
spdlog::info("Found printer P700!");
|
||||
return std::make_shared<printer::P700Printer>();
|
||||
} else {
|
||||
spdlog::trace("{:04x}:{:04x} is not a compatible printer", id.first, id.second);
|
||||
}
|
||||
return nullptr;
|
||||
if(printer::P700Printer::mInfo.usbId == id) {
|
||||
spdlog::debug("Printer is P700!");
|
||||
return std::make_shared<printer::P700Printer>();
|
||||
}
|
||||
else {
|
||||
spdlog::debug("{:04x}:{:04x} is not a compatible printer", id.first, id.second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace ptprnt
|
||||
|
||||
}
|
@@ -16,11 +16,12 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
#include <cstdint>
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||
#define SPDLOG_DEBUG_ON
|
||||
#define SPDLOG_TRACE_ON
|
||||
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
#include <CLI/App.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <spdlog/common.h>
|
||||
@@ -37,7 +38,6 @@
|
||||
|
||||
#include "CLI/Option.hpp"
|
||||
#include "PrinterDriverFactory.hpp"
|
||||
#include "PtouchPrint.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
@@ -69,9 +69,9 @@ int PtouchPrint::init(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int PtouchPrint::run() {
|
||||
spdlog::info("ptprnt version {}", mVersionString);
|
||||
spdlog::debug("ptprnt version {}", mVersionString);
|
||||
SPDLOG_TRACE("testing trace");
|
||||
mDetectedPrinters = getCompatiblePrinters();
|
||||
mDetectedPrinters = getCompatiblePrinters();
|
||||
auto numFoundPrinters = mDetectedPrinters.size();
|
||||
if (numFoundPrinters == 0) {
|
||||
spdlog::error(
|
||||
@@ -82,7 +82,7 @@ int PtouchPrint::run() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto printer = mDetectedPrinters[0];
|
||||
auto printer = mDetectedPrinters[0];
|
||||
const auto printerUsbId = printer->getUsbId();
|
||||
auto devices = mUsbDeviceFactory.findDevices(printerUsbId.first, printerUsbId.second);
|
||||
if (devices.size() != 1) {
|
||||
@@ -98,50 +98,21 @@ int PtouchPrint::run() {
|
||||
//printer->printText("wurst", 1);
|
||||
|
||||
for (auto& cmd : mCommands) {
|
||||
switch (cmd.first) {
|
||||
case CliCmdType::Text:
|
||||
spdlog::debug("Setting text to {}", cmd.second);
|
||||
printer->setText(cmd.second);
|
||||
break;
|
||||
case CliCmdType::Font:;
|
||||
spdlog::debug("Setting font to {}", cmd.second);
|
||||
printer->setFont(cmd.second);
|
||||
break;
|
||||
case CliCmdType::FontSize:;
|
||||
spdlog::debug("Setting font size to {}", cmd.second);
|
||||
printer->setFontSize(static_cast<uint8_t>(std::atoi(cmd.second.c_str())));
|
||||
break;
|
||||
case CliCmdType::HAlign:;
|
||||
spdlog::debug("[Not implemented] Setting text horizontal alignment to {}",
|
||||
cmd.second);
|
||||
break;
|
||||
case CliCmdType::VAlign:;
|
||||
spdlog::debug("[Not implemented] Setting text vertical alignment to {}",
|
||||
cmd.second);
|
||||
break;
|
||||
case CliCmdType::None:;
|
||||
[[fallthrough]];
|
||||
default:
|
||||
spdlog::warn("This command is currently not supported.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!printer->print()) {
|
||||
spdlog::error("An error occured while printing");
|
||||
return -1;
|
||||
spdlog::debug("Command: {}", cmd.second);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters() {
|
||||
|
||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||
auto usbDevs = mUsbDeviceFactory.findAllDevices();
|
||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers{};
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> foundPrinterDrivers {};
|
||||
|
||||
for (auto usbDev : usbDevs) {
|
||||
auto driver = driverFactory->create(usbDev->getUsbId());
|
||||
if (driver != nullptr) {
|
||||
if(driver != nullptr) {
|
||||
foundPrinterDrivers.push_back(driver);
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
@@ -32,21 +31,16 @@ namespace ptprnt {
|
||||
class IPrinterDriver {
|
||||
public:
|
||||
virtual ~IPrinterDriver() = default;
|
||||
[[nodiscard]] virtual const std::string_view getDriverName() = 0;
|
||||
[[nodiscard]] virtual const std::string_view getName() = 0;
|
||||
[[nodiscard]] virtual const std::string_view getVersion() = 0;
|
||||
[[nodiscard]] virtual const libusbwrap::usbId getUsbId() = 0;
|
||||
[[nodiscard]] virtual const PrinterInfo getPrinterInfo() = 0;
|
||||
[[nodiscard]] virtual const PrinterStatus getPrinterStatus() = 0;
|
||||
virtual const std::string_view getDriverName() = 0;
|
||||
virtual const std::string_view getName() = 0;
|
||||
virtual const std::string_view getVersion() = 0;
|
||||
virtual const libusbwrap::usbId getUsbId() = 0;
|
||||
virtual const PrinterInfo getPrinterInfo() = 0;
|
||||
virtual const PrinterStatus getPrinterStatus() = 0;
|
||||
virtual bool attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) = 0;
|
||||
virtual bool detachUsbDevice() = 0;
|
||||
virtual bool setText(const std::string& text) = 0;
|
||||
virtual bool setFont(const std::string& text) = 0;
|
||||
virtual bool setFontSize(uint8_t fontSize) = 0;
|
||||
virtual bool setHAlign(HAlignPosition hpos) = 0;
|
||||
virtual bool setVAlign(VAlignPosition vpos) = 0;
|
||||
virtual bool printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) = 0;
|
||||
virtual bool print() = 0;
|
||||
virtual bool printText(const std::string& text, uint16_t fontSize) = 0;
|
||||
};
|
||||
|
||||
} // namespace ptprnt
|
@@ -20,9 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "libusbwrap/LibUsbTypes.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
@@ -31,7 +29,7 @@ struct PrinterInfo {
|
||||
std::string_view driverName = "";
|
||||
std::string_view name = "";
|
||||
std::string_view version = "";
|
||||
libusbwrap::usbId usbId{0x00, 0x00};
|
||||
libusbwrap::usbId usbId {0x00, 0x00};
|
||||
};
|
||||
|
||||
struct PrinterStatus {
|
||||
@@ -39,27 +37,4 @@ struct PrinterStatus {
|
||||
unsigned int tapeWidthMm = 0.0;
|
||||
};
|
||||
|
||||
enum class HAlignPosition {
|
||||
UNKNOWN = 0,
|
||||
LEFT = 1,
|
||||
CENTER = 2,
|
||||
RIGHT = 3,
|
||||
JUSTIFY = 4,
|
||||
};
|
||||
|
||||
enum class VAlignPosition {
|
||||
UNKNOWN = 0,
|
||||
TOP = 1,
|
||||
MIDDLE = 2,
|
||||
BOTTOM = 3,
|
||||
};
|
||||
|
||||
struct PrintableText {
|
||||
std::string text{""};
|
||||
std::string font{"Noto"};
|
||||
uint8_t fontSize{0};
|
||||
HAlignPosition hAlign{HAlignPosition::LEFT};
|
||||
VAlignPosition vAlign{VAlignPosition::MIDDLE};
|
||||
};
|
||||
|
||||
} // namespace ptprnt
|
@@ -21,6 +21,8 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
TEST(basic_test, Image_smokeTest_succeeds) {
|
||||
auto im = ptprnt::graphics::Image();
|
||||
}
|
||||
|
@@ -1,38 +1,14 @@
|
||||
tests = [
|
||||
[
|
||||
'bitmap_test',
|
||||
'bitmap_test_exe',
|
||||
['../src/graphics/Bitmap.cpp', 'bitmap_test/bitmap_test.cpp'],
|
||||
],
|
||||
[
|
||||
'image_test',
|
||||
'image_test_exe',
|
||||
['../src/graphics/Image.cpp', 'image_test/image_test.cpp'],
|
||||
],
|
||||
[
|
||||
'monochrome_test',
|
||||
'monochrome_test_exe',
|
||||
[
|
||||
'../src/graphics/Monochrome.cpp',
|
||||
'monochrome_test/monochrome_test.cpp',
|
||||
],
|
||||
],
|
||||
]
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ptprnt_srcs +['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']]
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
test(
|
||||
test.get(0),
|
||||
executable(
|
||||
test.get(1),
|
||||
sources: test.get(2),
|
||||
include_directories: incdir,
|
||||
dependencies: [
|
||||
gtest_dep,
|
||||
usb_dep,
|
||||
log_dep,
|
||||
pangocairo_dep,
|
||||
cli11_dep,
|
||||
],
|
||||
),
|
||||
test(test.get(0),
|
||||
executable(test.get(1),
|
||||
sources: test.get(2),
|
||||
include_directories: incdir,
|
||||
dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep]
|
||||
)
|
||||
)
|
||||
endforeach
|
||||
endforeach
|
@@ -57,9 +57,6 @@ TEST(basic_test, Monochrome_convertWithCustomThreshhold_yieldsMonochromeRespecti
|
||||
}
|
||||
|
||||
TEST(basic_test, Monochrome_convertNonAlignedPixels_spillsOverIntoNewByte) {
|
||||
// TODO: We need to find to access the vector without the possiblity of out-of-bounds access
|
||||
// Ideas: constexpr? compile time check?
|
||||
GTEST_SKIP() << "Skipping this test, as ASAN will halt as this is an out-of-bounds access";
|
||||
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
||||
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF});
|
||||
|
||||
|
Reference in New Issue
Block a user