Skip to content

Commit

Permalink
Fixed AdvertisementReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
AskBojesen committed May 8, 2024
1 parent 3525524 commit 24b56c4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Source/Plugin.BLE/Windows/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,14 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
{
var deviceId = btAdv.BluetoothAddress.ParseDeviceId();

if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device) && device != null)
if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device))
{
// This deviceId has been discovered
Trace.Message("AdvReceived - Old: {0}", btAdv.ToDetailedString(device.Name));
(device as Device)?.Update(btAdv.RawSignalStrengthInDBm, ParseAdvertisementData(btAdv.Advertisement));
this.HandleDiscoveredDevice(device);
}
if (device == null)
HandleDiscoveredDevice(device);
}
else
{
var bluetoothLeDevice = BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress).AsTask().Result;
if (bluetoothLeDevice != null) //make sure advertisement bluetooth address actually returns a device
Expand All @@ -282,13 +283,8 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
deviceId,
ParseAdvertisementData(btAdv.Advertisement),
btAdv.IsConnectable);
Trace.Message("AdvReceived - New: {0}", btAdv.ToDetailedString(device.Name));
_ = DiscoveredDevicesRegistry.TryRemove(deviceId, out _);
this.HandleDiscoveredDevice(device);
}
else
{
DiscoveredDevicesRegistry[deviceId] = null;
Trace.Message("AdvReceived - New: {0}", btAdv.ToDetailedString(device.Name));
HandleDiscoveredDevice(device);
}
}
}
Expand Down

0 comments on commit 24b56c4

Please sign in to comment.