|
@@ -159,7 +159,6 @@ Page({
|
|
BtHelper.getInstance().getBluetoothDevices();
|
|
BtHelper.getInstance().getBluetoothDevices();
|
|
BtHelper.getInstance().startScan(null, null, function (res) { });
|
|
BtHelper.getInstance().startScan(null, null, function (res) { });
|
|
var isFirst = true;
|
|
var isFirst = true;
|
|
- console.log("开始监听蓝牙设备");
|
|
|
|
that.startBleTimer(isFirst, true);
|
|
that.startBleTimer(isFirst, true);
|
|
that.addNotification()
|
|
that.addNotification()
|
|
}
|
|
}
|
|
@@ -178,6 +177,7 @@ Page({
|
|
// 强制开启监听 && (有蓝牙在线 || 有wifi在线)就return
|
|
// 强制开启监听 && (有蓝牙在线 || 有wifi在线)就return
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
///再秒再对比一次
|
|
///再秒再对比一次
|
|
that.stopIntervalId1();
|
|
that.stopIntervalId1();
|
|
let count = 0;
|
|
let count = 0;
|
|
@@ -232,19 +232,18 @@ Page({
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
console.log("自动连接成功", isConnected)
|
|
console.log("自动连接成功", isConnected)
|
|
if (isConnected) {
|
|
if (isConnected) {
|
|
- let hasMyOnline = false;
|
|
|
|
let hasOtherOnline = false;
|
|
let hasOtherOnline = false;
|
|
that.data.deviceList.forEach(item => {
|
|
that.data.deviceList.forEach(item => {
|
|
if (item.state === 'online') {
|
|
if (item.state === 'online') {
|
|
if (item.deviceId == device.deviceId) {
|
|
if (item.deviceId == device.deviceId) {
|
|
- hasMyOnline = true;
|
|
|
|
} else {
|
|
} else {
|
|
hasOtherOnline = true;
|
|
hasOtherOnline = true;
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
- if (hasMyOnline && !hasOtherOnline) {
|
|
|
|
|
|
+ if (!hasOtherOnline) {
|
|
// 自己已经在线,没有其他设备在线, 直接更新
|
|
// 自己已经在线,没有其他设备在线, 直接更新
|
|
console.log("自己已经在线,没有其他设备在线, 直接更新");
|
|
console.log("自己已经在线,没有其他设备在线, 直接更新");
|
|
that.addBlueDevice(device);
|
|
that.addBlueDevice(device);
|
|
@@ -252,7 +251,9 @@ Page({
|
|
let bleDev = that.data.deviceList.find(item => {
|
|
let bleDev = that.data.deviceList.find(item => {
|
|
return item.deviceId === device.deviceId;
|
|
return item.deviceId === device.deviceId;
|
|
});
|
|
});
|
|
- bleDev.state = 'online';
|
|
|
|
|
|
+ if (bleDev) {
|
|
|
|
+ bleDev.state = 'online';
|
|
|
|
+ }
|
|
that.updateDeviceList(that.data.deviceList, false, false);
|
|
that.updateDeviceList(that.data.deviceList, false, false);
|
|
}
|
|
}
|
|
that.stopIntervalId1();
|
|
that.stopIntervalId1();
|
|
@@ -299,6 +300,8 @@ Page({
|
|
deviceListSelect: null,
|
|
deviceListSelect: null,
|
|
indexPage: indexPage == 1 ? 0 : indexPage,
|
|
indexPage: indexPage == 1 ? 0 : indexPage,
|
|
});
|
|
});
|
|
|
|
+ console.log("开启蓝牙监听1:",)
|
|
|
|
+
|
|
that.startBleTimer(true, false);
|
|
that.startBleTimer(true, false);
|
|
}, function () {
|
|
}, function () {
|
|
var indexPage = that.data.indexPage;
|
|
var indexPage = that.data.indexPage;
|
|
@@ -307,6 +310,8 @@ Page({
|
|
deviceListSelect: null,
|
|
deviceListSelect: null,
|
|
indexPage: indexPage == 1 ? 0 : indexPage,
|
|
indexPage: indexPage == 1 ? 0 : indexPage,
|
|
});
|
|
});
|
|
|
|
+ console.log("开启蓝牙监听2:",)
|
|
|
|
+
|
|
that.startBleTimer(true, false);
|
|
that.startBleTimer(true, false);
|
|
|
|
|
|
});
|
|
});
|
|
@@ -841,7 +846,6 @@ Page({
|
|
return item.state == "online" && item.connectType === 3
|
|
return item.state == "online" && item.connectType === 3
|
|
})
|
|
})
|
|
if (!wifiDevice) {
|
|
if (!wifiDevice) {
|
|
- console.log("开启蓝牙监听:", event.deviceId, event.commonValue)
|
|
|
|
that.startBleTimer(isFirst, true);
|
|
that.startBleTimer(isFirst, true);
|
|
}
|
|
}
|
|
}
|
|
}
|