Struct esp32_nimble::BLEScan
source · pub struct BLEScan { /* private fields */ }
Implementations§
source§impl BLEScan
impl BLEScan
pub fn active_scan(&mut self, active: bool) -> &mut Self
pub fn filter_duplicates(&mut self, val: bool) -> &mut Self
sourcepub fn limited(&mut self, val: bool) -> &mut Self
pub fn limited(&mut self, val: bool) -> &mut Self
Set whether or not the BLE controller only report scan results from devices advertising in limited discovery mode, i.e. directed advertising.
sourcepub fn filter_policy(&mut self, val: ScanFilterPolicy) -> &mut Self
pub fn filter_policy(&mut self, val: ScanFilterPolicy) -> &mut Self
Sets the scan filter policy.
sourcepub fn on_result(
&mut self,
callback: impl FnMut(&mut Self, &BLEAdvertisedDevice) + Send + Sync + 'static
) -> &mut Self
pub fn on_result( &mut self, callback: impl FnMut(&mut Self, &BLEAdvertisedDevice) + Send + Sync + 'static ) -> &mut Self
Set a callback to be called when a new scan result is detected.
- callback first parameter: The reference to
Self
- callback second parameter: Newly found device
pub fn on_completed( &mut self, callback: impl FnMut() + Send + Sync + 'static ) -> &mut Self
sourcepub async fn find_device(
&mut self,
duration_ms: i32,
callback: impl Fn(&BLEAdvertisedDevice) -> bool + Send + Sync
) -> Result<Option<BLEAdvertisedDevice>, BLEError>
pub async fn find_device( &mut self, duration_ms: i32, callback: impl Fn(&BLEAdvertisedDevice) -> bool + Send + Sync ) -> Result<Option<BLEAdvertisedDevice>, BLEError>
Asynchronously finds a device.
Examples
let ble_device = BLEDevice::take().unwrap();
let ble_scan = ble_device.get_scan();
let name = "Device Name To Be Found";
let device = ble_scan.find_device(10000, |device| device.name() == name).await.unwrap();