|
@@ -79,7 +79,7 @@ Page({
|
|
|
deviceMacId: null,
|
|
|
deviceListSelect: null,
|
|
|
deviceList: [],
|
|
|
- _willConnectBle: true,
|
|
|
+ _willConnectBle: null,
|
|
|
// deviceList: [{
|
|
|
// "connectType": 3,
|
|
|
// "devName": "猫王小王子OTR-X",
|
|
@@ -235,6 +235,7 @@ Page({
|
|
|
///监听蓝牙设备
|
|
|
BtHelper.getInstance().initBluetoothAdapter();
|
|
|
BtHelper.getInstance().getBluetoothDevices();
|
|
|
+ BtHelper.getInstance().startScan(null, null, function (res) { });
|
|
|
var isFirst = true;
|
|
|
console.log("开始监听蓝牙设备");
|
|
|
///再秒再对比一次
|
|
@@ -243,7 +244,7 @@ Page({
|
|
|
that.data.intervalId1 = setInterval(async function () {
|
|
|
isFirst = false;
|
|
|
that.compareList();
|
|
|
- if (count > 3) {
|
|
|
+ if (count > 4) {
|
|
|
that.stopIntervalId1();
|
|
|
} else {
|
|
|
count++;
|
|
@@ -254,21 +255,22 @@ Page({
|
|
|
|
|
|
/// 对比蓝牙数据
|
|
|
compareList() {
|
|
|
- var that = this;
|
|
|
- if (that.data.deviceList.length == 1) {
|
|
|
- let device = that.data.deviceList[0];
|
|
|
- if (device.state === 'online') {
|
|
|
- return;
|
|
|
+
|
|
|
+ let that = this;
|
|
|
+ lexin_scan.compareList2(that.data.deviceList, function (device) {
|
|
|
+ if (device) {
|
|
|
+ that.data._willConnectBle = device;
|
|
|
+ getApp().getBluetoothStatus();
|
|
|
}
|
|
|
- getApp().getBluetoothStatus();
|
|
|
- that.data._willConnectBle = true;
|
|
|
- return;
|
|
|
- }
|
|
|
- lexin_scan.compareList(function (list) {
|
|
|
- that.updateDeviceList(list, false, false);
|
|
|
- }, function (item) {
|
|
|
- that.addBlueDevice(item);
|
|
|
+
|
|
|
});
|
|
|
+
|
|
|
+ // lexin_scan.compareList(function (list) {
|
|
|
+ // console.log("对比蓝牙数据", list);
|
|
|
+ // that.updateDeviceList(list, false, false);
|
|
|
+ // }, function (item) {
|
|
|
+ // that.addBlueDevice(item);
|
|
|
+ // });
|
|
|
},
|
|
|
getBluetoothStatusCallck(v) {
|
|
|
var that = this;
|
|
@@ -277,7 +279,7 @@ Page({
|
|
|
return;
|
|
|
}
|
|
|
if (v) {
|
|
|
- var device = that.data.deviceList[0];
|
|
|
+ var device = that.data._willConnectBle;
|
|
|
console.log("开始连接设备0", device);
|
|
|
if (device.state === 'online' || device.connectType != 1) {
|
|
|
return;
|
|
@@ -287,7 +289,7 @@ Page({
|
|
|
if (isConnected) {
|
|
|
device.state = 'online';
|
|
|
that.addBlueDevice(device);
|
|
|
-
|
|
|
+ that.stopIntervalId1();
|
|
|
} else {
|
|
|
device.state = 'offline';
|
|
|
}
|
|
@@ -301,7 +303,7 @@ Page({
|
|
|
// success: function (res) { }
|
|
|
// });
|
|
|
}
|
|
|
- that.data._willConnectBle = false;
|
|
|
+ that.data._willConnectBle = null;
|
|
|
},
|
|
|
// 回调
|
|
|
mqttCallback(type, option) {
|
|
@@ -577,7 +579,7 @@ Page({
|
|
|
}
|
|
|
|
|
|
///去蓝牙连接处理
|
|
|
- if (index === deviceListSelect) {
|
|
|
+ if (index === deviceListSelect && device.state === "online") {
|
|
|
route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
|
|
|
} else if (device.state === "offline") {
|
|
|
console.log("去连接蓝牙", device)
|
|
@@ -753,9 +755,7 @@ Page({
|
|
|
event_bus.removeNotification(CmdEvent.eventName, that);
|
|
|
event_bus.addNotification(CmdEvent.eventName, function (event) {
|
|
|
if (event.cmdEvent == EnumCmdEvent.onoffline) {
|
|
|
- if (tmp.connected != false) {
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
let disDevice = that.data.deviceList.find(item => {
|
|
|
return item.deviceId == event.deviceId
|
|
|
})
|
|
@@ -764,9 +764,19 @@ Page({
|
|
|
|
|
|
// }
|
|
|
// });
|
|
|
- disDevice.state = event.commonValue;
|
|
|
- console.log("断开连接", disDevice)
|
|
|
- that.updateDeviceList(that.data.deviceList, false, false);
|
|
|
+ console.log("设备状态变化", disDevice)
|
|
|
+ if (disDevice != null) {
|
|
|
+ disDevice.state = event.commonValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.commonValue == "online") {
|
|
|
+ // BtHelper.getInstance().connect()
|
|
|
+ console.log("上线连接", disDevice)
|
|
|
+ } else {
|
|
|
+ console.log("断开连接", disDevice)
|
|
|
+ that.updateDeviceList(that.data.deviceList, false, false);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
});
|