br_ble/
lib.rs

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