|
@@ -45,21 +45,46 @@ Page({
|
|
|
onShow() {
|
|
|
var that = this;
|
|
|
if (!that.data.isOne) {
|
|
|
- thithats.Search();
|
|
|
+ that.Search();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ ///开始或结束,也可以过滤名称
|
|
|
+ Search: function () {
|
|
|
+ xBlufi.notifyStartDiscoverBle({
|
|
|
+ 'isStart': true,
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
// {"type":" 41","result":true,"data":{"errno":0,"errCode":0,"isDiscovering":true,"errMsg":"startBluetoothDevicesDiscovery:ok"}}
|
|
|
- // deviceConnect2.js:50 gadsfasdfqwerqwerqwerqer==={"type":"1","result":true,"data":[{"deviceId":"57:F6:7D:62:D6:C0","name":"","RSSI":-97,"connectable":true,"advertisData":"4c0010072a1fbee24315680100100000000000000000000000000000","advertisServiceUUIDs":[],"localName":"","serviceData":{}}]}
|
|
|
+ // {"type":"1","result":true,"data":[{"deviceId":"57:F6:7D:62:D6:C0","name":"","RSSI":-97,"connectable":true,"advertisData":"4c0010072a1fbee24315680100100000000000000000000000000000","advertisServiceUUIDs":[],"localName":"","serviceData":{}}]}
|
|
|
// {"type":"1","result":true,"data":[{"deviceId":"57:F6:7D:62:D6:C0","name":"","RSSI":-97,"connectable":true,"advertisData":"4c0010072a1fbee24315680100100000000000000000000000000000","advertisServiceUUIDs":[],"localName":"","serviceData":{}},{"deviceId":"42:E0:22:C2:6E:25","name":"","RSSI":-92,"connectable":true,"advertisData":"4c001007221fa8d7a84ba8","advertisServiceUUIDs":[],"localName":"","serviceData":{}}]}
|
|
|
funListenDeviceMsgEvent: function (options) {
|
|
|
- console.log("gadsfasdfqwerqwerqwerqer===" + JSON.stringify(options));
|
|
|
const that = this;
|
|
|
switch (options.type) {
|
|
|
+ //发现设备列表回调开始
|
|
|
+ case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
|
|
+ if (!options.result) {
|
|
|
+ console.log("蓝牙未开启 fail =》", options)
|
|
|
+ wx.showToast({
|
|
|
+ title: '蓝牙未开启',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //蓝牙搜索开始
|
|
|
+ that.setData({
|
|
|
+ searching: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ // [{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0","RSSI":-62,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fd3af0","serviceData":{}}]
|
|
|
+ ///发现设备列表回调
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
|
|
// 搜索到蓝牙
|
|
|
if (options.result) {
|
|
|
if (options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1).length > 0) {
|
|
|
+ ///过滤乐鑫设备
|
|
|
that.setData({
|
|
|
islanya: true,
|
|
|
devicesList: options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1)
|
|
@@ -68,16 +93,20 @@ Page({
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
+ // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0"}}
|
|
|
+ // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24"}}
|
|
|
+ ///主动去连接连接
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
|
|
|
- // console.log("连接回调:" + JSON.stringify(options))
|
|
|
+ wx.hideLoading();
|
|
|
if (options.result) {
|
|
|
- wx.hideLoading();
|
|
|
if (that.data.isOnBluetooth) {
|
|
|
return;
|
|
|
};
|
|
|
+
|
|
|
that.setData({
|
|
|
isOnBluetooth: true,
|
|
|
});
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
that.setData({
|
|
|
isSubmit: false,
|
|
@@ -88,10 +117,8 @@ Page({
|
|
|
wx.navigateTo({
|
|
|
url: '../deviceConnect3/deviceConnect3?deviceId=' + options.data.deviceId + '&name=' + options.data.name,
|
|
|
});
|
|
|
- }, 500);
|
|
|
-
|
|
|
+ }, 200);
|
|
|
} else {
|
|
|
- wx.hideLoading()
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '连接失败',
|
|
@@ -100,21 +127,7 @@ Page({
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
|
|
- if (!options.result) {
|
|
|
- console.log("蓝牙未开启 fail =》", options)
|
|
|
- wx.showToast({
|
|
|
- title: '蓝牙未开启',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- } else {
|
|
|
- //蓝牙搜索开始
|
|
|
- that.setData({
|
|
|
- searching: true
|
|
|
- });
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
+ ///停止发现设备列表回调
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
|
|
if (options.result) {
|
|
|
//蓝牙停止搜索ok
|
|
@@ -130,20 +143,11 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- Search: function () {
|
|
|
- xBlufi.notifyStartDiscoverBle({
|
|
|
- 'isStart': true,
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
+ // [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
|
|
|
async Connect(e) {
|
|
|
- // if(!this.data.islanya) {
|
|
|
- // return;
|
|
|
- // };
|
|
|
- // [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
|
|
|
var that = this;
|
|
|
- const deviceIdData = that.data.devicesList;
|
|
|
- if (deviceIdData.length < 1) {
|
|
|
+ const devicesList = that.data.devicesList;
|
|
|
+ if (devicesList.length < 1) {
|
|
|
wx.showToast({
|
|
|
title: '请短按设备配对键',
|
|
|
icon: 'none',
|
|
@@ -164,28 +168,32 @@ Page({
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
'isStart': false,
|
|
|
});
|
|
|
+
|
|
|
//开始连接
|
|
|
- let name = deviceIdData[0].name;
|
|
|
- // console.log('点击了,蓝牙准备连接的deviceId:' + deviceIdData[0].deviceId)
|
|
|
+ let name = devicesList[0].name;
|
|
|
+ // console.log('点击了,蓝牙准备连接的deviceId:' + devicesList[0].deviceId)
|
|
|
xBlufi.notifyConnectBle({
|
|
|
isStart: true,
|
|
|
- deviceId: deviceIdData[0].deviceId,
|
|
|
+ deviceId: devicesList[0].deviceId,
|
|
|
name
|
|
|
});
|
|
|
wx.showLoading({
|
|
|
title: '请稍后',
|
|
|
});
|
|
|
},
|
|
|
- onUnload: function () {
|
|
|
- var that = that
|
|
|
- xBlufi.listenDeviceMsgEvent(false, that.funListenDeviceMsgEvent);
|
|
|
- },
|
|
|
+
|
|
|
getBluetoothStatus() {
|
|
|
app.getBluetoothStatus();
|
|
|
},
|
|
|
+
|
|
|
notRoter() {
|
|
|
wx.navigateBack({
|
|
|
delta: 1
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+ onUnload: function () {
|
|
|
+ var that = this;
|
|
|
+ xBlufi.listenDeviceMsgEvent(false, that.funListenDeviceMsgEvent);
|
|
|
+ },
|
|
|
})
|