From 81ce2f7ee5f27d08479d40fb6450a49f70f3355c Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Mon, 9 Dec 2024 13:19:58 +0100 Subject: add x calibration prototype, add .clang-config --- printerclient.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'printerclient.cpp') diff --git a/printerclient.cpp b/printerclient.cpp index c5bf189..a78de50 100644 --- a/printerclient.cpp +++ b/printerclient.cpp @@ -5,10 +5,22 @@ #include #include #include +#include -PrinterClient::PrinterClient(QObject *parent) - : QObject { parent } - , m_serialPort { new QSerialPort { "/dev/ttyUSB0", this } } +QString getFirstTtyUSB() +{ + auto ports = QSerialPortInfo::availablePorts(); + + std::remove_if(ports.begin(), ports.end(), [](const auto& port) { + return !port.portName().contains("ttyUSB"); + }); + + return ports.isEmpty() ? "" : ports.first().portName(); +} + +PrinterClient::PrinterClient(QObject* parent) + : QObject{parent} // , m_serialPort{new QSerialPort{"/dev/ttyUSB0", this}} + , m_serialPort{new QSerialPort{getFirstTtyUSB(), this}} { if (!m_serialPort->setBaudRate(QSerialPort::Baud115200)) { throw std::runtime_error( -- cgit v1.2.3-70-g09d2