diff --git a/fastpair/rust/src/main.rs b/fastpair/rust/src/main.rs index 56b290a3..b7cb0937 100644 --- a/fastpair/rust/src/main.rs +++ b/fastpair/rust/src/main.rs @@ -28,34 +28,41 @@ fn main() -> Result<(), Box> { while let Ok(ble_device) = adapter.next_device().await { let name = ble_device.name()?; - if name.contains("LE_WF-1000XM3") { - println!("FOUND {} ", name); + for service_data in ble_device.service_data() { + let uuid = service_data.uuid(); - let addr: Address = ble_device.address(); + // This is a Fast Pair device. + if uuid == 0x2cfe { + if name.contains("LE_WF-1000XM3") { + println!("FOUND {} ", name); - // Dynamic dispatch is necessary here because `BleDevice` and - // `ClassicDevice` share the `Device` trait (and thus must have - // the same return type for `address()` method). This can be - // changed later if `Device` trait should exclusively define - // shared cross-platform behavior. - let classic_addr = match addr { - Address::Ble(ble) => ClassicAddress::try_from(ble), - Address::Classic(_) => unreachable!( + let addr: Address = ble_device.address(); + + // Dynamic dispatch is necessary here because `BleDevice` and + // `ClassicDevice` share the `Device` trait (and thus must have + // the same return type for `address()` method). This can be + // changed later if `Device` trait should exclusively define + // shared cross-platform behavior. + let classic_addr = match addr { + Address::Ble(ble) => ClassicAddress::try_from(ble), + Address::Classic(_) => panic!( "Address should come from BLE Device, therefore \ shouldn't be Classic." ), - }?; + }?; - let classic_device = - bluetooth::new_classic_device(classic_addr).await?; + let classic_device = + bluetooth::new_classic_device(classic_addr).await?; - match classic_device.pair().await { - Ok(_) => { - println!("Pairing success!"); + match classic_device.pair().await { + Ok(_) => { + println!("Pairing success!"); + } + Err(err) => println!("Error {}", err), + } + break; } - Err(err) => println!("Error {}", err), } - break; } } println!("Done scanning");