Skip to content

Commit

Permalink
Enable device blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Oct 12, 2022
1 parent 75ffd2e commit 735e632
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 29 deletions.
31 changes: 18 additions & 13 deletions qml/DeviceBrowser.qml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ Item {
border.color: Theme.colorSeparator
border.width: 1

MouseArea {
anchors.fill: parent
onClicked: parent.visible = false
}

IconSvg {
width: 28
height: 28
anchors.top: parent.top
anchors.topMargin: 8
anchors.left: parent.left
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter

source: "qrc:/assets/icons_material/outline-info-24px.svg"
color: Theme.colorIcon
Expand All @@ -116,7 +122,7 @@ Item {
anchors.right: parent.right
anchors.rightMargin: 8

text: qsTr("The device browser help you locate nearby BLE devices.")
text: qsTr("The device browser help you locate nearby BLE devices. You can also use this screen to blacklist sensors so the scan don't pick them up.")
textFormat: Text.StyledText
wrapMode: Text.WordWrap
color: Theme.colorSubText
Expand Down Expand Up @@ -192,6 +198,11 @@ Item {
border.color: Theme.colorSeparator
border.width: 1

MouseArea {
anchors.fill: parent
onClicked: parent.visible = false
}

IconSvg {
width: 28
height: 28
Expand All @@ -212,7 +223,7 @@ Item {
anchors.right: parent.right
anchors.rightMargin: 8

text: qsTr("The device browser help you locate nearby BLE devices.")
text: qsTr("The device browser help you locate nearby BLE devices. You can also use this screen to blacklist sensors so the scan don't pick them up.")
textFormat: Text.StyledText
wrapMode: Text.WordWrap
color: Theme.colorSubText
Expand Down Expand Up @@ -326,7 +337,7 @@ Item {
property real alpha: Math.random() * (3.14/2) + (3.14/4)
property real a: c * Math.cos(alpha)
property real b: c * Math.sin(alpha)
property real c: radar.height * Math.abs(((boxDevice.rssi)+10) / 100)
property real c: radar.height * Math.abs(((boxDevice.rssi)+12) / 100)

x: (radar.width / 2) - a
y: radar.height - b
Expand All @@ -350,15 +361,9 @@ Item {
}

color: {
if (boxDevice.rssi < 0) {
if (boxDevice.rssi > -65) return Theme.colorGreen
if (boxDevice.rssi > -85) return Theme.colorOrange
if (boxDevice.rssi > -100) return Theme.colorRed
} else {
if (boxDevice.rssi < 65) return Theme.colorGreen
if (boxDevice.rssi < 85) return Theme.colorOrange
if (boxDevice.rssi < 100) return Theme.colorRed
}
if (Math.abs(boxDevice.rssi) < 65) return Theme.colorGreen
if (Math.abs(boxDevice.rssi) < 85) return Theme.colorOrange
if (Math.abs(boxDevice.rssi) < 100) return Theme.colorRed
return Theme.colorRed
}

Expand Down
52 changes: 41 additions & 11 deletions qml/DeviceNearbyWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import "qrc:/js/UtilsDeviceSensors.js" as UtilsDeviceSensors

Rectangle {
id: deviceNearbyWidget
implicitWidth: 640
implicitWidth: 480
implicitHeight: 48

opacity: (device.rssi < 0) ? 1 : 0.66
color: (device.selected) ? Theme.colorForeground : Theme.colorBackground

property var device: pointer
property bool deviceSupported: UtilsDeviceSensors.isDeviceSupported(device.deviceName)
property bool deviceSupported: true // UtilsDeviceSensors.isDeviceSupported(device.deviceName)
property bool deviceBlacklisted: deviceManager.isBleDeviceBlacklisted(device.deviceAddress)

Connections {
Expand Down Expand Up @@ -63,6 +63,42 @@ Rectangle {

////////

IconSvg {
anchors.verticalCenter: parent.verticalCenter

width: 20
height: 20
visible: deviceSupported
enabled: true

source: deviceBlacklisted ? "qrc:/assets/icons_material/outline-remove_circle-24px.svg"
: "qrc:/assets/icons_material/outline-add_circle-24px.svg"
color: {
if (ma.hovered) return Theme.colorPrimary
if (deviceBlacklisted) return Theme.colorRed
return Theme.colorIcon
}

MouseArea {
id: ma
anchors.fill: parent

hoverEnabled: true
property bool hovered: false
onEntered: hovered = true
onExited: hovered = false
onCanceled: hovered = false

onClicked: {
confirmBlacklistDevice.deviceName = device.deviceName
confirmBlacklistDevice.deviceAddress = device.deviceAddress
confirmBlacklistDevice.open()
}
}
}

////////

Rectangle {
id: barbg
anchors.verticalCenter: parent.verticalCenter
Expand All @@ -79,15 +115,9 @@ Rectangle {
width: parent.width * Math.abs(device.rssi / 100)
radius: 3
color: {
if (device.rssi < 0) {
if (device.rssi > -65) return Theme.colorGreen
if (device.rssi > -85) return Theme.colorOrange
if (device.rssi > -100) return Theme.colorRed
} else {
if (device.rssi < 65) return Theme.colorGreen
if (device.rssi < 85) return Theme.colorOrange
if (device.rssi < 100) return Theme.colorRed
}
if (Math.abs(device.rssi) < 65) return Theme.colorGreen
if (Math.abs(device.rssi) < 85) return Theme.colorOrange
if (Math.abs(device.rssi) < 100) return Theme.colorRed
return Theme.colorRed
}

Expand Down
5 changes: 2 additions & 3 deletions src/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,14 +1324,13 @@ void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
// Various sanity checks
{
if (info.rssi() >= 0) return; // we probably just hit the device cache

if (info.isCached()) return; // we probably just hit the device cache
if ((info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) == false) return; // not a BLE device
if (m_devices_blacklist.contains(info.address().toString())) return; // device is blacklisted

SettingsManager *sm = SettingsManager::getInstance();
if (sm && sm->getBluetoothLimitScanningRange() && info.rssi() < -70) return; // device is too far away

if ((info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) == false) return; // not a BLE device

for (auto ed: qAsConst(m_devices_model->m_devices)) // device is already in the UI
{
Device *edd = qobject_cast<Device*>(ed);
Expand Down
7 changes: 5 additions & 2 deletions src/DeviceManager_advertisement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
//qDebug() << "updateBleDevice() " << info.name() << info.address(); // << info.deviceUuid() // << " updatedFields: " << updatedFields
bool status = false;

// We don't use QBluetoothDeviceInfo::Fields, it's unreliable
Q_UNUSED(updatedFields)
Q_UNUSED(updatedFields) // We don't use QBluetoothDeviceInfo::Fields, it's unreliable

if (info.rssi() >= 0) return; // we probably just hit the device cache
if (info.isCached()) return; // we probably just hit the device cache
if ((info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) == false) return; // not a BLE device
if (m_devices_blacklist.contains(info.address().toString())) return; // device is blacklisted
//if (info.name().isEmpty()) return; // skip beacons
if (info.name().replace('-', ':') == info.address().toString()) return; // skip beacons

Expand Down

0 comments on commit 735e632

Please sign in to comment.