static async Task <bool> Unpair(AnkiBLE.anki_vehicle vehicle) { BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(vehicle.mac_address); DeviceUnpairingResult result = await device.DeviceInformation.Pairing.UnpairAsync(); return(result.Status == DeviceUnpairingResultStatus.Unpaired); }
static async Task <bool> Pair(AnkiBLE.anki_vehicle vehicle) { BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(vehicle.mac_address); DeviceInformationCustomPairing customPairing = device.DeviceInformation.Pairing.Custom; customPairing.PairingRequested += PairingRequestedHandler; DevicePairingResult result = await customPairing.PairAsync(DevicePairingKinds.ConfirmOnly, DevicePairingProtectionLevel.None); customPairing.PairingRequested -= PairingRequestedHandler; return(result.Status == DevicePairingResultStatus.Paired || result.Status == DevicePairingResultStatus.AlreadyPaired); }
private async static Task <GattDeviceService> waitConnection(AnkiBLE.anki_vehicle vehicle) { BluetoothLEDevice bluetoothLeDevice = null; GattDeviceService service = null; bluetoothLeDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(vehicle.mac_address); while (bluetoothLeDevice.ConnectionStatus != BluetoothConnectionStatus.Connected) { throw new Exception("Not connected!"); } service = bluetoothLeDevice.GetGattService(Guid.Parse("be15beef-6186-407e-8381-0bd89c4d8df4")); return(service); }
static async Task <bool> IsPairedUnpair(AnkiBLE.anki_vehicle vehicle) { var selector = BluetoothDevice.GetDeviceSelector(); var devices = await DeviceInformation.FindAllAsync("System.Devices.DevObjectType:= 5 AND System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\" AND (System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#True OR System.Devices.Aep.Bluetooth.IssueInquiry:=System.StructuredQueryType.Boolean#False)"); if (devices.Count() > 0) { BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(vehicle.mac_address); foreach (var dev in devices) { if (dev.Id == device.DeviceInformation.Id) { await Unpair(vehicle); return(true); } } } return(false); }