example 'meshtastic': fix USB for macOS

This commit is contained in:
pls.153 2024-04-13 18:42:23 +02:00
parent 480e3eabfd
commit a8a6b0058b
3 changed files with 18 additions and 12 deletions

View file

@ -5,10 +5,14 @@
USB_ME::USB_ME() {
const auto infos = QSerialPortInfo::availablePorts();
const QStringList boards = { "RAK" }; // TODO: currently RAK only
const QStringList boards = { "RAK", "UART" }; // TODO
for (const QSerialPortInfo& info : infos) {
QString name(info.description() + " " + info.manufacturer());
qDebug() << "USB:" << info.portName() << name;
QString port(info.portName());
qDebug() << "USB:" << port << name;
if (port.startsWith("tty") &&
(port.contains("ACM", Qt::CaseInsensitive) || // Linux
port.contains("USB", Qt::CaseInsensitive))) { // macOS
for (auto board : boards) {
if (name.contains(board, Qt::CaseInsensitive)) {
setPortName(info.portName());
@ -16,8 +20,9 @@ USB_ME::USB_ME() {
}
}
}
}
done:
connect(this, &QSerialPort::readyRead, this, &USB_ME::read);
connect(this, &QSerialPort::readyRead, this, &USB_ME::read2);
connect(this, &QSerialPort::errorOccurred,
[](QSerialPort::SerialPortError error) {
if (error != QSerialPort::NoError) {
@ -54,10 +59,11 @@ void USB_ME::write2(const QByteArray& data) {
}
}
void USB_ME::read() {
const char header[] = { '\x94', '\xc3' };
void USB_ME::read2() {
static QTimer* timer = nullptr;
QByteArray data(readAll());
const char header[] = { '\x94', '\xc3' };
const int MAX = 0xffff;
QByteArray data(read(MAX));
if (data.startsWith(header)) { // skip evtl. debug log
if (state == Open) {
Q_EMIT setReady(portName());

View file

@ -19,7 +19,7 @@ public:
public Q_SLOTS:
void wantConfigId();
void write2(const QByteArray&);
void read();
void read2();
Q_SIGNALS:
void setReady(const QString&);

View file

@ -80,7 +80,7 @@
(defun set-ready-usb (port) ; see Qt
(setf *ready* t
*mode* :usb)
(app:toast (x:cc (tr "radio") ": " port) 2)
(app:toast (x:cc "USB: " port) 2)
(get-node-config nil)
(values))