-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.cpp
70 lines (57 loc) · 2.31 KB
/
dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by user on 29.10.2020.
//
#include "dialog.h"
#include "ui_dialog.h"
#include <iostream>
#include "serial/serial.h"
Dialog::Dialog(QWidget *parent)
:QDialog(parent),
ui(new Ui::Dialog)
{
auto refreshComPortsList = [this]() {
QStringList port_names;
for(const auto &port : serial::list_ports()) {
if ((port.port.find("USB") != std::string::npos) || (port.port.find("COM") != std::string::npos))
port_names.push_back(port.port.c_str());
}
ui->comboBox_comPorts->clear();
ui->comboBox_comPorts->addItems(port_names);
};
ui->setupUi(this);
connect(ui->comboBox_adapterType, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this, refreshComPortsList](int index)
{
m_selectedType = static_cast<enControllerType>(index);
refreshComPortsList();
if (m_selectedType == elm327) {
ui->checkBox_maximize->setChecked(false);
ui->checkBox_maximize->setEnabled(false);
ui->checkBox_autodetect->setChecked(false);
ui->checkBox_autodetect->setEnabled(false);
} else {
ui->checkBox_maximize->setEnabled(true);
ui->checkBox_autodetect->setEnabled(true);
}
});
connect(ui->pushButton_OK, &QPushButton::clicked, this, [this]() {
this->setEnabled(false);
m_settings.type = m_selectedType;
m_settings.port_name = ui->comboBox_comPorts->currentText().toStdString();
m_settings.autodetect = ui->checkBox_autodetect->isChecked();
m_settings.maximize = ui->checkBox_maximize->isChecked();
m_settings.baudrate = ui->spinBox_baudrate->value();
emit btnOk_click();
});
connect(ui->checkBox_autodetect, &QCheckBox::toggled, this, [this](bool checked) {
ui->spinBox_baudrate->setEnabled(!checked);
});
connect(ui->comboBox_comPorts, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this](int index){ ui->pushButton_OK->setEnabled(index != -1);});
connect(ui->pushButton_comRefresh, &QPushButton::clicked, this, [refreshComPortsList, this]() {
refreshComPortsList();
});
ui->spinBox_baudrate->setValue(38400);
ui->comboBox_adapterType->addItem(ToString(els27));
ui->comboBox_adapterType->addItem(ToString(elm327));
}