-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluetoothmanager.cpp
More file actions
144 lines (114 loc) · 3.4 KB
/
bluetoothmanager.cpp
File metadata and controls
144 lines (114 loc) · 3.4 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "bluetoothmanager.h"
#include <qbluetoothaddress.h>
#include <QBluetoothLocalDevice>
#include <QDebug>
#include <QTimer>
#include <QSettings>
bool deviceFound = false;
QString settings;
QTimer *timer;
bool signUp = true;
BluetoothManager::BluetoothManager(QObject *parent) : QObject(parent)
{
QBluetoothLocalDevice localDevice;
// Turn Bluetooth on
localDevice.powerOn();
// m_discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
// connect(m_discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
// this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
// connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished()));
// connect(m_discoveryAgent, SIGNAL(canceled()), this, SLOT(scanCanceled()));
//// startDiscovery();
// timer = new QTimer(this);
// connect(timer, SIGNAL(timeout()), this, SLOT(update()));
// m_devicesList.clear();
}
BluetoothManager::~BluetoothManager()
{
delete m_discoveryAgent;
}
void BluetoothManager::update()
{
m_discoveryAgent->stop();
// if(deviceFound == false && signUp == false) {
// m_device.clear();
// m_device = "notFound";
// emit deviceBluetoothChanged();
// }
// deviceFound = false;
qDebug() << "star/stop";
m_discoveryAgent->start();
}
void BluetoothManager::startDiscovery()
{
qDebug() << "scanning";
m_discoveryAgent->start();
// timer->start(5000);
}
void BluetoothManager::setDevice(QString address)
{
deviceFound = true;
m_device.clear();
m_device = address;
emit deviceBluetoothChanged();
settings = address;
m_discoveryAgent->stop();
timer->stop();
}
QString BluetoothManager::getDevice()
{
return settings;
}
void BluetoothManager::registering(bool flag)
{
signUp = flag;
}
void BluetoothManager::scanCanceled()
{
// qDebug() << "deviceCanceled";
}
void BluetoothManager::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo)
{
// if(deviceInfo.address().toString() == settings && signUp == false) {
// deviceFound = true;
// m_device.clear();
// m_device = deviceInfo.address().toString();
// emit deviceBluetoothChanged();
// }
qDebug() << "detected";
// qDebug() << "Found new device:" << deviceInfo.name() << ", rssi:" << deviceInfo.address().toString();
if(!m_devicesList.contains(deviceInfo.name()) && signUp == true){
m_devicesList.append("{\"name\":\""+deviceInfo.name()+"\",\"address\":\""+deviceInfo.address().toString()+"\"}");
emit devicesListChanged();
}
}
QString BluetoothManager::deviceBluetooth() const
{
return m_device;
}
QStringList BluetoothManager::devicesList()
{
return m_devicesList;
}
void BluetoothManager::discoveryFinished()
{
qDebug() << __func__;
startDiscovery();
}
void BluetoothManager::connectDevice(const QBluetoothDeviceInfo device)
{
qDebug()<<"connecting device";
m_controller = 0;
m_controller = new QLowEnergyController(QBluetoothAddress("00:A0:C6:24:16:30"), this);
// connect(m_controller, SIGNAL(connected()), this, SLOT(deviceConnected()));
// connect(m_controller, SIGNAL(disconnected()), this, SLOT(deviceDisconnected()));
// m_controller->connectToDevice();
}
void BluetoothManager::deviceConnected()
{
qDebug()<<"Dispositivo conectado";
}
void BluetoothManager::deviceDisconnected()
{
qDebug()<<"Dispositivo desconectado";
}