add query specific peripheral state command.
This commit is contained in:
parent
26165f5d5c
commit
caacc63289
|
@ -1,6 +1,9 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use btleplug::api::{Central as _, Peripheral as _};
|
use btleplug::{
|
||||||
|
api::{Central as _, Peripheral as _},
|
||||||
|
platform::PeripheralId,
|
||||||
|
};
|
||||||
pub use state::{CentralState, ChannelState, PeripheralItem};
|
pub use state::{CentralState, ChannelState, PeripheralItem};
|
||||||
use tauri::{async_runtime::RwLock, AppHandle, Emitter, State};
|
use tauri::{async_runtime::RwLock, AppHandle, Emitter, State};
|
||||||
|
|
||||||
|
@ -79,6 +82,24 @@ pub async fn connected_peripheral_state(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn specific_peripheral_state(
|
||||||
|
app_state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
id: PeripheralId,
|
||||||
|
) -> Result<PeripheralItem, errors::AppError> {
|
||||||
|
let state = app_state.read().await;
|
||||||
|
let central = state
|
||||||
|
.get_central_adapter()
|
||||||
|
.await
|
||||||
|
.ok_or(errors::AppError::BluetoothAdapterNotFound)?;
|
||||||
|
let peripheral = central
|
||||||
|
.peripheral(&id)
|
||||||
|
.await
|
||||||
|
.map_err(|_| errors::AppError::UnableToRetrievePeripheralState)?;
|
||||||
|
let properties = peripheral.properties().await.unwrap_or(None);
|
||||||
|
Ok(PeripheralItem::new(&peripheral, properties.as_ref()).await)
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn channel_a_state(
|
pub async fn channel_a_state(
|
||||||
_app_state: State<'_, Arc<RwLock<AppState>>>,
|
_app_state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
|
|
@ -55,6 +55,7 @@ pub fn run() {
|
||||||
.invoke_handler(generate_handler![
|
.invoke_handler(generate_handler![
|
||||||
cmd::central_device_state,
|
cmd::central_device_state,
|
||||||
cmd::connected_peripheral_state,
|
cmd::connected_peripheral_state,
|
||||||
|
cmd::specific_peripheral_state,
|
||||||
cmd::channel_a_state,
|
cmd::channel_a_state,
|
||||||
cmd::channel_b_state,
|
cmd::channel_b_state,
|
||||||
cmd::activate_central_adapter,
|
cmd::activate_central_adapter,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user