br_ble/
lib.rs

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