|
@@ -92,16 +92,6 @@ export default {
|
|
|
let $high_beta_2 = hex.substr(hex.indexOf("0418") + 36, 2);
|
|
|
let $high_beta_3 = hex.substr(hex.indexOf("0418") + 38, 2);
|
|
|
let $high_beta = parseInt($high_beta_1 + $high_beta_2 + $high_beta_3, 16);
|
|
|
- console.log(
|
|
|
- "att: " + $att,
|
|
|
- "med: " + $med,
|
|
|
- "delta: " + $delta,
|
|
|
- "theta: " + $theta,
|
|
|
- "low_alpha: " + $low_alpha,
|
|
|
- "high_alpha: " + $high_alpha,
|
|
|
- "low_beta: " + $low_beta,
|
|
|
- "high_beta: " + $high_beta,
|
|
|
- );
|
|
|
let $max_num = 30000;
|
|
|
return {
|
|
|
att: $att,
|
|
@@ -243,8 +233,11 @@ export default {
|
|
|
const that = this;
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
let hexStr = that.ab2hex(characteristic.value);
|
|
|
- console.log(hexStr);
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD")!=-1){
|
|
|
+ console.log(hexStr);
|
|
|
+ }
|
|
|
let $data = that.get_big_data(hexStr);
|
|
|
+ let $game_status = game_store.getters.getGameStatus();
|
|
|
|
|
|
// 2021年10月20日17:18:13 判断教具 连接
|
|
|
if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
@@ -272,25 +265,17 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //监听连接教具
|
|
|
- // if (hexStr.substr(0, 8).toLowerCase() == "aadd0a00") {
|
|
|
- // if ($this.toy_item["hex"]) {
|
|
|
- // let $hex = $this.toy_item["hex"].substr($this.toy_item["hex"].length - 2, 2);
|
|
|
- // if (hexStr.substr(8, 2) == $hex) {
|
|
|
- // wx.showToast({
|
|
|
- // title: "已连接到" + $this.toy_item.name
|
|
|
- // });
|
|
|
- // $this.change_toy_connect_status(2);
|
|
|
- // } else if (hexStr.substr(8, 2) == "00") {
|
|
|
- // $this.change_toy_connect_status(3);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- //暂停脑控,切断教具连接
|
|
|
- // if (hexStr.substr(0, 8).toLowerCase() == "aadd0900") {
|
|
|
- // this.shutdownSendControl();
|
|
|
- // }
|
|
|
+
|
|
|
+
|
|
|
+ //2021年10月21日16:30:07 获取教具电量
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
|
|
|
+ let $_hexStr = hexStr.substr(6);
|
|
|
+ let $power = parseInt($_hexStr.substr(0, 2), 16)
|
|
|
+ let $voltage = parseInt($_hexStr.substr(2, 2), 16)
|
|
|
+ console.log("电量:" + $power)
|
|
|
+ console.log("电压:" + $voltage / 10)
|
|
|
+ $this.toy_power = $power;
|
|
|
+ }
|
|
|
|
|
|
//监听佩戴正确
|
|
|
if (hexStr.substr(0, 6) == "555520") {
|
|
@@ -301,9 +286,38 @@ export default {
|
|
|
$this.device_bg = $s1 == "00";
|
|
|
}
|
|
|
|
|
|
+ //2021年10月21日17:22:37
|
|
|
+ //收到一次UUID就发送一次获取教具的电量
|
|
|
+ //读取教具UUID
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
|
|
|
+ let $_hexStr = hexStr.substr(6);
|
|
|
+ let $datas = $_hexStr.substr(0, 10);
|
|
|
+ if ($datas != "0000000000") {
|
|
|
+ $this.toy_UUID = $datas;
|
|
|
+ //读取教具电量
|
|
|
+ that.SendOrder('8a')
|
|
|
+ } else {
|
|
|
+ //如果游戏中则重新连接
|
|
|
+ if ($game_status == 1) {
|
|
|
+ //先发UUID 再发id 02
|
|
|
+ console.log($this.toy_UUID)
|
|
|
+ console.log(`aa cc 03 00 ${$this.toy_hex} 02 0a`)
|
|
|
+ } else {
|
|
|
+ $this.toy_UUID = ""
|
|
|
+ $this.toy_power = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 监听脑环电量
|
|
|
let $power = that.get_device_elc(hexStr);
|
|
|
if ($power) {
|
|
|
+ //发送一次获取教具的UUID
|
|
|
+ that.SendOrder("84");
|
|
|
+
|
|
|
// console.log("当前脑环电量:", $power)
|
|
|
$this.device_power = $power;
|
|
|
}
|
|
@@ -319,7 +333,6 @@ export default {
|
|
|
}
|
|
|
|
|
|
//游戏中模块
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
if ($game_status == 1 && $data) {
|
|
|
try {
|
|
|
if ($this.played_time > 0) {
|
|
@@ -403,7 +416,7 @@ export default {
|
|
|
return $errmsg;
|
|
|
},
|
|
|
//写入buffer
|
|
|
- WriteBufferInBle($hex) {
|
|
|
+ WriteBufferInBle($hex,$buffer_len = 8) {
|
|
|
let $device_id = game_store.getters.getDeviceId();
|
|
|
let $service_id = game_store.getters.getServiceId()
|
|
|
let $charateristic = game_store.getters.getCharacterId();
|
|
@@ -419,7 +432,7 @@ export default {
|
|
|
let $checksum = ($hex_sum ^ parseInt($8f, 16)) & parseInt($ff, 16);
|
|
|
|
|
|
$hex = $hex_header + $hex + " " + $checksum.toString(16);
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
+ let buffer = new ArrayBuffer($buffer_len);
|
|
|
let dataView = new DataView(buffer);
|
|
|
$hex_ary = $hex.split(" ");
|
|
|
$hex_ary.forEach(($val, $index) => {
|
|
@@ -439,5 +452,22 @@ export default {
|
|
|
console.log(err);
|
|
|
},
|
|
|
});
|
|
|
- }
|
|
|
+ },
|
|
|
+ //写入指令
|
|
|
+ SendOrder(id) {
|
|
|
+ let $hexStr = `03 00 00 00 ${id}`;
|
|
|
+ this.WriteBufferInBle($hexStr)
|
|
|
+ },
|
|
|
+ Send16Order(val, id) {
|
|
|
+ let $str = val;
|
|
|
+ let $str_ary = $str.split('');
|
|
|
+ $str = "";
|
|
|
+ $str_ary.forEach(($val, $index) => {
|
|
|
+ $str += $val.charCodeAt().toString(16) + " "
|
|
|
+ });
|
|
|
+ $str = $str.substr(0, $str.length - 1)
|
|
|
+ let $hexStr = "03 ff " + $str + ` ${id}`;
|
|
|
+ this.WriteBufferInBle($hexStr, 16)
|
|
|
+ },
|
|
|
+
|
|
|
};
|