|
@@ -6,22 +6,38 @@ var $ff = "ff";
|
|
|
var $8f = "ffffffff"
|
|
|
export default {
|
|
|
|
|
|
- // 发送开启脑电数据包指令
|
|
|
- sendOpen() {
|
|
|
+ // 打开大包数据
|
|
|
+ sendOpenBigData() {
|
|
|
this.WriteBufferInBle("03 00 00 00 ff");
|
|
|
},
|
|
|
- // 发送开启教具脑控指令
|
|
|
+ // 关闭大包数据
|
|
|
+ sendCloseBigData() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 00");
|
|
|
+ },
|
|
|
+ //获取当前连接的教具类型
|
|
|
+ sendGetToyType() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 06");
|
|
|
+ },
|
|
|
+ // 开启脑控
|
|
|
sendControl() {
|
|
|
this.WriteBufferInBle("03 00 00 00 07");
|
|
|
},
|
|
|
- //发送断开玩具的指令
|
|
|
- sendEnd() {
|
|
|
+ //暂停脑控
|
|
|
+ sendControlPause() {
|
|
|
//AA CC 03 00 00 00 09 F3
|
|
|
+ this.WriteBufferInBle("03 00 00 00 08");
|
|
|
+ },
|
|
|
+ // 关闭脑控
|
|
|
+ sendControlClose() {
|
|
|
this.WriteBufferInBle("03 00 00 00 09");
|
|
|
},
|
|
|
- // 发送停止发送脑电数据包指令
|
|
|
- sendPause() {
|
|
|
- this.WriteBufferInBle("03 00 00 00 08");
|
|
|
+ //发送一对多连接
|
|
|
+ sendConnectOneToMore(id) {
|
|
|
+ this.WriteBufferInBle(`03 00 ${id} 00 0A`);
|
|
|
+ },
|
|
|
+ //发送一对一连接
|
|
|
+ sendConnectOneToOne(id) {
|
|
|
+ this.WriteBufferInBle(`03 00 ${id} 01 0A`)
|
|
|
},
|
|
|
|
|
|
// 获取大包数据 进行绘制图表
|
|
@@ -192,10 +208,7 @@ export default {
|
|
|
game_store.setters.setServiceId(serviceId);
|
|
|
game_store.setters.setCid(item.uuid);
|
|
|
//打开数据帧
|
|
|
- $this.sendOpen();
|
|
|
- // $this.sendPause(deviceId, serviceId, item.uuid)
|
|
|
- //获取玩具的值
|
|
|
- // bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
|
|
|
+ $this.sendOpenBigData();
|
|
|
}
|
|
|
|
|
|
if (item.properties.notify || item.properties.indicate) {
|
|
@@ -215,15 +228,6 @@ export default {
|
|
|
},
|
|
|
|
|
|
|
|
|
- // 发送连接玩具指令
|
|
|
- sendConnect($hex) {
|
|
|
- //获取最后两个字节
|
|
|
- this.WriteBufferInBle("03 00 " + $hex + " 00 0a");
|
|
|
- },
|
|
|
- // 获取当前连接得玩具
|
|
|
- getConnectedToy() {
|
|
|
- this.WriteBufferInBle("03 00 00 00 06");
|
|
|
- },
|
|
|
// ArrayBuffer转16进度字符串示例
|
|
|
ab2hex(buffer) {
|
|
|
var hexArr = Array.prototype.map.call(
|
|
@@ -234,11 +238,6 @@ export default {
|
|
|
);
|
|
|
return hexArr.join("");
|
|
|
},
|
|
|
- //断开发送数据
|
|
|
- shutdownSendControl() {
|
|
|
- this.WriteBufferInBle("03 00 00 00 0a");
|
|
|
- },
|
|
|
-
|
|
|
// 监听脑环是否带正
|
|
|
watchingDevice($this) {
|
|
|
const that = this;
|
|
@@ -246,33 +245,52 @@ export default {
|
|
|
let hexStr = that.ab2hex(characteristic.value);
|
|
|
console.log(hexStr);
|
|
|
let $data = that.get_big_data(hexStr);
|
|
|
- // wx.getBLEDeviceRSSI({
|
|
|
- // deviceId: characteristic.deviceId,
|
|
|
- // success(res) {
|
|
|
- // $this.rssi = Math.abs(res["RSSI"]);
|
|
|
- // },
|
|
|
- // });
|
|
|
|
|
|
- //监听连接教具
|
|
|
- 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) {
|
|
|
+ // 2021年10月20日17:18:13 判断教具 连接
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
|
+ //没连接上教具
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
|
+ $this.change_toy_connect_status(3);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ let $hexAry = $this.current_hex.split(" ")
|
|
|
+ // 03 00 01 00 0a
|
|
|
+ // [2] [3]
|
|
|
+ // 连接上教具
|
|
|
+ if (new RegExp("00").test($hexAry[2]) == false) {
|
|
|
+ if (new RegExp("00").test($hexAry[3]) == true) {
|
|
|
+ that.sendConnectOneToOne($hexAry[2])
|
|
|
+ $this.current_hex = `03 00 $hexAry[2] 01 0A`
|
|
|
+ console.log("一对多")
|
|
|
+ } else {
|
|
|
+ console.log("一对一")
|
|
|
+ $this.current_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() == "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();
|
|
|
- }
|
|
|
-
|
|
|
+ // if (hexStr.substr(0, 8).toLowerCase() == "aadd0900") {
|
|
|
+ // this.shutdownSendControl();
|
|
|
+ // }
|
|
|
|
|
|
//监听佩戴正确
|
|
|
if (hexStr.substr(0, 6) == "555520") {
|
|
@@ -317,7 +335,7 @@ export default {
|
|
|
if ($this.played_time == 0) {
|
|
|
$this.post_data();
|
|
|
//判断是否隐藏 隐藏则不绘画
|
|
|
- that.shutdownSendControl();
|
|
|
+ that.sendControlClose();
|
|
|
let $hide_status = game_store.getters.getHideStatus();
|
|
|
if (!$hide_status) {
|
|
|
$this.game_finished();
|