From 0bd4f649ff1f8f6ef29439f64d8ea131a9b409d4 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 11 Mar 2024 11:06:06 +0800 Subject: [PATCH] update --- mainwindow.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++---- mainwindow.h | 6 +----- mainwindow.ui | 2 +- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e74c5b6..e1cda89 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,6 +20,7 @@ QTimer *timer0; QTimer *timer1; QTimer *timer2; QTimer *timer3; +QTimer *checkConnectTimer0; #define TAG "MainWindow" static const char *fmt(const char *fmt, ...) { @@ -245,6 +246,19 @@ void MainWindow::refreshReadonlyPage2() { UPDATE(4); } } + +bool MainWindow::checkConnected() { + if (!G_QTDataChannel.isOpen()) { + return false; + } + uint32_t val; + zaf_error_code_t ecode = m_clstc->reg_read(kreg_software_version, val); + if (ecode != kaf_ec_success) { + return false; + } + return true; +} + void MainWindow::refreshReadonlyPage3() { if (!G_QTDataChannel.isOpen()) { return; @@ -632,6 +646,8 @@ void MainWindow::constructUI() { ui->ShutterX_InSigSelect_2->addItems(LightSrcX_TriSrc_QStringList); ui->ShutterX_InSigSelect_3->addItems(LightSrcX_TriSrc_QStringList); ui->ShutterX_InSigSelect_4->addItems(LightSrcX_TriSrc_QStringList); + + ui->InterClk_TriOutSignalFreq_Text->setDisabled(true); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -654,22 +670,45 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi constructUI(); // 创建定时器 - timer0 = new QTimer(this); - timer1 = new QTimer(this); - timer2 = new QTimer(this); - timer3 = new QTimer(this); + timer0 = new QTimer(this); + timer1 = new QTimer(this); + timer2 = new QTimer(this); + timer3 = new QTimer(this); + checkConnectTimer0 = new QTimer(this); connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); }); connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); }); connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); }); connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); }); + connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { // + static bool connected = false; + bool connect = checkConnected(); + if (connect) { + ui->DeviceConnectStateTB->setText("已连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: green"); + + } else { + ui->DeviceConnectStateTB->setText("未连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: red"); + } + if (connected != connect) { + connected = connect; + if (connected) { + refreshPage(); + } + } + + }); + timer0->setInterval(1100); // 每隔一秒触发一次 timer1->setInterval(1200); // 每隔一秒触发一次 timer2->setInterval(900); // 每隔一秒触发一次 timer3->setInterval(1000); // 每隔一秒触发一次 + checkConnectTimer0->setInterval(100); timer0->start(); timer1->start(); timer2->start(); timer3->start(); + checkConnectTimer0->start(); // m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) { // QString text; diff --git a/mainwindow.h b/mainwindow.h index 4b25a9a..ca97eac 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -81,6 +81,7 @@ class MainWindow : public QMainWindow { void refreshReadonlyPage2(); void refreshReadonlyPage3(); + bool checkConnected(); private slots: /** @@ -90,14 +91,9 @@ class MainWindow : public QMainWindow { signals: void doinui_signal(QFunction); - - private: static void log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg); void constructUI(); void dumpLog(const char *fmt, ...); }; #endif // MAINWINDOW_H - - - diff --git a/mainwindow.ui b/mainwindow.ui index bc394a7..8795d24 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -449,7 +449,7 @@ - 3 + 0 true