|
@@ -203,7 +203,7 @@ export default {
|
|
|
},
|
|
|
//扫描连接蓝牙
|
|
|
scan_to_bluetooth() {
|
|
|
- console.log("在扫码时是否存在deviceId?:", this._deviceId);
|
|
|
+ // console.log("在扫码时是否存在deviceId?:", this._deviceId);
|
|
|
wx.scanCode({
|
|
|
onlyFromCamera: true,
|
|
|
success: (res) => {
|
|
@@ -221,25 +221,55 @@ export default {
|
|
|
$this.code = $code[1].toUpperCase();
|
|
|
console.log("头环码", $code);
|
|
|
//打开蓝牙设备
|
|
|
- wx.openBluetoothAdapter({
|
|
|
+ wx.getSystemInfo({
|
|
|
success(res) {
|
|
|
- //判断已经打开连接了
|
|
|
- if (res["errMsg"] == "openBluetoothAdapter:ok") {
|
|
|
- $this.startBluetoothDevicesDiscovery();
|
|
|
- }
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- if (err["errCode"] == 10001) {
|
|
|
- Toast.fail({
|
|
|
- message: "请打开蓝牙和位置信息!",
|
|
|
- });
|
|
|
+ console.log("获取系统信息:", res);
|
|
|
+ if (res.platform == "ios") {
|
|
|
} else {
|
|
|
- Toast.fail({
|
|
|
- message: "蓝牙连接失败",
|
|
|
+ wx.openBluetoothAdapter({
|
|
|
+ success(res) {
|
|
|
+ console.log("初始化蓝牙模块res信息:", res);
|
|
|
+ //判断已经打开连接了
|
|
|
+ if (res["errMsg"] == "openBluetoothAdapter:ok") {
|
|
|
+ $this.startBluetoothDevicesDiscovery();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ if (err["errCode"] == 10001) {
|
|
|
+ Toast.fail({
|
|
|
+ message: "请打开蓝牙和位置信息!",
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Toast.fail({
|
|
|
+ message: "蓝牙连接失败",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
+ // wx.openBluetoothAdapter({
|
|
|
+ // success(res) {
|
|
|
+ // console.log("初始化蓝牙模块res信息:", res);
|
|
|
+ // //判断已经打开连接了
|
|
|
+ // if (res["errMsg"] == "openBluetoothAdapter:ok") {
|
|
|
+ // $this.startBluetoothDevicesDiscovery();
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // if (err["errCode"] == 10001) {
|
|
|
+ // Toast.fail({
|
|
|
+ // message: "请打开蓝牙和位置信息!",
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // Toast.fail({
|
|
|
+ // message: "蓝牙连接失败",
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // });
|
|
|
}
|
|
|
},
|
|
|
});
|
|
@@ -341,12 +371,12 @@ export default {
|
|
|
},
|
|
|
//打开蓝牙搜索
|
|
|
onBluetoothDeviceFound() {
|
|
|
- console.log(
|
|
|
- "打开蓝牙搜索 device_status",
|
|
|
- $this.device_status,
|
|
|
- "是否有id _deviceId",
|
|
|
- $this._deviceId
|
|
|
- );
|
|
|
+ // console.log(
|
|
|
+ // "打开蓝牙搜索 device_status",
|
|
|
+ // $this.device_status,
|
|
|
+ // "是否有id _deviceId",
|
|
|
+ // $this._deviceId
|
|
|
+ // );
|
|
|
try {
|
|
|
// 5秒后判断 这5秒在搜索设备,搜索到就赋值给_deviceId
|
|
|
setTimeout(() => {
|
|
@@ -379,7 +409,7 @@ export default {
|
|
|
game_store.setters.setDeviceId(device.deviceId);
|
|
|
$this._deviceId = device.deviceId;
|
|
|
|
|
|
- console.log("蓝牙搜索状态 device_status", $this.device_status);
|
|
|
+ // console.log("蓝牙搜索状态 device_status", $this.device_status);
|
|
|
|
|
|
$this.createBLEConnection();
|
|
|
}
|
|
@@ -391,12 +421,12 @@ export default {
|
|
|
},
|
|
|
// 停止蓝牙搜索
|
|
|
stopBluetoothDevicesDiscovery() {
|
|
|
- console.log(
|
|
|
- "脑环被占用的情况下我能获取到吗?",
|
|
|
- $this.device_status,
|
|
|
- "是否有id _deviceId",
|
|
|
- $this._deviceId
|
|
|
- );
|
|
|
+ // console.log(
|
|
|
+ // "脑环被占用的情况下我能获取到吗?",
|
|
|
+ // $this.device_status,
|
|
|
+ // "是否有id _deviceId",
|
|
|
+ // $this._deviceId
|
|
|
+ // );
|
|
|
wx.stopBluetoothDevicesDiscovery();
|
|
|
},
|
|
|
//连接低功耗蓝牙设备。
|
|
@@ -404,7 +434,7 @@ export default {
|
|
|
wx.createBLEConnection({
|
|
|
deviceId: $this.device.deviceId,
|
|
|
success: (res) => {
|
|
|
- console.log("成功连接");
|
|
|
+ // console.log("成功连接");
|
|
|
//成功连接脑环蓝牙
|
|
|
$this.change_device_status(2);
|
|
|
bluetooth.watch_bluetooth_status($this);
|
|
@@ -454,7 +484,7 @@ export default {
|
|
|
onShow() {
|
|
|
//判断是否游戏中
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
|
- console.log("游戏中:" + $game_status);
|
|
|
+ // console.log("游戏中:" + $game_status);
|
|
|
if ($game_status == 3) {
|
|
|
//不在游戏状态
|
|
|
$this.connect_toy = 0;
|
|
@@ -468,14 +498,32 @@ export default {
|
|
|
// }
|
|
|
// 状态为0的时候重置为0 小乌龟
|
|
|
} else if ($game_status == 0) {
|
|
|
+ // 重置默认条件
|
|
|
$this.connect_toy = 0;
|
|
|
$this.connect_show = false;
|
|
|
$this.device_status = 0;
|
|
|
bluetooth.watch_bluetooth_status($this);
|
|
|
+ $this._deviceId = "";
|
|
|
+
|
|
|
+ // 清空三个id值
|
|
|
+ let $deviceId = game_store.getters.getDeviceId();
|
|
|
+ let $serviceId = game_store.getters.getServiceId();
|
|
|
+ let $cid = game_store.getters.getCharacterId();
|
|
|
+ bluetooth.shutdownSendControl($deviceId, $serviceId, $cid);
|
|
|
+ // 清空链接的设备
|
|
|
+ game_store.setters.clearDeviceToy();
|
|
|
|
|
|
- // console.log('我是在游戏中断开,我触发了嘛~',$this.connect_toy, $this.connect_show,$this.device_status );
|
|
|
+ console.log("返回时出现,我触发了嘛", $deviceId, $serviceId, $cid);
|
|
|
}
|
|
|
},
|
|
|
+ onHide() {
|
|
|
+ console.log(
|
|
|
+ "你好啊,我触发了嘛?",
|
|
|
+ $this.connect_show,
|
|
|
+ $this.device_status,
|
|
|
+ game_store.getters.getGameStatus()
|
|
|
+ );
|
|
|
+ },
|
|
|
onLoad(options) {
|
|
|
// 原有的code
|
|
|
let $_code = wx.getStorageSync("code");
|