@@ -58,16 +58,21 @@ public UWPBluetoothManager(IButtplugLogManager aLogManager)
5858 private async void OnAdvertisementReceived ( BluetoothLEAdvertisementWatcher aObj ,
5959 BluetoothLEAdvertisementReceivedEventArgs aEvent )
6060 {
61+ var advertName = aEvent . Advertisement . LocalName ;
62+ var advertGUIDs = new List < Guid > ( ) ;
63+ advertGUIDs . AddRange ( aEvent . Advertisement . ServiceUuids ) ;
64+ var btAddr = aEvent . BluetoothAddress ;
65+
6166 // BpLogger.Trace($"Got BLE Advertisement for device: {aEvent.Advertisement.LocalName} / {aEvent.BluetoothAddress}");
62- if ( _currentlyConnecting . Contains ( aEvent . BluetoothAddress ) )
67+ if ( _currentlyConnecting . Contains ( btAddr ) )
6368 {
6469 // BpLogger.Trace($"Ignoring advertisement for already connecting device: {aEvent.Advertisement.LocalName} / {aEvent.BluetoothAddress}");
6570 return ;
6671 }
6772
68- BpLogger . Trace ( "BLE device found: " + aEvent . Advertisement . LocalName ) ;
73+ BpLogger . Trace ( "BLE device found: " + advertName ) ;
6974 var factories = from x in _deviceFactories
70- where x . MayBeDevice ( aEvent . Advertisement )
75+ where x . MayBeDevice ( advertName , advertGUIDs )
7176 select x ;
7277
7378 // We should always have either 0 or 1 factories.
@@ -76,7 +81,7 @@ where x.MayBeDevice(aEvent.Advertisement)
7681 {
7782 if ( buttplugBluetoothDeviceFactories . Any ( ) )
7883 {
79- BpLogger . Warn ( $ "Found multiple BLE factories for { aEvent . Advertisement . LocalName } { aEvent . BluetoothAddress } :") ;
84+ BpLogger . Warn ( $ "Found multiple BLE factories for { advertName } { btAddr } :") ;
8085 buttplugBluetoothDeviceFactories . ToList ( ) . ForEach ( x => BpLogger . Warn ( x . GetType ( ) . Name ) ) ;
8186 }
8287 else
@@ -87,12 +92,12 @@ where x.MayBeDevice(aEvent.Advertisement)
8792 return ;
8893 }
8994
90- _currentlyConnecting . Add ( aEvent . BluetoothAddress ) ;
95+ _currentlyConnecting . Add ( btAddr ) ;
9196 var factory = buttplugBluetoothDeviceFactories . First ( ) ;
9297 BpLogger . Debug ( $ "Found BLE factory: { factory . GetType ( ) . Name } ") ;
9398
9499 // If we actually have a factory for this device, go ahead and create the device
95- var fromBluetoothAddressAsync = BluetoothLEDevice . FromBluetoothAddressAsync ( aEvent . BluetoothAddress ) ;
100+ var fromBluetoothAddressAsync = BluetoothLEDevice . FromBluetoothAddressAsync ( btAddr ) ;
96101 if ( fromBluetoothAddressAsync != null )
97102 {
98103 var dev = await fromBluetoothAddressAsync ;
@@ -108,13 +113,13 @@ where x.MayBeDevice(aEvent.Advertisement)
108113 catch ( Exception ex )
109114 {
110115 BpLogger . Error (
111- $ "Cannot connect to device { aEvent . Advertisement . LocalName } { aEvent . BluetoothAddress } : { ex . Message } ") ;
112- _currentlyConnecting . Remove ( aEvent . BluetoothAddress ) ;
116+ $ "Cannot connect to device { advertName } { btAddr } : { ex . Message } ") ;
117+ _currentlyConnecting . Remove ( btAddr ) ;
113118 return ;
114119 }
115120 }
116121
117- _currentlyConnecting . Remove ( aEvent . BluetoothAddress ) ;
122+ _currentlyConnecting . Remove ( btAddr ) ;
118123 }
119124
120125 private void OnWatcherStopped ( BluetoothLEAdvertisementWatcher aObj ,
0 commit comments