微信小程序使用蓝牙小插件
本文实例为大家分享了微信小程序使用蓝牙小插件,供大家参考,具体内容如下
bluetooth.js
functionBLE(options){
this.options=options||{locator:{}};
}
functionab2hex(buffer){
consthexArr=Array.prototype.map.call(
newUint8Array(buffer),
function(bit){
return('00'+bit.toString(16)).slice(-2)
}
)
returnhexArr.join('-')
};
BLE.prototype={
open:function(callback){//打开适配器成功调用callback();
wx.openBluetoothAdapter({
success(res){
if(typeofcallback!="undefined"){
callback();
}
},
fail(res){
console.log(res)
}
})
},
scan:function(callback){//扫描设备成功调用callback(ls);
wx.startBluetoothDevicesDiscovery({
success(res){
wx.getBluetoothDevices({
success(res){
console.log(res);
varls=[];
for(vari=0;i
index.js
constBle=require('../../lib/bluetooch/bluetooch');
varble=newBle.BLE();
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短