|
@@ -20,6 +20,11 @@ var FlagOpenControl = false;
|
|
|
|
|
|
var ToyPower = 0;
|
|
|
|
|
|
+//Math.round(new Date() / 1000)
|
|
|
+var logTime = "";
|
|
|
+
|
|
|
+var current_hex = "";
|
|
|
+
|
|
|
|
|
|
//2021年11月10日14:59:38
|
|
|
// 0为旧 1为新
|
|
@@ -54,7 +59,7 @@ function getServicesAndCharateristc() {
|
|
|
|
|
|
export default {
|
|
|
//变量
|
|
|
- connect_toy, control_close, current_toy_id, current_toy_UUID,ToyPower,
|
|
|
+ connect_toy, control_close, current_toy_id, current_toy_UUID, ToyPower,
|
|
|
|
|
|
// 打开大包数据
|
|
|
sendOpenBigData() {
|
|
@@ -118,9 +123,9 @@ export default {
|
|
|
// // $connect_false_count += 1;
|
|
|
// clearInterval(toy_intv)
|
|
|
// } else {
|
|
|
- // $connect_false_count = 0;
|
|
|
- that.SendOrder('8a')
|
|
|
- // connect_toy = false
|
|
|
+ // $connect_false_count = 0;
|
|
|
+ that.SendOrder('8a')
|
|
|
+ // connect_toy = false
|
|
|
// }
|
|
|
|
|
|
//3次获取不到电量则重新连接
|
|
@@ -315,7 +320,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
fail(res) {
|
|
|
- console.log("连接蓝牙成功,获取服务失败",res);
|
|
|
+ console.log("连接蓝牙成功,获取服务失败", res);
|
|
|
},
|
|
|
});
|
|
|
},
|
|
@@ -390,17 +395,11 @@ export default {
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
let hexStr = that.ab2hex(characteristic.value);
|
|
|
|
|
|
- wx.getSystemInfo({
|
|
|
- success(res) {
|
|
|
- if (res.platform == "ios") {
|
|
|
- console.log(hexStr)
|
|
|
- } else {
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD") != -1) {
|
|
|
- console.log(hexStr);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD") != -1) {
|
|
|
+ let nowTime = Math.round(new Date() / 1000);
|
|
|
+ console.log(`${(nowTime - logTime)}s`)
|
|
|
+ console.log(hexStr);
|
|
|
+ }
|
|
|
let $data = that.get_big_data(hexStr);
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
|
|
|
@@ -429,8 +428,8 @@ export default {
|
|
|
});
|
|
|
$this.toy_connected = true;
|
|
|
$this.change_toy_connect_status(2);
|
|
|
- //连接成功后 获取一次教具电量信息
|
|
|
- that.SendOrder('8a')
|
|
|
+ //连接成功后 获取一次教具名称
|
|
|
+ that.SendOrder('87')
|
|
|
}
|
|
|
|
|
|
if (new RegExp("02").test($hex_index) == true) {
|
|
@@ -445,16 +444,30 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //2021年11月23日10:39:49
|
|
|
+ // 获取教具名称
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD87") != -1) {
|
|
|
+ let $datas = that.DoAnalysis(hexStr, 10)
|
|
|
+ console.log($datas)
|
|
|
+ $this.toy_sn = $datas;
|
|
|
+ //获取教具电量
|
|
|
+ that.SendOrder('8a')
|
|
|
+ }
|
|
|
+
|
|
|
//2021年10月21日16:30:07
|
|
|
// 获取教具电量
|
|
|
if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
|
|
|
- let $_hexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD8A")+6);
|
|
|
+ let $_hexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD8A") + 6);
|
|
|
let $power = parseInt($_hexStr.substr(0, 2), 16)
|
|
|
let $voltage = parseInt($_hexStr.substr(2, 2), 16)
|
|
|
|
|
|
// $this.toy_power = Math.round(that.CalBLEPower($voltage));
|
|
|
- $this.toy_power = $power
|
|
|
- ToyPower = $power;
|
|
|
+ if ($power > 0) {
|
|
|
+ $this.toy_power = $power
|
|
|
+ $this.toy_voltage = $voltage
|
|
|
+ ToyPower = $power;
|
|
|
+ }
|
|
|
+
|
|
|
//连接上教具的标识
|
|
|
//FF为无效
|
|
|
if ($power != 0) {
|
|
@@ -535,7 +548,7 @@ export default {
|
|
|
let $version_data = $_data.substr(0, 2).split('')
|
|
|
$this.device_data.hardware_version = `${$version_data[0]}.${$version_data[1]}`
|
|
|
|
|
|
- setDeviceInDb($this, DeviceId)
|
|
|
+ // setDeviceInDb($this, DeviceId)
|
|
|
}
|
|
|
|
|
|
if (hexStr.toUpperCase().indexOf("AADD09") != -1) {
|
|
@@ -556,23 +569,28 @@ export default {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 监听脑环电量
|
|
|
- let $power = that.get_device_elc(hexStr);
|
|
|
- if ($power) {
|
|
|
- // console.log("当前脑环电量:", $power)
|
|
|
- $this.device_power = $power;
|
|
|
- }
|
|
|
- if ($power < 10 && $power > 0) {
|
|
|
- wx.showToast({
|
|
|
- title: "脑环电量不足",
|
|
|
- icon: "none",
|
|
|
- duration: 2000,
|
|
|
- success() {
|
|
|
- // $this.change_device_status(0);
|
|
|
- },
|
|
|
- });
|
|
|
+ if (hexStr.substr(0, 8) == "55550203") {
|
|
|
+ let $power = parseInt(hexStr.substr(8, 2), 16);
|
|
|
+ let $voltage = parseInt(hexStr.substr(10, 2), 16);
|
|
|
+ // 监听脑环电量
|
|
|
+ if ($power) {
|
|
|
+ // console.log("当前脑环电量:", $power)
|
|
|
+ $this.device_power = $power;
|
|
|
+ $this.device_voltage = $voltage;
|
|
|
+ }
|
|
|
+ if ($power < 10 && $power > 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "脑环电量不足",
|
|
|
+ icon: "none",
|
|
|
+ duration: 2000,
|
|
|
+ success() {
|
|
|
+ // $this.change_device_status(0);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//游戏中模块
|
|
|
if ($game_status == 1 && $data) {
|
|
|
try {
|
|
@@ -660,6 +678,7 @@ export default {
|
|
|
//写入buffer
|
|
|
|
|
|
WriteBufferInBle($hex, $buffer_len = 8) {
|
|
|
+ let that = this;
|
|
|
let $deviceInfo = getServicesAndCharateristc();
|
|
|
let $hex_header = "aa cc ";
|
|
|
// let $hex = "03 00 01 00 0a";
|
|
@@ -687,6 +706,7 @@ export default {
|
|
|
value: buffer,
|
|
|
success: function (res) {
|
|
|
console.log($hex + ',写入成功')
|
|
|
+ logTime = Math.round(new Date() / 1000);
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
console.log($hex + "写入失败");
|