forked from Gawhary/Qt-BLE-Tester
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
72 lines (63 loc) · 1.9 KB
/
Copy pathmainwindow.cpp
File metadata and controls
72 lines (63 loc) · 1.9 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStatusBar>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_bleInterface = new BLEInterface(this);
connect(m_bleInterface, &BLEInterface::dataReceived,
this, &MainWindow::dataReceived);
connect(m_bleInterface, &BLEInterface::devicesNamesChanged,
[this] (QStringList devices){
ui->devicesComboBox->clear();
ui->devicesComboBox->addItems(devices);
});
connect(m_bleInterface, &BLEInterface::servicesChanged,
[this] (QStringList services){
ui->servicesComboBox->clear();
ui->servicesComboBox->addItems(services);
});
connect(m_bleInterface, &BLEInterface::statusInfoChanged,
[this](QString info, bool){
this->statusBar()->showMessage(info);
});
m_bleInterface->scanDevices();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_bleScanButton_clicked()
{
m_bleInterface->scanDevices();
}
void MainWindow::on_connectButton_clicked()
{
m_bleInterface->set_currentDevice(ui->devicesComboBox->currentIndex());
m_bleInterface->connectCurrentDevice();
}
void MainWindow::on_sendButton_clicked()
{
QByteArray data;
if(ui->asciiRadioButton->isChecked())
data = QByteArray(ui->sendTextEdit->toPlainText().toLatin1());
else
data = QByteArray::fromHex(ui->sendTextEdit->toPlainText().toLatin1());
m_bleInterface->write(data);
ui->sendTextEdit->clear();
}
void MainWindow::dataReceived(QByteArray data){
if(ui->asciiRadioButton->isChecked()){
ui->receivedTextEdit->append("\n");
ui->receivedTextEdit->append(data);
}
else{
ui->receivedTextEdit->append(data.toHex());
}
}
void MainWindow::on_servicesComboBox_currentIndexChanged(int index)
{
m_bleInterface->setCurrentService(index);
}