Struct esp32_nimble::BLEScan

source ·
pub struct BLEScan { /* private fields */ }
Expand description

Scan for ble devices.

§Examples

let ble_device = BLEDevice::take();
let ble_scan = BLEScan::new();
let name = "Device Name To Be Found";
let device = ble_scan
  .start(ble_device, 10000, |device, data| {
    if let Some(device_name) = data.name() {
      if device_name == name {
        return Some(*device);
      }
    }
    None
  })
  .await
  .unwrap();

Implementations§

source§

impl BLEScan

source

pub fn new() -> Self

source

pub fn active_scan(&mut self, active: bool) -> &mut Self

source

pub fn filter_duplicates(&mut self, val: bool) -> &mut Self

source

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.

source

pub fn filter_policy(&mut self, val: ScanFilterPolicy) -> &mut Self

Sets the scan filter policy.

source

pub fn interval(&mut self, interval_msecs: u16) -> &mut Self

Set the interval to scan.

source

pub fn window(&mut self, window_msecs: u16) -> &mut Self

Set the window to actively scan.

source

pub async fn start<F, R>( &mut self, _ble_device: &BLEDevice, duration_ms: i32, callback: F, ) -> Result<Option<R>, BLEError>
where F: FnMut(&BLEAdvertisedDevice, BLEAdvertisedData<&[u8]>) -> Option<R>,

The callback function must return Option type. If it returns None, the scan continues. If Some(r) is returned, the scan stops and the start function returns the return value of the callback.

Auto Trait Implementations§

§

impl !Freeze for BLEScan

§

impl !RefUnwindSafe for BLEScan

§

impl Send for BLEScan

§

impl Sync for BLEScan

§

impl Unpin for BLEScan

§

impl UnwindSafe for BLEScan

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.