diff --git a/src/winrtble/adapter.rs b/src/winrtble/adapter.rs index c4cba39d..2fec5f60 100644 --- a/src/winrtble/adapter.rs +++ b/src/winrtble/adapter.rs @@ -122,10 +122,15 @@ impl Central for Adapter { self.manager.peripheral(id).ok_or(Error::DeviceNotFound) } - async fn add_peripheral(&self, _address: &PeripheralId) -> Result { - Err(Error::NotSupported( - "Can't add a Peripheral from a BDAddr".to_string(), - )) + async fn add_peripheral(&self, id: &PeripheralId) -> Result { + if let Some(peripheral) = self.manager.peripheral(id) { + return Ok(peripheral); + } + // Create a peripheral straight from its address so a device the OS already knows (bonded or + // connected to another central) can be reached without waiting for an advertisement. + let peripheral = Peripheral::new(Arc::downgrade(&self.manager), id.clone().into()); + self.manager.add_peripheral(peripheral.clone()); + Ok(peripheral) } async fn clear_peripherals(&self) -> Result<()> { diff --git a/src/winrtble/peripheral.rs b/src/winrtble/peripheral.rs index 7924d678..9bab0828 100644 --- a/src/winrtble/peripheral.rs +++ b/src/winrtble/peripheral.rs @@ -671,3 +671,9 @@ impl From for PeripheralId { PeripheralId(address) } } + +impl From for BDAddr { + fn from(id: PeripheralId) -> Self { + id.0 + } +}