br_ble/
lib.rs

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