UNPKG

hfs-bluetooth-adapter

Version:

海富思科技对外提供的蓝牙设备LLSyncSDK

147 lines (131 loc) 3.38 kB
# Hfs-LLSync-Bluetooth-Adapter 由海富思提供给客户的蓝牙设备LLSyncSDK ## SDK使用说明 ### 初始化蓝牙模块 初始化蓝牙模块 会判断用户手机蓝牙状态 ```js import BluetoothAdapter from "hfs-bluetooth-adapter" const blueAdapter = new BluetoothAdapter() //实例化蓝牙适配器 blueAdapter.initBluetooth().then(res=>{}).catch(err=>{}) //初始化蓝牙设配器 ``` ### 搜索蓝牙设备 在初始化后进行 ```js //传入一个配置项 onSearch为搜索到设备时的回调函数 blueAdapter.startSearch({ onSearch(res){ //返回附近设备列表 console.log(res); }, onError(err){ console.log(err); } }) ``` ### 停止搜索蓝牙设备 ```js blueAdapter.stopSearch() ``` ### 连接蓝牙设备 传入一个设备对象 startSearch的onSearch回调函数返回的设备对象 返回一个连接成功后蓝牙设备对应的设备适配器 ```js const deviceAdapter = await blueAdapter.connectDevice(device) ``` ### 绑定设备 通过设备适配器进行绑定设备 ```js const deviceAdapter = await bluetoothAdapter.connectDevice(device) deviceAdapter.bindDevice().then(res=>{ console.log(res.deviceName) //返回设备名称 }) ``` ### 搜索单个蓝牙设备 传入设备名称 ```js const device = await bluetoothAdapter.searchDevice({ deviceName }) ``` ### 断开蓝牙设备连接 ```js deviceAdapter.disconnectDevice() ``` ### 添加指纹密码 ```js deviceAdapter.addFP({ name start_effective_time//有效起始时间 传空为永久有效 需要进行特殊处理 具体看demo end_effective_time//有效结束时间 传空为永久有效 },(res)=>{ //res返回添加指纹状态 result:0添加失败 1-4指纹采集次数 5添加成功 B移开手指 C指纹模块错误 D指纹已满 E锁端退出添加指纹 Toast.loading({ message: res.msg, forbidClick: true, duration: 0, }) if(res.result == 5){ Toast("添加指纹用户成功") } }) ``` ### 添加密码 ```js deviceAdapter.addPwd({ name password start_effective_time end_effective_time }).then(res=>{ //result 1成功 0失败 if(res.result == 1){ Toast("添加密码用户成功") } }) ``` ### 添加卡片密码 ```js deviceAdapter.addRfCard({ name start_effective_time end_effective_time },(res)=>{ //1 用户已刷卡 0为未刷卡 if(res.result == 1){ Toast("添加卡片用户成功") } }) ``` ### 删除密码 ```js deviceAdapter.deletePwd({ pwdIdGroup:[1,2,3] //密码Id的数组 可以进行批量删除 }).then(res=>{ //result 1成功 0失败 console.log(res.result); }) ``` ### 获取密码列表 ```js deviceAdapter.getAllPwd().then(res=>{ //密码列表 console.log(res.result); }) ``` ### 获取开锁日志 ```js deviceAdapter.getHistory({ start_effective_time //开始日期 end_effective_time //结束日期 时间戳是秒级 }).then(res=>{ //日志数组 console.log(res.result); }) ``` ### 解绑设备 解绑后 该设备会重新被startSearch函数搜索到 ```js deviceAdapter.unbindDevice().then(res=>{ //result 1成功 0失败 console.log(res.result); }) ```