-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialcommands.cpp
More file actions
93 lines (80 loc) · 3.34 KB
/
serialcommands.cpp
File metadata and controls
93 lines (80 loc) · 3.34 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <mainwindow.h>
#include <ui_mainwindow.h>
// Вспомогательная функция для отправки данных через последовательный порт
void MainWindow::writeToSerial(const char* command)
{
if (serialPort && serialPort->isOpen())
{
serialPort->write(command);
}
else
{
printConsole("[ERROR]: Последовательный порт не открыт");
}
}
// Обработчик нажатия кнопки для пользовательских команд
void MainWindow::on_pushButton_userCommand_clicked()
{
bool ok;
QString text = QInputDialog::getText(this, "Пользовательская команда", "Введите команду:", QLineEdit::Normal, "", &ok);
if (ok && !text.isEmpty())
{
writeToSerial(text.toUtf8().constData());
}
}
// Обработчик для отправки параметризированных команд с использованием QLineEdit
void MainWindow::sendCommand(const char* commandBase, QLineEdit* lineEdit)
{
if (lineEdit && !lineEdit->text().isEmpty())
{
QString fullCommand = QString(commandBase) + lineEdit->text();
writeToSerial(fullCommand.toUtf8().constData());
}
}
// Обработчики для команд, задаваемых через QComboBox
void MainWindow::sendCommand(const char* commandBase, QComboBox* comboBox)
{
if (comboBox)
{
QString fullCommand = QString(commandBase) + QString::number(comboBox->currentIndex());
writeToSerial(fullCommand.toUtf8().constData());
}
}
// Обработчики для команд, задаваемых через QSpinBox
void MainWindow::sendCommand(const char* commandBase, QSpinBox* spinBox)
{
if (spinBox)
{
QString fullCommand = QString(commandBase) + QString::number(spinBox->value());
writeToSerial(fullCommand.toUtf8().constData());
}
}
// Обработчик нажатия кнопки для установки настроек по умолчанию
void MainWindow::on_pushButton_default_settings_set_clicked()
{
QDialog dialog(this);
dialog.setWindowTitle("Сброс изделия до заводских настроек");
QFormLayout form(&dialog);
QLabel* label = new QLabel(&dialog);
QLabel* labelSure = new QLabel(&dialog);
label->setText("Применение этой команды сбросит все настройки изделия до заводского состояния.\n");
labelSure->setText("Вы уверены?\n");
labelSure->setAlignment(Qt::AlignCenter);
form.addRow(label);
form.addRow(labelSure);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
buttonBox.button(QDialogButtonBox::Ok)->setText("Сбросить");
buttonBox.button(QDialogButtonBox::Cancel)->setText("Отмена");
form.addRow(&buttonBox);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
if (dialog.exec() == QDialog::Accepted)
{
writeToSerial(CMD_DEFAULT_SETTINGS_SET);
}
}
void MainWindow::on_pushButton_start_configure_clicked()
{
QString fullCommand = QString(PASSWORD_CONFIG);
writeToSerial(fullCommand.toUtf8().constData());
}