diff options
| author | Nikita Kostovsky <luntik2012@gmail.com> | 2024-12-09 13:19:58 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <luntik2012@gmail.com> | 2024-12-09 13:19:58 +0100 |
| commit | 81ce2f7ee5f27d08479d40fb6450a49f70f3355c (patch) | |
| tree | 1fa85786c8696494d84fdf7fc1c351e89b1a7a7b /printerclient.cpp | |
| parent | ee43621697a4cdc4c7728d4b42ad73b8321137c4 (diff) | |
add x calibration prototype, add .clang-config
Diffstat (limited to 'printerclient.cpp')
| -rw-r--r-- | printerclient.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/printerclient.cpp b/printerclient.cpp index c5bf189..a78de50 100644 --- a/printerclient.cpp +++ b/printerclient.cpp @@ -5,10 +5,22 @@ #include <QDebug> #include <QFile> #include <QSerialPort> +#include <QSerialPortInfo> -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( |
