Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/winrtble/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ impl Central for Adapter {
self.manager.peripheral(id).ok_or(Error::DeviceNotFound)
}

async fn add_peripheral(&self, _address: &PeripheralId) -> Result<Peripheral> {
Err(Error::NotSupported(
"Can't add a Peripheral from a BDAddr".to_string(),
))
async fn add_peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
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<()> {
Expand Down
6 changes: 6 additions & 0 deletions src/winrtble/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,9 @@ impl From<BDAddr> for PeripheralId {
PeripheralId(address)
}
}

impl From<PeripheralId> for BDAddr {
fn from(id: PeripheralId) -> Self {
id.0
}
}
Loading