mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-15 23:01:01 -08:00
example 'meshtastic': fix USB for macOS
This commit is contained in:
parent
480e3eabfd
commit
a8a6b0058b
3 changed files with 18 additions and 12 deletions
|
|
@ -5,19 +5,24 @@
|
||||||
|
|
||||||
USB_ME::USB_ME() {
|
USB_ME::USB_ME() {
|
||||||
const auto infos = QSerialPortInfo::availablePorts();
|
const auto infos = QSerialPortInfo::availablePorts();
|
||||||
const QStringList boards = { "RAK" }; // TODO: currently RAK only
|
const QStringList boards = { "RAK", "UART" }; // TODO
|
||||||
for (const QSerialPortInfo& info : infos) {
|
for (const QSerialPortInfo& info : infos) {
|
||||||
QString name(info.description() + " " + info.manufacturer());
|
QString name(info.description() + " " + info.manufacturer());
|
||||||
qDebug() << "USB:" << info.portName() << name;
|
QString port(info.portName());
|
||||||
for (auto board : boards) {
|
qDebug() << "USB:" << port << name;
|
||||||
if (name.contains(board, Qt::CaseInsensitive)) {
|
if (port.startsWith("tty") &&
|
||||||
setPortName(info.portName());
|
(port.contains("ACM", Qt::CaseInsensitive) || // Linux
|
||||||
goto done;
|
port.contains("USB", Qt::CaseInsensitive))) { // macOS
|
||||||
|
for (auto board : boards) {
|
||||||
|
if (name.contains(board, Qt::CaseInsensitive)) {
|
||||||
|
setPortName(info.portName());
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
connect(this, &QSerialPort::readyRead, this, &USB_ME::read);
|
connect(this, &QSerialPort::readyRead, this, &USB_ME::read2);
|
||||||
connect(this, &QSerialPort::errorOccurred,
|
connect(this, &QSerialPort::errorOccurred,
|
||||||
[](QSerialPort::SerialPortError error) {
|
[](QSerialPort::SerialPortError error) {
|
||||||
if (error != QSerialPort::NoError) {
|
if (error != QSerialPort::NoError) {
|
||||||
|
|
@ -54,10 +59,11 @@ void USB_ME::write2(const QByteArray& data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USB_ME::read() {
|
void USB_ME::read2() {
|
||||||
const char header[] = { '\x94', '\xc3' };
|
|
||||||
static QTimer* timer = nullptr;
|
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 (data.startsWith(header)) { // skip evtl. debug log
|
||||||
if (state == Open) {
|
if (state == Open) {
|
||||||
Q_EMIT setReady(portName());
|
Q_EMIT setReady(portName());
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void wantConfigId();
|
void wantConfigId();
|
||||||
void write2(const QByteArray&);
|
void write2(const QByteArray&);
|
||||||
void read();
|
void read2();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void setReady(const QString&);
|
void setReady(const QString&);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@
|
||||||
(defun set-ready-usb (port) ; see Qt
|
(defun set-ready-usb (port) ; see Qt
|
||||||
(setf *ready* t
|
(setf *ready* t
|
||||||
*mode* :usb)
|
*mode* :usb)
|
||||||
(app:toast (x:cc (tr "radio") ": " port) 2)
|
(app:toast (x:cc "USB: " port) 2)
|
||||||
(get-node-config nil)
|
(get-node-config nil)
|
||||||
(values))
|
(values))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue