diff --git a/mainwindow.cpp b/mainwindow.cpp index e1cda89..e4d7f82 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,8 @@ QTimer *timer1; QTimer *timer2; QTimer *timer3; QTimer *checkConnectTimer0; + +ZQThread *m_zqthread; #define TAG "MainWindow" static const char *fmt(const char *fmt, ...) { @@ -195,7 +197,9 @@ void MainWindow::refreshReadonlyPage0() { { float TriOutSignalFreq; DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq)); - ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2)); + emit doinui_signal(QFunction([this, TriOutSignalFreq]() { // + ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2)); + })); } } void MainWindow::refreshReadonlyPage1() { @@ -207,12 +211,15 @@ void MainWindow::refreshReadonlyPage1() { float infreq; float outfreq; -#define UPDATE(index) \ - DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \ - DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \ - ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \ - ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); - +#define UPDATE(index) \ + DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \ + DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \ + { \ + emit doinui_signal(QFunction([this, infreq, outfreq]() { \ + ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \ + ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); \ + })); \ + } UPDATE(1); UPDATE(2); UPDATE(3); @@ -232,13 +239,17 @@ void MainWindow::refreshReadonlyPage2() { float outfreq; uint32_t state; -#define UPDATE(index) \ - DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \ - DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \ - DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \ - ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \ - ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \ - ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); +#define UPDATE(index) \ + DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \ + DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \ + DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \ + { \ + emit doinui_signal(QFunction([this, infreq, outfreq, state]() { \ + ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \ + ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \ + ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); \ + })); \ + } UPDATE(1); UPDATE(2); @@ -246,7 +257,11 @@ void MainWindow::refreshReadonlyPage2() { UPDATE(4); } } - +void MainWindow::refreshReadonlyPage3() { + if (!G_QTDataChannel.isOpen()) { + return; + } +} bool MainWindow::checkConnected() { if (!G_QTDataChannel.isOpen()) { return false; @@ -259,12 +274,6 @@ bool MainWindow::checkConnected() { return true; } -void MainWindow::refreshReadonlyPage3() { - if (!G_QTDataChannel.isOpen()) { - return; - } -} - void MainWindow::refreshPage() { /******************************************************************************* * 刷新内部触发源页面 * @@ -663,6 +672,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi qRegisterMetaType("int32_t"); qRegisterMetaType("uint32_t"); + qRegisterMetaType("float"); qRegisterMetaType>("function"); qRegisterMetaType("QFunction"); // qInstallMessageHandler(log_output); @@ -675,40 +685,73 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi 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(); + m_zqthread = new ZQThread("", [this]() { + while (true) { + static bool connected = false; + static bool first = true; + bool connect = checkConnected(); + if (connected != connect || first) { + first = false; + connected = connect; + emit doinui_signal(QFunction([this, connect]() { + if (connect) { + ui->DeviceConnectStateTB->setText("已连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: green"); + } else { + ui->DeviceConnectStateTB->setText("未连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: red"); + } + if (connected) { + refreshPage(); + } + })); } - } + refreshReadonlyPage0(); + refreshReadonlyPage1(); + refreshReadonlyPage2(); + refreshReadonlyPage3(); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } }); + m_zqthread->start(); + + // 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(); + // 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;