Merge PR #503: Improve bt setup

pull/507/head
Jenkins nymea 2021-01-14 00:38:22 +01:00
commit 9abae35ced
5 changed files with 17 additions and 2 deletions

View File

@ -67,6 +67,11 @@ bool BluetoothDeviceInfo::isLowEnergy() const
return m_deviceInfo.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration;
}
int BluetoothDeviceInfo::signalStrength() const
{
return (m_deviceInfo.rssi() + 100) * 2;
}
QBluetoothDeviceInfo BluetoothDeviceInfo::bluetoothDeviceInfo() const
{
return m_deviceInfo;

View File

@ -41,6 +41,7 @@ class BluetoothDeviceInfo : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY deviceChanged)
Q_PROPERTY(QString address READ address NOTIFY deviceChanged)
Q_PROPERTY(int signalStrength READ signalStrength NOTIFY deviceChanged)
public:
BluetoothDeviceInfo();
@ -50,6 +51,7 @@ public:
QString address() const;
QString name() const;
bool isLowEnergy() const;
int signalStrength() const;
QBluetoothDeviceInfo bluetoothDeviceInfo() const;
void setBluetoothDeviceInfo(const QBluetoothDeviceInfo &deviceInfo);

View File

@ -60,6 +60,8 @@ QVariant BluetoothDeviceInfos::data(const QModelIndex &index, int role) const
return deviceInfo->address();
} else if (role == BluetoothDeviceInfoRoleLe) {
return deviceInfo->isLowEnergy();
} else if (role == BluetoothDeviceInfoRoleSignalStrength) {
return deviceInfo->signalStrength();
}
return QVariant();
@ -103,5 +105,6 @@ QHash<int, QByteArray> BluetoothDeviceInfos::roleNames() const
roles[BluetoothDeviceInfoRoleName] = "name";
roles[BluetoothDeviceInfoRoleAddress] = "address";
roles[BluetoothDeviceInfoRoleLe] = "lowEnergy";
roles[BluetoothDeviceInfoRoleSignalStrength] = "signalStrength";
return roles;
}

View File

@ -44,8 +44,10 @@ public:
enum BluetoothDeviceInfoRole {
BluetoothDeviceInfoRoleName = Qt::DisplayRole,
BluetoothDeviceInfoRoleAddress,
BluetoothDeviceInfoRoleLe
BluetoothDeviceInfoRoleLe,
BluetoothDeviceInfoRoleSignalStrength
};
Q_ENUM(BluetoothDeviceInfoRole)
explicit BluetoothDeviceInfos(QObject *parent = nullptr);

View File

@ -176,16 +176,19 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo
{
if (!deviceInfo.isValid()
|| !deviceInfo.coreConfigurations().testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
|| deviceInfo.name().isEmpty()) {
|| deviceInfo.name().isEmpty()
|| deviceInfo.isCached()) {
return;
}
foreach (BluetoothDeviceInfo *di, m_deviceInfos->deviceInfos()) {
if (di->address() == deviceInfo.address().toString()) {
di->setBluetoothDeviceInfo(deviceInfo);
return;
}
}
BluetoothDeviceInfo *deviceInformation = new BluetoothDeviceInfo(deviceInfo);
// qDebug() << "BluetoothDiscovery: [+]" << deviceInformation->name() << "(" << deviceInformation->address() << ")" << (isLowEnergy ? "LE" : "") << deviceInfo.majorDeviceClass() << deviceInfo.minorDeviceClass() << deviceInfo.serviceClasses();
m_deviceInfos->addBluetoothDeviceInfo(deviceInformation);