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 1fbfb0a commit 8def8f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
6 changes: 5 additions & 1 deletion qml/components_js/UtilsDeviceSensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ function getDeviceBatteryIcon(batteryLevel) {
src = "qrc:/assets/icons/material-icons/duotone/battery_90.svg";
} else if (batteryLevel > 75) {
src = "qrc:/assets/icons/material-icons/duotone/battery_80.svg";
} else if (batteryLevel > 65) {
src = "qrc:/assets/icons/material-icons/duotone/battery_70.svg";
} else if (batteryLevel > 55) {
src = "qrc:/assets/icons/material-icons/duotone/battery_60.svg";
} else if (batteryLevel > 45) {
src = "qrc:/assets/icons/material-icons/duotone/battery_50.svg";
} else if (batteryLevel > 35) {
src = "qrc:/assets/icons/material-icons/duotone/battery_40.svg";
} else if (batteryLevel > 25) {
src = "qrc:/assets/icons/material-icons/duotone/battery_30.svg";
} else if (batteryLevel > 15) {
src = "qrc:/assets/icons/material-icons/duotone/battery_20.svg";
} else if (batteryLevel > 1) {
} else if (batteryLevel > 1) {
src = "qrc:/assets/icons/material-icons/duotone/battery_10.svg";
} else if (batteryLevel >= 0) {
src = "qrc:/assets/icons/material-icons/duotone/battery_unknown.svg";
Expand Down
29 changes: 5 additions & 24 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,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 @@ -191,8 +187,8 @@ void Device::deviceConnect()
m_ble_status = DeviceUtils::DEVICE_CONNECTING;
Q_EMIT statusUpdated();

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

Expand Down Expand Up @@ -308,36 +304,21 @@ 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();
}

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

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

void Device::refreshRetry()
Expand Down

0 comments on commit 8def8f5

Please sign in to comment.