Add discovery check
This commit is contained in:
parent
daf8d0f638
commit
3e959b3bce
@ -55,6 +55,7 @@ void BluetoothLowEnergyDevice::setConnected(const bool &connected)
|
|||||||
{
|
{
|
||||||
if (m_connected != connected) {
|
if (m_connected != connected) {
|
||||||
m_connected = connected;
|
m_connected = connected;
|
||||||
|
qCDebug(dcBluetooth()) << "Device" << name() << address().toString() << (connected ? "connected" : "disconnected");
|
||||||
emit connectedChanged(m_connected);
|
emit connectedChanged(m_connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,11 +75,12 @@ void BluetoothLowEnergyDevice::setEnabled(const bool &enabled)
|
|||||||
|
|
||||||
void BluetoothLowEnergyDevice::onConnected()
|
void BluetoothLowEnergyDevice::onConnected()
|
||||||
{
|
{
|
||||||
qCDebug(dcBluetooth()) << "Device connected" << name() << address().toString();
|
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
|
|
||||||
qCDebug(dcBluetooth()) << "Discover services on" << name() << address().toString();
|
if (m_controller->state() != QLowEnergyController::DiscoveredState) {
|
||||||
m_controller->discoverServices();
|
qCDebug(dcBluetooth()) << "Discover services on" << name() << address().toString();
|
||||||
|
m_controller->discoverServices();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothLowEnergyDevice::onDisconnected()
|
void BluetoothLowEnergyDevice::onDisconnected()
|
||||||
@ -107,6 +109,10 @@ void BluetoothLowEnergyDevice::connectDevice()
|
|||||||
if (!m_enabled)
|
if (!m_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Only connect if not connected
|
||||||
|
if (m_controller->state() != QLowEnergyController::UnconnectedState)
|
||||||
|
return;
|
||||||
|
|
||||||
m_controller->connectToDevice();
|
m_controller->connectToDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user