Skip to content

Commit

Permalink
Updated version and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MnlPhlp committed Dec 18, 2024
1 parent d4220fe commit 218a59c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-blec"
license = "MIT OR Apache-2.0"
version = "0.2.0"
version = "0.3.0"
authors = ["Manuel Philipp"]
description = "BLE-Client plugin for Tauri"
edition = "2021"
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let address = ...
await connect(address, () => console.log('disconnected'))
// send some text to a characteristic
const CHARACTERISTIC_UUID = '51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B'
await sendString(CHARACTERISTIC_UUID, 'Test')
await sendString(CHARACTERISTIC_UUID, 'Test', 'withResponse')
```

## Usage in Backend
Expand All @@ -75,14 +75,13 @@ This means if you connect from the frontend you can send data from rust without

```rs
use uuid::{uuid, Uuid};
use tauri_plugin_blec::models::WriteType;

const CHARACTERISTIC_UUID: Uuid = uuid!("51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B");
const DATA: [u8; 500] = [0; 500];
let handler = tauri_plugin_blec::get_handler().unwrap();
handler
.lock()
.await
.send_data(CHARACTERISTIC_UUID, &DATA)
.send_data(CHARACTERISTIC_UUID, &DATA, WriteType::WithResponse)
.await
.unwrap();
```
20 changes: 11 additions & 9 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Handler {
/// use tauri::async_runtime;
/// async_runtime::block_on(async {
/// let handler = tauri_plugin_blec::get_handler().unwrap();
/// handler.lock().await.connect("00:00:00:00:00:00".to_string(),Some(|| println!("disconnected"))).await.unwrap();
/// handler.connect("00:00:00:00:00:00", Some(Box::new(|| println!("disconnected")))).await.unwrap();
/// });
/// ```
pub async fn connect(
Expand Down Expand Up @@ -321,14 +321,12 @@ impl Handler {
Ok(())
}

/// Scans for [timeout] milliseconds and periodically sends discovered devices
/// Scans for `timeout` milliseconds and periodically sends discovered devices
/// to the given channel.
/// A task is spawned to handle the scan and send the devices, so the function
/// returns immediately.
///
/// A list of Service UUIDs can be provided to filter the devices discovered.
/// Devices that provide at least one of the services in the list will be included.
/// An empty list will include all devices.
/// A Variant of [`ScanFilter`] can be provided to filter the discovered devices
///
/// # Errors
/// Returns an error if starting the scan fails
Expand All @@ -338,10 +336,12 @@ impl Handler {
/// ```no_run
/// use tauri::async_runtime;
/// use tokio::sync::mpsc;
/// use tauri_plugin_blec::models::ScanFilter;
///
/// async_runtime::block_on(async {
/// let handler = tauri_plugin_blec::get_handler().unwrap();
/// let (tx, mut rx) = mpsc::channel(1);
/// handler.lock().await.discover(Some(tx),1000).await.unwrap();
/// handler.discover(Some(tx),1000, ScanFilter::None).await.unwrap();
/// while let Some(devices) = rx.recv().await {
/// println!("Discovered {devices:?}");
/// }
Expand Down Expand Up @@ -499,11 +499,13 @@ impl Handler {
/// ```no_run
/// use tauri::async_runtime;
/// use uuid::{Uuid,uuid};
/// use tauri_plugin_blec::models::WriteType;
///
/// const CHARACTERISTIC_UUID: Uuid = uuid!("51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B");
/// async_runtime::block_on(async {
/// let handler = tauri_plugin_blec::get_handler().unwrap();
/// let data = [1,2,3,4,5];
/// let response = handler.lock().await.send_data(CHARACTERISTIC_UUID,&data).await.unwrap();
/// let response = handler.send_data(CHARACTERISTIC_UUID,&data, WriteType::WithResponse).await.unwrap();
/// });
/// ```
pub async fn send_data(
Expand Down Expand Up @@ -532,7 +534,7 @@ impl Handler {
/// const CHARACTERISTIC_UUID: Uuid = uuid!("51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B");
/// async_runtime::block_on(async {
/// let handler = tauri_plugin_blec::get_handler().unwrap();
/// let response = handler.lock().await.recv_data(CHARACTERISTIC_UUID).await.unwrap();
/// let response = handler.recv_data(CHARACTERISTIC_UUID).await.unwrap();
/// });
/// ```
pub async fn recv_data(&self, c: Uuid) -> Result<Vec<u8>, Error> {
Expand All @@ -556,7 +558,7 @@ impl Handler {
/// const CHARACTERISTIC_UUID: Uuid = uuid!("51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B");
/// async_runtime::block_on(async {
/// let handler = tauri_plugin_blec::get_handler().unwrap();
/// let response = handler.lock().await.subscribe(CHARACTERISTIC_UUID,|data| println!("received {data:?}")).await.unwrap();
/// let response = handler.subscribe(CHARACTERISTIC_UUID,|data| println!("received {data:?}")).await.unwrap();
/// });
/// ```
pub async fn subscribe(
Expand Down
2 changes: 2 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ impl From<WriteType> for btleplug::api::WriteType {
}
}

/// Filter for discovering devices.
/// Only devices matching the filter will be returned by the handler::discover method
pub enum ScanFilter {
None,
/// Matches if the device advertises the specified service.
Expand Down

0 comments on commit 218a59c

Please sign in to comment.