Skip to content

Commit

Permalink
Improve bluetooth disconnecting state
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Apr 15, 2024
1 parent 0bec57c commit d2b4571
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
38 changes: 11 additions & 27 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ Device::Device(const QBluetoothDeviceInfo &d, QObject *parent) : QObject(parent)

Device::~Device()
{
if (m_bleController)
{
m_bleController->disconnectFromDevice();
delete m_bleController;
}
deviceDisconnect();
}

/* ************************************************************************** */
Expand Down Expand Up @@ -203,8 +199,11 @@ void Device::deviceConnect()
// Start the actual connection process
if (m_bleController)
{
setTimeoutTimer();
m_ble_status = DeviceUtils::DEVICE_CONNECTING;
Q_EMIT statusUpdated();

m_bleController->connectToDevice();
setTimeoutTimer();
}
}

Expand All @@ -214,6 +213,9 @@ void Device::deviceDisconnect()

if (m_bleController && m_bleController->state() != QLowEnergyController::UnconnectedState)
{
m_ble_status = DeviceUtils::DEVICE_DISCONNECTING;
Q_EMIT statusUpdated();

m_bleController->disconnectFromDevice();
}
}
Expand Down Expand Up @@ -440,26 +442,14 @@ void Device::refreshStop()
{
//qDebug() << "Device::refreshStop()" << getAddress() << getName();

if (m_bleController && m_bleController->state() != QLowEnergyController::UnconnectedState)
{
m_bleController->disconnectFromDevice();
}

if (m_ble_status != DeviceUtils::DEVICE_OFFLINE)
{
m_ble_status = DeviceUtils::DEVICE_OFFLINE;
Q_EMIT statusUpdated();
}
deviceDisconnect();
}

void Device::actionCanceled()
{
//qDebug() << "Device::actionCanceled()" << getAddress() << getName();

if (m_bleController)
{
m_bleController->disconnectFromDevice();
}
deviceDisconnect();

refreshDataFinished(false);
}
Expand All @@ -468,10 +458,7 @@ void Device::actionTimedout()
{
//qDebug() << "Device::actionTimedout()" << getAddress() << getName();

if (m_bleController)
{
m_bleController->disconnectFromDevice();
}
deviceDisconnect();

refreshDataFinished(false);
}
Expand All @@ -486,9 +473,6 @@ void Device::refreshRetry()
void Device::actionStarted()
{
//qDebug() << "Device::actionStarted()" << getAddress() << getName();

m_ble_status = DeviceUtils::DEVICE_CONNECTING;
Q_EMIT statusUpdated();
}

void Device::refreshDataFinished(bool status, bool cached)
Expand Down
6 changes: 4 additions & 2 deletions src/device_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ class DeviceUtils: public QObject
DEVICE_OFFLINE = 0, //!< Not connected

DEVICE_QUEUED = 1, //!< In the update queue, not started
DEVICE_CONNECTING = 2, //!< Trying to connect to the device
DEVICE_CONNECTED = 3, //!< Connected

DEVICE_DISCONNECTING = 2, //!< Disconnecting from the device
DEVICE_CONNECTING = 3, //!< Connecting to the device
DEVICE_CONNECTED = 4, //!< Connected

DEVICE_WORKING = 8, //!< Connected, doing something
DEVICE_UPDATING = 9, //!< Connected, reading latest data
Expand Down

0 comments on commit d2b4571

Please sign in to comment.