Add signal strength property to bluetooth devices
parent
94483e92c5
commit
46e4180bb0
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ public:
|
|||
enum BluetoothDeviceInfoRole {
|
||||
BluetoothDeviceInfoRoleName = Qt::DisplayRole,
|
||||
BluetoothDeviceInfoRoleAddress,
|
||||
BluetoothDeviceInfoRoleLe
|
||||
BluetoothDeviceInfoRoleLe,
|
||||
BluetoothDeviceInfoRoleSignalStrength
|
||||
};
|
||||
Q_ENUM(BluetoothDeviceInfoRole)
|
||||
|
||||
explicit BluetoothDeviceInfos(QObject *parent = nullptr);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue