|
@@ -28,7 +28,7 @@ var logTime = "";
|
|
|
|
|
|
var current_hex = "";
|
|
var current_hex = "";
|
|
|
|
|
|
-var is_new = game_store.getters.getIsNew();
|
|
|
|
|
|
+//var is_new = game_store.getters.getIsNew();
|
|
|
|
|
|
//2021年11月10日14:59:38
|
|
//2021年11月10日14:59:38
|
|
// 0为旧 1为新
|
|
// 0为旧 1为新
|
|
@@ -49,9 +49,9 @@ var charateristics = [
|
|
|
|
|
|
function getServicesAndCharateristc() {
|
|
function getServicesAndCharateristc() {
|
|
//获取当前设备名称
|
|
//获取当前设备名称
|
|
- // let $brainSn = game_store.getters.getDeviceSn();
|
|
|
|
- let $deviceId = game_store.getters.getDeviceId();
|
|
|
|
- let $serviceId = game_store.getters.getServiceId();
|
|
|
|
|
|
+ // let $brainSn = ble_store.getters.getDeviceSn();
|
|
|
|
+ let $deviceId = ble_store.getters.getDeviceId();
|
|
|
|
+ let $serviceId = ble_store.getters.getServiceId();
|
|
let $index = services.indexOf($serviceId.toUpperCase())
|
|
let $index = services.indexOf($serviceId.toUpperCase())
|
|
// let $index = $brainSn.toUpperCase().indexOf("JELLYFISH") != -1 ? 0 : 1;
|
|
// let $index = $brainSn.toUpperCase().indexOf("JELLYFISH") != -1 ? 0 : 1;
|
|
return {
|
|
return {
|
|
@@ -136,27 +136,31 @@ export default {
|
|
that.SendOrder('09');
|
|
that.SendOrder('09');
|
|
//清空当前数据
|
|
//清空当前数据
|
|
that.clearLocalDatas();
|
|
that.clearLocalDatas();
|
|
|
|
+ //设置打开脑控为false
|
|
|
|
+ FlagOpenControl = false;
|
|
|
|
+ //清空当前数据
|
|
|
|
+ that.clearLocalDatas()
|
|
},1000);
|
|
},1000);
|
|
// setTimeout(()=>{
|
|
// setTimeout(()=>{
|
|
// // 断开教具及蓝牙连接
|
|
// // 断开教具及蓝牙连接
|
|
// that.SendOrder("31");
|
|
// that.SendOrder("31");
|
|
// },1500);
|
|
// },1500);
|
|
// 兼容二代脑机,不能退出循环
|
|
// 兼容二代脑机,不能退出循环
|
|
- if (!is_new) {
|
|
|
|
- control_close = false;
|
|
|
|
- control_close_intv = setInterval(() => {
|
|
|
|
- if (!control_close) {
|
|
|
|
- //如果是jellyfish则发送00教具
|
|
|
|
- that.sendConnectOneToMore('00')
|
|
|
|
- } else {
|
|
|
|
- //设置打开脑控为false
|
|
|
|
- FlagOpenControl = false;
|
|
|
|
- clearInterval(control_close_intv)
|
|
|
|
- //清空当前数据
|
|
|
|
- that.clearLocalDatas()
|
|
|
|
- }
|
|
|
|
- }, 2000)
|
|
|
|
- }
|
|
|
|
|
|
+ // if (!is_new) {
|
|
|
|
+ // control_close = false;
|
|
|
|
+ // control_close_intv = setInterval(() => {
|
|
|
|
+ // if (!control_close) {
|
|
|
|
+ // //如果是jellyfish则发送00教具
|
|
|
|
+ // that.sendConnectOneToMore('00')
|
|
|
|
+ // } else {
|
|
|
|
+ // //设置打开脑控为false
|
|
|
|
+ // FlagOpenControl = false;
|
|
|
|
+ // clearInterval(control_close_intv)
|
|
|
|
+ // //清空当前数据
|
|
|
|
+ // that.clearLocalDatas()
|
|
|
|
+ // }
|
|
|
|
+ // }, 2000)
|
|
|
|
+ // }
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* todo:发送一对多连接
|
|
* todo:发送一对多连接
|
|
@@ -177,7 +181,7 @@ export default {
|
|
*/
|
|
*/
|
|
sendToyPower() {
|
|
sendToyPower() {
|
|
let that = this;
|
|
let that = this;
|
|
- if (is_new) {
|
|
|
|
|
|
+ // if (is_new) {
|
|
let $connect_false_count = 0;
|
|
let $connect_false_count = 0;
|
|
let toy_intv = setInterval(() => {
|
|
let toy_intv = setInterval(() => {
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
@@ -189,9 +193,9 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, 5000)
|
|
}, 5000)
|
|
- } else {
|
|
|
|
- console.log("旧脑机不支持获取教具电量")
|
|
|
|
- }
|
|
|
|
|
|
+ // } else {
|
|
|
|
+ // console.log("旧脑机不支持获取教具电量")
|
|
|
|
+ // }
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -338,84 +342,83 @@ export default {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- /**
|
|
|
|
- * todo 获取蓝牙设备服务
|
|
|
|
- * @param deviceId
|
|
|
|
- */
|
|
|
|
- getBLEDeviceServices(deviceId) {
|
|
|
|
- const that = this;
|
|
|
|
- current_device_mac = deviceId
|
|
|
|
- wx.getBLEDeviceServices({
|
|
|
|
- deviceId,
|
|
|
|
- success: (res) => {
|
|
|
|
- for (let i = 0; i < res.services.length; i++) {
|
|
|
|
- console.log("serviceItem:" + res.services[i].uuid);
|
|
|
|
- if (res.services[i].uuid.indexOf('6E') != -1 || res.services[i].uuid.indexOf('0000FFF0') != -1) {
|
|
|
|
- console.log("SelectedServiceItem:" + res.services[i].uuid);
|
|
|
|
- that.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
|
|
|
|
- game_store.setters.setServiceId(res.services[i].uuid)
|
|
|
|
- is_new = game_store.getters.getIsNew()
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- fail(res) {
|
|
|
|
- let deviceId = wx.getStorageSync('deviceId');
|
|
|
|
- //断开蓝牙连接
|
|
|
|
- wx.closeBLEConnection({
|
|
|
|
- deviceId: deviceId
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * todo 获取蓝牙设备某个服务中所有特征值
|
|
|
|
- */
|
|
|
|
- getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
|
- console.log(deviceId, serviceId);
|
|
|
|
- const $this = this;
|
|
|
|
- wx.getBLEDeviceCharacteristics({
|
|
|
|
- deviceId,
|
|
|
|
- serviceId,
|
|
|
|
- success: (res) => {
|
|
|
|
- console.log("getBLEDeviceCharacteristics success", res.characteristics);
|
|
|
|
- for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
|
- let item = res.characteristics[i];
|
|
|
|
- let writeState = null;
|
|
|
|
- if (serviceId.indexOf("0001") != -1) {
|
|
|
|
- writeState = item.properties.write && item.uuid.indexOf("0002") != -1;
|
|
|
|
- } else {
|
|
|
|
- writeState = item.properties.write;
|
|
|
|
- }
|
|
|
|
- if (writeState) {
|
|
|
|
- // if (item.properties.write) {
|
|
|
|
- $this.deviceId = deviceId;
|
|
|
|
- $this.serviceId = serviceId;
|
|
|
|
- $this.cid = item.uuid;
|
|
|
|
- //打开数据帧
|
|
|
|
- $this.sendOpenBigData();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (item.properties.notify || item.properties.indicate) {
|
|
|
|
- wx.notifyBLECharacteristicValueChange({
|
|
|
|
- deviceId,
|
|
|
|
- serviceId,
|
|
|
|
- characteristicId: item.uuid,
|
|
|
|
- state: true,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- fail(res) {
|
|
|
|
- let deviceId = wx.getStorageSync('deviceId');
|
|
|
|
- //断开蓝牙连接
|
|
|
|
- wx.closeBLEConnection({
|
|
|
|
- deviceId: deviceId
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
|
|
+ // /**
|
|
|
|
+ // * todo 获取蓝牙设备服务
|
|
|
|
+ // * @param deviceId
|
|
|
|
+ // */
|
|
|
|
+ // getBLEDeviceServices(deviceId) {
|
|
|
|
+ // const that = this;
|
|
|
|
+ // wx.getBLEDeviceServices({
|
|
|
|
+ // deviceId,
|
|
|
|
+ // success: (res) => {
|
|
|
|
+ // console.log("获取蓝牙设备服务service:\n", JSON.stringify(res.services));
|
|
|
|
+ // for (let i = 0; i < res.services.length; i++) {
|
|
|
|
+ // console.log("第" + (i + 1) + "个UUID:" + res.services[i].uuid + "\n");
|
|
|
|
+ // if (res.services[i].uuid.indexOf('6E') !== -1 || res.services[i].uuid.indexOf('0000FFF0') !== -1) {
|
|
|
|
+ // console.log("notifyServicesId:" + res.services[i].uuid);
|
|
|
|
+ // that.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
|
|
|
|
+ // game_store.setters.setServiceId(res.services[i].uuid);
|
|
|
|
+ // return;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // fail(res) {
|
|
|
|
+ // let deviceId = wx.getStorageSync('deviceId');
|
|
|
|
+ // //断开蓝牙连接
|
|
|
|
+ // wx.closeBLEConnection({
|
|
|
|
+ // deviceId: deviceId
|
|
|
|
+ // });
|
|
|
|
+ // },
|
|
|
|
+ // });
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // /**
|
|
|
|
+ // * todo 获取蓝牙设备某个服务中所有特征值
|
|
|
|
+ // */
|
|
|
|
+ // getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
|
+ // console.log(deviceId, serviceId);
|
|
|
|
+ // const $this = this;
|
|
|
|
+ // wx.getBLEDeviceCharacteristics({
|
|
|
|
+ // deviceId,
|
|
|
|
+ // serviceId,
|
|
|
|
+ // success: (res) => {
|
|
|
|
+ // console.log("getBLEDeviceCharacteristics success", res.characteristics);
|
|
|
|
+ // for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
|
+ // let item = res.characteristics[i];
|
|
|
|
+ // let writeState = null;
|
|
|
|
+ // if (serviceId.indexOf("0001") != -1) {
|
|
|
|
+ // writeState = item.properties.write && item.uuid.indexOf("0002") != -1;
|
|
|
|
+ // } else {
|
|
|
|
+ // writeState = item.properties.write;
|
|
|
|
+ // }
|
|
|
|
+ // if (writeState) {
|
|
|
|
+ // // if (item.properties.write) {
|
|
|
|
+ // $this.deviceId = deviceId;
|
|
|
|
+ // $this.serviceId = serviceId;
|
|
|
|
+ // $this.cid = item.uuid;
|
|
|
|
+ // //打开数据帧
|
|
|
|
+ // $this.sendOpenBigData();
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // if (item.properties.notify || item.properties.indicate) {
|
|
|
|
+ // wx.notifyBLECharacteristicValueChange({
|
|
|
|
+ // deviceId,
|
|
|
|
+ // serviceId,
|
|
|
|
+ // characteristicId: item.uuid,
|
|
|
|
+ // state: true,
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // fail(res) {
|
|
|
|
+ // let deviceId = wx.getStorageSync('deviceId');
|
|
|
|
+ // //断开蓝牙连接
|
|
|
|
+ // wx.closeBLEConnection({
|
|
|
|
+ // deviceId: deviceId
|
|
|
|
+ // });
|
|
|
|
+ // },
|
|
|
|
+ // });
|
|
|
|
+ // },
|
|
// 启用蓝牙低功耗设备特征值变化时的 notify 功能,订阅特征。
|
|
// 启用蓝牙低功耗设备特征值变化时的 notify 功能,订阅特征。
|
|
openNotify($this) {
|
|
openNotify($this) {
|
|
let that = this;
|
|
let that = this;
|
|
@@ -454,7 +457,7 @@ export default {
|
|
*/
|
|
*/
|
|
notifyDatas($this) {
|
|
notifyDatas($this) {
|
|
const that = this;
|
|
const that = this;
|
|
- let DeviceId = game_store.getters.getDeviceId();
|
|
|
|
|
|
+ let DeviceId = ble_store.getters.getDeviceId();
|
|
// 监听蓝牙低功耗设备的特征值变化事件
|
|
// 监听蓝牙低功耗设备的特征值变化事件
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
// 获取脑机信号值
|
|
// 获取脑机信号值
|
|
@@ -512,9 +515,9 @@ export default {
|
|
if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
//没连接上教具
|
|
//没连接上教具
|
|
if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
- if (is_new) {
|
|
|
|
|
|
+ //if (is_new) {
|
|
$this.connect_toy = 3;
|
|
$this.connect_toy = 3;
|
|
- }
|
|
|
|
|
|
+ //}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
|
|
let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
|
|
@@ -524,18 +527,18 @@ export default {
|
|
console.log("教具", $toy_id)
|
|
console.log("教具", $toy_id)
|
|
// 连接上教具
|
|
// 连接上教具
|
|
if (new RegExp("00").test($hex_index) == true) {
|
|
if (new RegExp("00").test($hex_index) == true) {
|
|
- if (is_new) {
|
|
|
|
|
|
+ //if (is_new) {
|
|
that.sendConnectOneToOne($toy_id)
|
|
that.sendConnectOneToOne($toy_id)
|
|
$this.current_hex = `03 00 ${$toy_id} 01 0A`
|
|
$this.current_hex = `03 00 ${$toy_id} 01 0A`
|
|
console.log("一对多")
|
|
console.log("一对多")
|
|
- } else {
|
|
|
|
- $this.current_hex = "";
|
|
|
|
- wx.showToast({
|
|
|
|
- title: "已连接到" + $this.toy_item.name
|
|
|
|
- });
|
|
|
|
- $this.toy_connected = true;
|
|
|
|
- $this.connect_toy = 2;
|
|
|
|
- }
|
|
|
|
|
|
+ // } else {
|
|
|
|
+ // $this.current_hex = "";
|
|
|
|
+ // wx.showToast({
|
|
|
|
+ // title: "已连接到" + $this.toy_item.name
|
|
|
|
+ // });
|
|
|
|
+ // $this.toy_connected = true;
|
|
|
|
+ // $this.connect_toy = 2;
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
if (new RegExp("01").test($hex_index) == true) {
|
|
if (new RegExp("01").test($hex_index) == true) {
|
|
console.log("一对一")
|
|
console.log("一对一")
|