diff --git a/mainwindow.cpp b/mainwindow.cpp index 9319eab..5169efa 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -106,6 +106,7 @@ void MainWindow::on_pushButton_5_clicked() ui->lineEdit->setEnabled(false); ui->pushButton_5->setEnabled(false); ui->pushButton_7->setEnabled(true); + ui->btnSpiSaveSetting->setEnabled(false); onLogPrint("Close device success"); }else{ onLogPrint("Close device failed"); @@ -134,15 +135,17 @@ void MainWindow::on_pushButton_2_clicked() // 判断打开串口设备是否成功 if(status == TRUE){ - ui->comboBox_3->setEnabled(true); - ui->comboBox_4->setEnabled(true); - ui->comboBox_5->setEnabled(true); - ui->comboBox_6->setEnabled(true); - ui->comboBox_16->setEnabled(true); - ui->comboBox_17->setEnabled(true); + ui->comboSpiMode->setEnabled(true); + ui->comboSpiClock->setEnabled(true); + ui->comboSpiByteOrder->setEnabled(true); + ui->comboSpiDataBits->setEnabled(true); + ui->comboSpiCS1Pol->setEnabled(true); + ui->comboSpiCS2Pol->setEnabled(true); ui->pushButton_3->setEnabled(true); ui->pushButton_2->setEnabled(false); + ui->btnSpiSaveSetting->setEnabled(true); onLogPrint("Open device success"); + on_btnSpiSaveSetting_clicked(); // 初始化SPI参数 }else{ onLogPrint("Open device failed"); } @@ -157,12 +160,12 @@ void MainWindow::on_pushButton_3_clicked() // 判断打开串口设备是否成功 if(status == TRUE){ - ui->comboBox_3->setEnabled(false); - ui->comboBox_4->setEnabled(false); - ui->comboBox_5->setEnabled(false); - ui->comboBox_6->setEnabled(false); - ui->comboBox_16->setEnabled(false); - ui->comboBox_17->setEnabled(false); + ui->comboSpiMode->setEnabled(false); + ui->comboSpiClock->setEnabled(false); + ui->comboSpiByteOrder->setEnabled(false); + ui->comboSpiDataBits->setEnabled(false); + ui->comboSpiCS1Pol->setEnabled(false); + ui->comboSpiCS2Pol->setEnabled(false); ui->pushButton_3->setEnabled(false); ui->pushButton_2->setEnabled(true); @@ -172,3 +175,44 @@ void MainWindow::on_pushButton_3_clicked() } } +void MainWindow::on_btnSpiSaveSetting_clicked() { + drvSPI->spi_Init( + ui->comboBox_2->currentIndex(), + ui->comboSpiMode->currentIndex(), + ui->comboSpiClock->currentIndex(), + ui->comboSpiByteOrder->currentIndex(), + ui->comboSpiDataBits->currentIndex(), + ui->comboSpiCS1Pol->currentIndex(), + ui->comboSpiCS2Pol->currentIndex() + ); +} + +void MainWindow::onWriteRegButtonClicked() { + QByteArray ba; + ba.append(0x9F); + ba.append(0xE4); + ba.append(0x05); + ba.append(0x0B); + for (int i = 0; i < 11; ++i) { + ba.append((char)0x00); + } + ba.append(0x93); + + drvSPI->spi_Write(ba); + qDebug() << __FUNCTION__ << ba; +} + +void MainWindow::onReadRegButtonClicked() { + qDebug() << __FUNCTION__; +} + +void MainWindow::on_comboBox_currentTextChanged(const QString& text) { + if (text.toLower() == "spi") { + connect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked); + connect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked); + } else { + disconnect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked); + disconnect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked); + } +} + diff --git a/mainwindow.h b/mainwindow.h index 708f98d..0e28a29 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -49,11 +49,16 @@ private slots: void on_pushButton_3_clicked(); + void on_btnSpiSaveSetting_clicked(); + void onWriteRegButtonClicked(); + void onReadRegButtonClicked(); + + void on_comboBox_currentTextChanged(const QString& text); + private: Ui::MainWindow *ui; DialogCalibrate *dc; DRV_Uart *drvUart; DRV_Spi *drvSPI; - }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 0a2762c..efcc3fe 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -90,7 +90,7 @@ Timeout(ms): - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -149,7 +149,7 @@ Data Bits: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -159,7 +159,7 @@ Stop Bits: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -258,7 +258,7 @@ Baud Rate: - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter @@ -268,7 +268,7 @@ Parity Bits: - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter @@ -288,7 +288,7 @@ UART Device List: - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter @@ -311,15 +311,18 @@ SPI Device List: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - + false + + 1 + LSB @@ -333,7 +336,7 @@ - + false @@ -355,12 +358,15 @@ SPI Mode: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - + + + false + 0 @@ -383,10 +389,13 @@ - + false + + 1 + 60MHz @@ -435,7 +444,7 @@ Clock: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -445,12 +454,12 @@ LSB/MSB - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - + false @@ -482,12 +491,12 @@ DataBits: - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - + false @@ -504,7 +513,7 @@ - + false @@ -632,10 +641,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::MinimumExpanding + QSizePolicy::Policy::MinimumExpanding @@ -1057,7 +1066,7 @@ - + Write Reg @@ -1091,7 +1100,7 @@ 0 0 839 - 21 + 33