From 928326efb245b1690f2e6b7fad38c5ca333b7b79 Mon Sep 17 00:00:00 2001 From: luocai Date: Fri, 9 Aug 2024 18:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=87=E7=BA=A7=E4=B8=B2?= =?UTF-8?q?=E5=8F=A3=E6=89=93=E5=BC=80=E5=A4=B1=E8=B4=A5=E5=90=8E=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD=E5=B0=9D=E8=AF=95=E7=9A=84=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OtaUpdate/Widget.cpp | 7 ++++++- Peripheral/CdcUpdater.cpp | 10 +++++++--- Peripheral/CdcUpdater.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OtaUpdate/Widget.cpp b/OtaUpdate/Widget.cpp index e736d66..8e6ad13 100644 --- a/OtaUpdate/Widget.cpp +++ b/OtaUpdate/Widget.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,8 @@ Widget::Widget(QWidget *parent) : QWidget(parent) { setAcceptDrops(true); } -Widget::~Widget() {} +Widget::~Widget() { +} void Widget::start() { m_progressBar->setValue(0); @@ -90,6 +92,9 @@ void Widget::start() { void Widget::onCdcDeviceDiscovered(const QSerialPortInfo &info) { auto status = m_updater->open(info); LOG(info) << "open cdc port: " << info.portName().toStdString() << ", status: " << status; + if (!status) { + QTimer::singleShot(0, this, [this]() { m_updater->startSearchDevice(); }); + } } void Widget::onSelectButtonClicked() { diff --git a/Peripheral/CdcUpdater.cpp b/Peripheral/CdcUpdater.cpp index f317308..9bd5e57 100644 --- a/Peripheral/CdcUpdater.cpp +++ b/Peripheral/CdcUpdater.cpp @@ -42,9 +42,7 @@ CdcUpdater::~CdcUpdater() { void CdcUpdater::start(const QString &path, const QSerialPortInfo &info) { if (info.isNull()) { - if (m_timerId < 0) { - m_timerId = startTimer(1000); - } + startSearchDevice(); } else { open(info); } @@ -54,6 +52,12 @@ void CdcUpdater::start(const QString &path, const QSerialPortInfo &info) { emit progressChanged(++m_progress); } +void CdcUpdater::startSearchDevice() { + if (m_timerId < 0) { + m_timerId = startTimer(1000); + } +} + bool CdcUpdater::open(const QSerialPortInfo &info) { m_serialPort = std::make_shared(info); connect(m_serialPort.get(), &QSerialPort::readyRead, this, &CdcUpdater::onReadyRead); diff --git a/Peripheral/CdcUpdater.h b/Peripheral/CdcUpdater.h index 9e8b52b..e84b541 100644 --- a/Peripheral/CdcUpdater.h +++ b/Peripheral/CdcUpdater.h @@ -37,6 +37,7 @@ public: CdcUpdater(QObject *parent = nullptr); ~CdcUpdater(); void start(const QString &path, const QSerialPortInfo &info = QSerialPortInfo()); + void startSearchDevice(); bool open(const QSerialPortInfo &info); static std::optional searchDevice();