|
@@ -1,335 +1,27 @@
|
|
|
import game_store from "../store/game";
|
|
|
import ble_store from "../store/bluetooth";
|
|
|
-import bluetooth from "../store/bluetooth";
|
|
|
import Notify from "../../static/vant/notify/notify";
|
|
|
|
|
|
+var $ff = "ff";
|
|
|
+var $8f = "ffffffff"
|
|
|
export default {
|
|
|
- // 发送开启脑电数据包指令
|
|
|
- sendOpen(deviceId, serviceId, Cid) {
|
|
|
- // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
-
|
|
|
- // 玩具对应指令数组
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0xff) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
-
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0xff");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- // console.log('开启脑电数据包成功')
|
|
|
- // console.log(res)
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("开启脑电数据包失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
+ // 发送开启脑电数据包指令
|
|
|
+ sendOpen() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 ff");
|
|
|
},
|
|
|
// 发送开启教具脑控指令
|
|
|
- sendControl(deviceId, serviceId, Cid) {
|
|
|
- const that = this;
|
|
|
-
|
|
|
- // 玩具对应指令数组
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x07) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
- // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x07");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
-
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- // console.log('开启教具脑控成功')
|
|
|
- // that.sendOpen()
|
|
|
- // console.log(res)
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("开启教具脑控失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
- // 发送连接玩具指令
|
|
|
- sendConnect($hex, deviceId, serviceId, Cid, Toast, $this) {
|
|
|
- //获取最后两个字节
|
|
|
- const that = this;
|
|
|
- // 玩具对应指令数组
|
|
|
- let arr = [
|
|
|
- "0x01",
|
|
|
- "0x02",
|
|
|
- "0x03",
|
|
|
- "0x04",
|
|
|
- "0x05",
|
|
|
- "0x06",
|
|
|
- "0x07",
|
|
|
- "0x08",
|
|
|
- "0x09",
|
|
|
- "0x0a",
|
|
|
- "0x0b",
|
|
|
- ];
|
|
|
- let arr1 = [
|
|
|
- 0x01,
|
|
|
- 0x02,
|
|
|
- 0x03,
|
|
|
- 0x04,
|
|
|
- 0x05,
|
|
|
- 0x06,
|
|
|
- 0x07,
|
|
|
- 0x08,
|
|
|
- 0x09,
|
|
|
- 0x0a,
|
|
|
- 0x0b,
|
|
|
- ];
|
|
|
- let $index = arr.indexOf($hex);
|
|
|
- let CheckSum =
|
|
|
- ((0x03 + 0x00 + arr1[$index] + 0x00 + 0x0a) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
-
|
|
|
- // 向蓝牙设备发送指令
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, arr[$index]);
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x0a");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
- console.log(buffer);
|
|
|
- console.log(dataView);
|
|
|
-
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- console.log("发送连接玩具指令成功");
|
|
|
- // wx.showLoading({
|
|
|
- // title: '正在创建连接',
|
|
|
- // })
|
|
|
- that.watching_toy($this, deviceId, serviceId, Cid, Toast);
|
|
|
-
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
- Toast.loading({
|
|
|
- duration: 0,
|
|
|
- message: "正在创建连接",
|
|
|
- forbidClick: true,
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("发送连接玩具指令失败");
|
|
|
- Toast.fail({
|
|
|
- message: "玩具连接失败",
|
|
|
- });
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
+ sendControl() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 07");
|
|
|
},
|
|
|
//发送断开玩具的指令
|
|
|
- sendEnd(deviceId, serviceId, Cid) {
|
|
|
+ sendEnd() {
|
|
|
//AA CC 03 00 00 00 09 F3
|
|
|
-
|
|
|
- // 玩具对应指令数组
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x09) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
-
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x09");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
-
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- console.log("断开玩具成功");
|
|
|
- // that.sendOpen()
|
|
|
- console.log(res);
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("断开玩具失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
+ this.WriteBufferInBle("03 00 00 00 09");
|
|
|
},
|
|
|
// 发送停止发送脑电数据包指令
|
|
|
- sendPause(deviceId, serviceId, Cid) {
|
|
|
- let that = this;
|
|
|
- // 玩具对应指令数组
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x08) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
- // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x08");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
-
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- console.log("停止数据发送成功");
|
|
|
- console.log(res);
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("停止数据发送失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
- // 通过字节码获取玩具
|
|
|
- connect_toy(hexStr, deviceId, serviceId, Cid, Toast) {
|
|
|
- console.log("开始连接玩具");
|
|
|
- let $flag = "";
|
|
|
- let $toys = [{
|
|
|
- id: 1,
|
|
|
- hex: "aadd0a0000",
|
|
|
- msg: "无连接设备",
|
|
|
- flag: false,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- hex: "aadd0a0001",
|
|
|
- msg: "已连接到智脑水舞",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- hex: "aadd0a0002",
|
|
|
- msg: "已连接到智脑恐龙",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- hex: "aadd0a0003",
|
|
|
- msg: "已连接到喷雾恐龙(小)",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 4,
|
|
|
- hex: "aadd0a0004",
|
|
|
- msg: "已连接到智脑赛车",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 5,
|
|
|
- hex: "aadd0a0005",
|
|
|
- msg: "已连接到智脑碰碰车",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 6,
|
|
|
- hex: "aadd0a0006",
|
|
|
- msg: "已连接到智脑SUV赛车",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 7,
|
|
|
- hex: "aadd0a0007",
|
|
|
- msg: "已连接到小车(中)",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 8,
|
|
|
- hex: "aadd0a0008",
|
|
|
- msg: "已连接到小车(小)",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 9,
|
|
|
- hex: "aadd0a0009",
|
|
|
- msg: "已连接到智脑无人机",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 10,
|
|
|
- hex: "aadd0a000a",
|
|
|
- msg: "已连接到飞行器(小)",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 11,
|
|
|
- hex: "aadd0a000b",
|
|
|
- msg: "已连接到水母灯",
|
|
|
- flag: true,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 12,
|
|
|
- hex: "aadd070000",
|
|
|
- msg: "无连接设备",
|
|
|
- flag: false,
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- $toys.forEach(($val, $index) => {
|
|
|
- if (hexStr.substring(0, 10) == $val["hex"]) {
|
|
|
- Toast.clear();
|
|
|
- if ($val["flag"]) {
|
|
|
- Toast.success($val["msg"]);
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
- this.sendControl(deviceId, serviceId, Cid);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ($val["hex"] == "aadd070000") {
|
|
|
- this.sendOpen(deviceId, serviceId, Cid);
|
|
|
- } else {
|
|
|
- Toast.fail($val["msg"]);
|
|
|
- }
|
|
|
- }
|
|
|
- $flag = $val["flag"];
|
|
|
- }
|
|
|
- });
|
|
|
- return $flag;
|
|
|
+ sendPause() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 08");
|
|
|
},
|
|
|
|
|
|
// 获取大包数据 进行绘制图表
|
|
@@ -447,9 +139,7 @@ export default {
|
|
|
duration: 0,
|
|
|
message: '智脑环已断开连接,请重新扫码智脑环'
|
|
|
});
|
|
|
- // game_store.setters.setGameStatus(0);
|
|
|
- game_store.setters.setGameCloseStatus(1);
|
|
|
-
|
|
|
+ game_store.setters.setGameStatus(0);
|
|
|
|
|
|
|
|
|
}
|
|
@@ -502,7 +192,7 @@ export default {
|
|
|
game_store.setters.setServiceId(serviceId);
|
|
|
game_store.setters.setCid(item.uuid);
|
|
|
//打开数据帧
|
|
|
- $this.sendOpen(deviceId, serviceId, item.uuid);
|
|
|
+ $this.sendOpen();
|
|
|
// $this.sendPause(deviceId, serviceId, item.uuid)
|
|
|
//获取玩具的值
|
|
|
// bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
|
|
@@ -523,81 +213,16 @@ export default {
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
- //监听玩具得状态
|
|
|
- watching_toy($this, deviceId, serviceId, Cid, Toast) {
|
|
|
- Toast.loading({
|
|
|
- forbidClick: false,
|
|
|
- message: "正在创建连接",
|
|
|
- });
|
|
|
- let that = this;
|
|
|
- let $count = 0;
|
|
|
- //关闭核销选项窗口
|
|
|
- // $this.pay_window = false
|
|
|
- wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
- try {
|
|
|
- let hexStr = that.ab2hex(characteristic.value);
|
|
|
- //连接玩具
|
|
|
- let $flag = that.connect_toy(hexStr, deviceId, serviceId, Cid, Toast);
|
|
|
- //连接不上设备
|
|
|
- if ($flag) {
|
|
|
- //连接成功 打开核销窗口
|
|
|
- // $this.pay_window = true
|
|
|
- $this.change_toy_connect_status(2);
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
- $this.change_toy_connect_status(4);
|
|
|
- }
|
|
|
- wx.offBLECharacteristicValueChange();
|
|
|
- that.watchingDevice($this);
|
|
|
- } else {
|
|
|
- $count++;
|
|
|
- if ($count == 10) {
|
|
|
- $this.change_toy_connect_status(3);
|
|
|
- wx.offBLECharacteristicValueChange();
|
|
|
- that.watchingDevice($this);
|
|
|
- }
|
|
|
- }
|
|
|
- // 取消监听低功耗蓝牙设备
|
|
|
- } catch (e) {
|
|
|
- wx.offBLECharacteristicValueChange();
|
|
|
- that.watchingDevice($this);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
|
|
|
- // 获取当前连接得玩具
|
|
|
- getConnectedToy(deviceId, serviceId, Cid) {
|
|
|
- let that = this;
|
|
|
- // 玩具对应指令数组
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x06) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
- // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x06");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- console.log("获取当前连接的玩具类型");
|
|
|
- console.log(res);
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("获取当前连接的玩具类型失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
+ // 发送连接玩具指令
|
|
|
+ sendConnect($hex) {
|
|
|
+ //获取最后两个字节
|
|
|
+ this.WriteBufferInBle("03 00 " + $hex + " 00 0a");
|
|
|
+ },
|
|
|
+ // 获取当前连接得玩具
|
|
|
+ getConnectedToy() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 06");
|
|
|
},
|
|
|
// ArrayBuffer转16进度字符串示例
|
|
|
ab2hex(buffer) {
|
|
@@ -610,37 +235,8 @@ export default {
|
|
|
return hexArr.join("");
|
|
|
},
|
|
|
//断开发送数据
|
|
|
- shutdownSendControl(deviceId, serviceId, Cid) {
|
|
|
- let that = this;
|
|
|
- let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x0a) ^ 0xffffffff) & 0xff;
|
|
|
- let $CheckSum = "0x" + CheckSum.toString(16);
|
|
|
-
|
|
|
- // 向蓝牙设备发送指令
|
|
|
- let buffer = new ArrayBuffer(8);
|
|
|
- let dataView = new DataView(buffer);
|
|
|
- dataView.setUint8(0, "0xaa");
|
|
|
- dataView.setUint8(1, "0xcc");
|
|
|
- dataView.setUint8(2, "0x03");
|
|
|
- dataView.setUint8(3, "0x00");
|
|
|
- dataView.setUint8(4, "0x00");
|
|
|
- dataView.setUint8(5, "0x00");
|
|
|
- dataView.setUint8(6, "0x0a");
|
|
|
- dataView.setUint8(7, $CheckSum);
|
|
|
- // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
-
|
|
|
- wx.writeBLECharacteristicValue({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: Cid,
|
|
|
- value: buffer,
|
|
|
- success: function (res) {
|
|
|
- console.log("断开连接玩具指令成功");
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.log("发送连接玩具指令失败");
|
|
|
- console.log(err);
|
|
|
- },
|
|
|
- });
|
|
|
+ shutdownSendControl() {
|
|
|
+ this.WriteBufferInBle("03 00 00 00 0a");
|
|
|
},
|
|
|
|
|
|
// 监听脑环是否带正
|
|
@@ -650,12 +246,33 @@ 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"]);
|
|
|
- },
|
|
|
- });
|
|
|
+ // 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) {
|
|
|
+ console.log("已连接到"+$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, 6) == "555520") {
|
|
|
//当s1为 00时 数据有效
|
|
|
let $s1 = hexStr.substr(8, 2);
|
|
@@ -680,6 +297,7 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //游戏中模块
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
|
if ($game_status == 1 && $data) {
|
|
|
try {
|
|
@@ -693,11 +311,7 @@ export default {
|
|
|
}
|
|
|
if ($this.played_time == 0) {
|
|
|
//判断是否隐藏 隐藏则不绘画
|
|
|
- that.shutdownSendControl(
|
|
|
- characteristic.deviceId,
|
|
|
- $this._serviceId,
|
|
|
- $this._characteristicId
|
|
|
- );
|
|
|
+ that.shutdownSendControl();
|
|
|
let $hide_status = game_store.getters.getHideStatus();
|
|
|
if (!$hide_status) {
|
|
|
$this.game_finished();
|
|
@@ -709,7 +323,7 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- // 游玩时间倒计时
|
|
|
+ // 游玩时间倒计时
|
|
|
formatPlaySeconds(value) {
|
|
|
console.log('剩余可游玩时间', value)
|
|
|
// 字符串转数字
|
|
@@ -765,4 +379,44 @@ export default {
|
|
|
|
|
|
return $errmsg;
|
|
|
}
|
|
|
+
|
|
|
+ ,
|
|
|
+ //写入buffer
|
|
|
+ WriteBufferInBle($hex) {
|
|
|
+ let $device_id = game_store.getters.getDeviceId();
|
|
|
+ let $service_id = game_store.getters.getServiceId()
|
|
|
+ let $charateristic = game_store.getters.getCharacterId();
|
|
|
+ let $hex_header = "aa cc ";
|
|
|
+ // let $hex = "03 00 01 00 0a";
|
|
|
+
|
|
|
+ let $hex_sum = 0;
|
|
|
+ let $hex_ary = $hex.split(" ");
|
|
|
+ $hex_ary.forEach(($val, $index) => {
|
|
|
+ $hex_sum += parseInt($val, 16);
|
|
|
+ })
|
|
|
+
|
|
|
+ let $checksum = ($hex_sum ^ parseInt($8f, 16)) & parseInt($ff, 16);
|
|
|
+
|
|
|
+ $hex = $hex_header + $hex + " " + $checksum.toString(16);
|
|
|
+ let buffer = new ArrayBuffer(8);
|
|
|
+ let dataView = new DataView(buffer);
|
|
|
+ $hex_ary = $hex.split(" ");
|
|
|
+ $hex_ary.forEach(($val, $index) => {
|
|
|
+ dataView.setUint8($index, parseInt($val, 16))
|
|
|
+ })
|
|
|
+
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: $device_id,
|
|
|
+ serviceId: $service_id,
|
|
|
+ characteristicId: $charateristic,
|
|
|
+ value: buffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log($hex + ',写入成功')
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log("开启脑电数据包失败");
|
|
|
+ console.log(err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|