From e952a3f5e4373d025d42b7067af5c16cc75e3f6d Mon Sep 17 00:00:00 2001 From: Przemyslaw Wegrzyn Date: Sun, 6 Oct 2024 23:07:32 +0200 Subject: [PATCH] FIx examples to work with BLEDevice::new_client() call --- examples/ble_client.rs | 4 ++-- examples/ble_l2cap_client.rs | 4 ++-- examples/ble_secure_client.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/ble_client.rs b/examples/ble_client.rs index c6a19d4..3005983 100644 --- a/examples/ble_client.rs +++ b/examples/ble_client.rs @@ -1,5 +1,5 @@ use bstr::ByteSlice; -use esp32_nimble::{uuid128, BLEClient, BLEDevice, BLEScan}; +use esp32_nimble::{uuid128, BLEDevice, BLEScan}; use esp_idf_svc::hal::{ prelude::Peripherals, task::block_on, @@ -31,7 +31,7 @@ fn main() -> anyhow::Result<()> { .await?; if let Some(device) = device { - let mut client = BLEClient::new(); + let mut client = ble_device.new_client(); client.on_connect(|client| { client.update_conn_params(120, 120, 0, 60).unwrap(); }); diff --git a/examples/ble_l2cap_client.rs b/examples/ble_l2cap_client.rs index 709a767..9ef6fc1 100644 --- a/examples/ble_l2cap_client.rs +++ b/examples/ble_l2cap_client.rs @@ -1,6 +1,6 @@ use bstr::ByteSlice; use core::str; -use esp32_nimble::{l2cap::L2capClient, BLEClient, BLEDevice, BLEScan}; +use esp32_nimble::{l2cap::L2capClient, BLEDevice, BLEScan}; use esp_idf_svc::hal::task::block_on; fn main() -> anyhow::Result<()> { @@ -25,7 +25,7 @@ fn main() -> anyhow::Result<()> { .await?; if let Some(device) = device { - let mut client = BLEClient::new(); + let mut client = ble_device.new_client(); client.connect(&device.addr()).await.unwrap(); let mut l2cap = L2capClient::connect(&client, 0x1002, 512).await.unwrap(); diff --git a/examples/ble_secure_client.rs b/examples/ble_secure_client.rs index 7fcfc20..19d43d0 100644 --- a/examples/ble_secure_client.rs +++ b/examples/ble_secure_client.rs @@ -1,4 +1,4 @@ -use esp32_nimble::{enums::*, utilities::BleUuid, BLEClient, BLEDevice, BLEScan}; +use esp32_nimble::{enums::*, utilities::BleUuid, BLEDevice, BLEScan}; use esp_idf_svc::hal::task::block_on; use log::*; @@ -9,9 +9,9 @@ fn main() -> anyhow::Result<()> { esp_idf_svc::log::EspLogger::initialize_default(); block_on(async { - let device = BLEDevice::take(); - device.set_power(PowerType::Default, PowerLevel::P9)?; - device + let ble_device = BLEDevice::take(); + ble_device.set_power(PowerType::Default, PowerLevel::P9)?; + ble_device .security() .set_auth(AuthReq::all()) .set_io_cap(SecurityIOCap::KeyboardOnly); @@ -22,7 +22,7 @@ fn main() -> anyhow::Result<()> { .active_scan(true) .interval(100) .window(99) - .start(device, 10000, |device, data| { + .start(ble_device, 10000, |device, data| { if data.is_advertising_service(&SERVICE_UUID) { return Some(*device); } @@ -37,7 +37,7 @@ fn main() -> anyhow::Result<()> { info!("Advertised Device: {:?}", device); - let mut client = BLEClient::new(); + let mut client = ble_device.new_client(); client.connect(&device.addr()).await?; client.on_passkey_request(|| 123456); client.secure_connection().await?;