|
@@ -6,6 +6,9 @@ import {setDeviceInDb} from "../requests/game";
|
|
|
var $ff = "ff";
|
|
|
var $8f = "ffffffff"
|
|
|
var control_close = false
|
|
|
+
|
|
|
+var current_device_mac = "";
|
|
|
+
|
|
|
var connect_toy = false;
|
|
|
var current_toy_id = "00";
|
|
|
var current_toy_UUID = "";
|
|
@@ -71,14 +74,15 @@ export default {
|
|
|
$connect_false_count = 0
|
|
|
} else {
|
|
|
$connect_false_count += 1;
|
|
|
- if ($connect_false_count == 3) {
|
|
|
+ console.log("循环数:" + $connect_false_count)
|
|
|
+ if ($connect_false_count == 2) {
|
|
|
//调用重连教具
|
|
|
+ connect_toy = false;
|
|
|
that.ReconnectToy()
|
|
|
clearInterval(toy_intv)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log("循环数:" + $connect_false_count)
|
|
|
}, 3000)
|
|
|
}
|
|
|
},
|
|
@@ -229,7 +233,7 @@ export default {
|
|
|
//获取蓝牙设备服务
|
|
|
getBLEDeviceServices(deviceId) {
|
|
|
const $this = this;
|
|
|
-
|
|
|
+ current_device_mac = deviceId
|
|
|
wx.getBLEDeviceServices({
|
|
|
deviceId,
|
|
|
success: (res) => {
|
|
@@ -443,6 +447,7 @@ export default {
|
|
|
}
|
|
|
if (hexStr.toUpperCase().indexOf("AADD0A02") != -1) {
|
|
|
//发送教具连接
|
|
|
+ connect_toy = true
|
|
|
wx.showToast({
|
|
|
title: "教具重连成功"
|
|
|
})
|
|
@@ -605,6 +610,7 @@ export default {
|
|
|
});
|
|
|
$str = $str.substr(0, $str.length - 1)
|
|
|
let $hexStr = "03 ff " + $str + ` ${id}`;
|
|
|
+
|
|
|
this.WriteBufferInBle($hexStr, 16)
|
|
|
},
|
|
|
//解析
|
|
@@ -622,14 +628,45 @@ export default {
|
|
|
|
|
|
//重连教具
|
|
|
ReconnectToy() {
|
|
|
- //发送UUID
|
|
|
- let $uuid_str = "";
|
|
|
- for (let $i = 0; $i < current_toy_UUID.length; $i + 2) {
|
|
|
- $uuid_str += current_toy_UUID.substr($i, 2) + " ";
|
|
|
+ let that = this;
|
|
|
+ try {
|
|
|
+ //发送UUID
|
|
|
+ let $uuid_str = "";
|
|
|
+ for (let $i = 0; $i < current_toy_UUID.length; $i += 2) {
|
|
|
+ $uuid_str += current_toy_UUID.substr($i, 2) + " ";
|
|
|
+ }
|
|
|
+
|
|
|
+ let _deviceId = "";
|
|
|
+ let deviceIds = current_device_mac.split(':');
|
|
|
+ for (let i = 0; i < deviceIds.length; i++) {
|
|
|
+ if (i != 2) {
|
|
|
+ _deviceId += deviceIds[i] + " ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let sum = $uuid_str + _deviceId;
|
|
|
+ sum = sum.substr(0, sum.length - 1);
|
|
|
+ let $hexStr = `03 ff ${sum} 8e`;
|
|
|
+ let loop_count = "";
|
|
|
+ // let connect_toy_intv = setInterval(() => {
|
|
|
+ // if (connect_toy == false) {
|
|
|
+ // if (loop_count == 3) {
|
|
|
+ // wx.showToast("教具已无法连接")
|
|
|
+ // clearInterval(connect_toy_intv)
|
|
|
+ // }
|
|
|
+ // loop_count += 1;
|
|
|
+ that.WriteBufferInBle($hexStr, 16)
|
|
|
+ // } else {
|
|
|
+ // loop_count = 0;
|
|
|
+ // clearInterval(connect_toy_intv)
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // }, 3000)
|
|
|
+
|
|
|
+ } catch (e) {
|
|
|
+ console.log("ReconnectToy:", e)
|
|
|
}
|
|
|
- console.log("uuid_str" + $uuid_str)
|
|
|
- $uuid_str = $uuid_str.substr(0, $uuid_str.length - 1)
|
|
|
- this.Send16Order($uuid_str, "8e")
|
|
|
+
|
|
|
},
|
|
|
|
|
|
//清空当前脚本的变量值
|