234 lines
6.3 KiB
C++
234 lines
6.3 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
drvSPI = new DRV_Spi(this);
|
|
drvUart = new DRV_Uart(this);
|
|
fHandler = new FrameHandler(this);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void MainWindow::onLogPrint(QString msg){
|
|
|
|
auto now = QDateTime::currentDateTime();
|
|
QString tmp = now.toString("yyyy-MM-dd HH:mm:ss")+" "+msg;
|
|
ui->textBrowser->append(tmp);
|
|
|
|
}
|
|
|
|
void MainWindow::on_pushButton_14_clicked()
|
|
{
|
|
dc= new DialogCalibrate(this);
|
|
dc->show();
|
|
}
|
|
|
|
|
|
void MainWindow::on_comboBox_activated(int index)
|
|
{
|
|
ui->stackedWidget->setCurrentIndex(ui->comboBox->currentIndex());
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_6_clicked()
|
|
{
|
|
ui->comboBox_7->clear();
|
|
// 刷新UART设备
|
|
if(drvUart->Uart_enumDevice()){
|
|
// 将串口设备的名称添加至列表中
|
|
for(int i = 0; i < drvUart->m_DRV_Uart_Infors.ulDevCnt; i++)
|
|
ui->comboBox_7->addItem(drvUart->m_DRV_Uart_Infors.bDeviceName[i]);
|
|
}else{
|
|
onLogPrint("No devices");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_7_clicked()
|
|
{
|
|
ULONG index = ui->comboBox_7->currentIndex();
|
|
// 调用串口打开函数
|
|
BOOL status = drvUart->Uart_openDevice(index);
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
ui->comboBox_8->setEnabled(true);
|
|
ui->comboBox_9->setEnabled(true);
|
|
ui->comboBox_10->setEnabled(true);
|
|
ui->comboBox_11->setEnabled(true);
|
|
ui->pushButton_8->setEnabled(true);
|
|
ui->lineEdit->setEnabled(true);
|
|
ui->pushButton_5->setEnabled(true);
|
|
ui->pushButton_7->setEnabled(false);
|
|
onLogPrint("Open device success");
|
|
}else{
|
|
onLogPrint("Open device failed");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_8_clicked()
|
|
{
|
|
// 读取组件中配置参数的值
|
|
ULONG Baudrate = this->ui->comboBox_8->currentText().toLong();
|
|
UCHAR StopBits = this->ui->comboBox_10->currentIndex();
|
|
UCHAR Parity = this->ui->comboBox_9->currentIndex();
|
|
UCHAR DataBits = this->ui->comboBox_11->currentText().toUInt();
|
|
UCHAR Timeout = this->ui->lineEdit->text().toUInt();
|
|
// 调用配置参数函数进行配置
|
|
if(drvUart->Uart_setPara(Baudrate, StopBits, Parity, DataBits, Timeout)){
|
|
onLogPrint("Set parameters success");
|
|
}else{
|
|
onLogPrint("Fail to set parameters");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_5_clicked()
|
|
{
|
|
|
|
BOOL status = drvUart->Uart_closeDevice();
|
|
if(status == TRUE){
|
|
ui->comboBox_8->setEnabled(false);
|
|
ui->comboBox_9->setEnabled(false);
|
|
ui->comboBox_10->setEnabled(false);
|
|
ui->comboBox_11->setEnabled(false);
|
|
ui->pushButton_8->setEnabled(false);
|
|
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");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
{
|
|
ui->comboBox_2->clear();
|
|
// 刷新UART设备
|
|
if(drvSPI->spi_enumDevice()){
|
|
// 将串口设备的名称添加至列表中
|
|
ui->comboBox_2->addItem(drvSPI->m_DRV_Spi_Infors.bDeviceName);
|
|
}else{
|
|
onLogPrint("No devices");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_2_clicked()
|
|
{
|
|
ULONG index = ui->comboBox_2->currentIndex();
|
|
// 调用串口打开函数
|
|
BOOL status = drvSPI->spi_openDevice(index);
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == 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");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
{
|
|
|
|
BOOL status = drvSPI->spi_closeDevice();
|
|
|
|
// 判断打开串口设备是否成功
|
|
if(status == TRUE){
|
|
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);
|
|
|
|
onLogPrint("Close device success");
|
|
}else{
|
|
onLogPrint("Close device failed");
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_9_clicked()
|
|
{
|
|
QByteArray tmp = fHandler->genREGWrite(0x01,0x01,0x09,0x81);
|
|
qDebug()<<tmp.toHex();
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_10_clicked()
|
|
{
|
|
QByteArray tmp = fHandler->genREGRead(0x01);
|
|
qDebug()<<tmp.toHex();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|