private Stream GetBleStream(IBluetoothLowEnergyDevice device) { var stream = new BluetoothLowEnergyStream(device, () => { _acceptedDevices.Remove(device); _adapter.DisconnectDevice(device); }); _acceptedDevices.Add(device); return(stream); }
public void DisconnectDevice(IBluetoothLowEnergyDevice device) { if (device is BleDevice wrap) { _adapter.DisconnectDevice(wrap.Device); } else { throw new InvalidOperationException( $"Only pass {nameof(IBluetoothLowEnergyDevice)} instances that were retrieved from the {nameof(ConnectedDevices)} list"); } }
public BluetoothLowEnergyStream(IBluetoothLowEnergyDevice device, Action onDispose) { _device = device; _onDispose = onDispose; var tcs = new TaskCompletionSource <int>(); _device.DiscoverServicesAsync().ContinueWith(async _ => { await ServicesDiscovered(); tcs.SetResult(0); }); _initializationTask = tcs.Task; }
public bool Equals(IBluetoothLowEnergyDevice other) { return(other is BleDevice otherDevice && Device == otherDevice.Device); }