br_ble/
lib.rs

1use std::collections::HashMap;
2use crate::device::{Characteristic, Device};
3
4
5#[cfg(target_os = "macos")]
6pub mod mac;
7#[cfg(target_os = "windows")]
8pub mod win;
9pub mod device;
10pub fn run<F>(factory: F)
11where
12    F: Fn() -> Box<dyn Handler>,
13{
14    #[cfg(target_os = "windows")]
15    win::Win::new().run(factory);
16    #[cfg(target_os = "macos")]
17    mac::Mac::new().run(factory);
18}
19
20
21pub trait Handler {
22    /// 蓝牙适配器开启
23    fn on_adapter_open(&mut self);
24    /// 蓝牙适配器关闭
25    fn on_adapter_close(&mut self);
26    /// 发现设备
27    fn on_discover(&mut self, device: Device);
28    /// 获取设备列表
29    fn listen_connected(&mut self, device_list: Vec<String>);
30    /// 连接成功通知
31    fn on_connect(&mut self, uuid: String);
32    /// 未连接通知
33    fn on_unconnect(&mut self, uuid: String);
34    /// 设备关闭
35    /// * uuid 设备uuid
36    fn on_disconnect(&mut self, uuid: String);
37    /// 特征发现通知
38    fn on_characteristics(&mut self, uuid: String, characteristic: Characteristic);
39    /// 开始监听具体接口
40    fn listen(&mut self, uuid: String);
41
42    /// 接收具体接口数据
43    fn on_data(&mut self, uuid: String, characteristic_uuid: String, data: Vec<u8>);
44}