pub struct Adapter { /* private fields */ }Expand description
The system’s Bluetooth adapter interface.
Implementations§
Source§impl Adapter
impl Adapter
Sourcepub async fn default() -> Option<Self>
pub async fn default() -> Option<Self>
Creates an interface to a Bluetooth adapter using the default config.
Sourcepub async fn with_config(config: AdapterConfig) -> Result<Self>
pub async fn with_config(config: AdapterConfig) -> Result<Self>
Creates an interface to a Bluetooth adapter. The vm pointer will be ignored
if this has been called previously.
Sourcepub async fn events(
&self,
) -> Result<impl Stream<Item = Result<AdapterEvent>> + Send + Unpin + '_>
pub async fn events( &self, ) -> Result<impl Stream<Item = Result<AdapterEvent>> + Send + Unpin + '_>
A stream of AdapterEvent which allows the application to identify when the adapter is enabled or disabled.
Sourcepub async fn wait_available(&self) -> Result<()>
pub async fn wait_available(&self) -> Result<()>
Asynchronously blocks until the adapter is available.
Sourcepub async fn is_available(&self) -> Result<bool>
pub async fn is_available(&self) -> Result<bool>
Check if the adapter is available.
Sourcepub async fn open_device(&self, id: &DeviceId) -> Result<Device>
pub async fn open_device(&self, id: &DeviceId) -> Result<Device>
Attempts to create the device identified by id.
Sourcepub async fn connected_devices(&self) -> Result<Vec<Device>>
pub async fn connected_devices(&self) -> Result<Vec<Device>>
Finds all connected Bluetooth LE devices.
NOTE: there might be BLE devices connected outside this library.
If AdapterConfig::allow_multiple_connections is set to true, this method will call
BluetoothManager.getConnectedDevices() and ensure GATT connections are created
for them in this library instance.
Sourcepub async fn connected_devices_with_services(
&self,
service_ids: &[Uuid],
) -> Result<Vec<Device>>
pub async fn connected_devices_with_services( &self, service_ids: &[Uuid], ) -> Result<Vec<Device>>
Finds all connected devices providing any service in service_ids.
Sourcepub async fn scan<'a>(
&'a self,
service_ids: &'a [Uuid],
) -> Result<impl Stream<Item = AdvertisingDevice> + Send + Unpin + 'a>
pub async fn scan<'a>( &'a self, service_ids: &'a [Uuid], ) -> Result<impl Stream<Item = AdvertisingDevice> + Send + Unpin + 'a>
Starts scanning for Bluetooth advertising packets.
Returns a stream of AdvertisingDevice structs which contain the data from the advertising packet and the
Device which sent it. Scanning is automatically stopped when the stream is dropped. Inclusion of duplicate
packets is a platform-specific implementation detail.
If service_ids is not empty, returns advertisements including at least one GATT service with a UUID in
services. Otherwise returns all advertisements.
Sourcepub async fn discover_devices<'a>(
&'a self,
services: &'a [Uuid],
) -> Result<impl Stream<Item = Result<Device>> + Send + Unpin + 'a>
pub async fn discover_devices<'a>( &'a self, services: &'a [Uuid], ) -> Result<impl Stream<Item = Result<Device>> + Send + Unpin + 'a>
Finds Bluetooth devices providing any service in services.
Returns a stream of Device structs with matching connected devices returned first. If the stream is not
dropped before all matching connected devices are consumed then scanning will begin for devices advertising any
of the services. Scanning will continue until the stream is dropped. Inclusion of duplicate devices is a
platform-specific implementation detail.
Sourcepub async fn disconnect_device(&self, device: &Device) -> Result<()>
pub async fn disconnect_device(&self, device: &Device) -> Result<()>
Disconnects from the Device.
XXX: manage to call this internally when all API wrapper objects for the device are dropped.
Sourcepub async fn device_connection_events<'a>(
&'a self,
device: &'a Device,
) -> Result<impl Stream<Item = ConnectionEvent> + Send + Unpin + 'a>
pub async fn device_connection_events<'a>( &'a self, device: &'a Device, ) -> Result<impl Stream<Item = ConnectionEvent> + Send + Unpin + 'a>
Monitors a device for connection/disconnection events.
This monitors only devices connected/disconnected in this library instance, even if AdapterConfig::allow_multiple_connections is set to true.
This does not work with random address devices.