|
@@ -42,7 +42,6 @@
|
|
|
<div class="connecting_toy">
|
|
|
<toy_connecting
|
|
|
:connect_toy="connect_toy"
|
|
|
- :deviceId="device.deviceId"
|
|
|
:toy_id="toy_action"
|
|
|
:toy="toy_item"
|
|
|
:device_bg="device_bg"
|
|
@@ -182,7 +181,6 @@ export default {
|
|
|
//连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
|
|
|
connect_toy: 0,
|
|
|
code: "jellyfish1234",
|
|
|
- device: {},
|
|
|
deviceId: "",
|
|
|
_device_index: false,
|
|
|
toy_id: 0,
|
|
@@ -250,7 +248,7 @@ export default {
|
|
|
scan_to_bluetooth() {
|
|
|
wx.scanCode({
|
|
|
onlyFromCamera: true,
|
|
|
- scanType:['barCode', 'qrCode'],
|
|
|
+ scanType: ['barCode', 'qrCode'],
|
|
|
success: (res) => {
|
|
|
let $data = res;
|
|
|
if ($data.result) {
|
|
@@ -258,12 +256,12 @@ export default {
|
|
|
let $code = ""
|
|
|
|
|
|
//二维码
|
|
|
- if (res.scanType=="QR_CODE"){
|
|
|
+ if (res.scanType == "QR_CODE") {
|
|
|
$code = url.match(/\?ring=(.*)/)
|
|
|
- ? url.match(/\?ring=(.*)/)
|
|
|
- : url.match(/\?code=(.*)/);
|
|
|
+ ? url.match(/\?ring=(.*)/)
|
|
|
+ : url.match(/\?code=(.*)/);
|
|
|
$code = $code[1].toUpperCase();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//一维码
|
|
|
$code = res.result.toUpperCase();
|
|
|
}
|
|
@@ -352,7 +350,7 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- fail(res){
|
|
|
+ fail(res) {
|
|
|
console.log(res)
|
|
|
}
|
|
|
});
|
|
@@ -415,21 +413,21 @@ export default {
|
|
|
if ($status == 0) {
|
|
|
game_store.setters.setGameStatus(0);
|
|
|
// 清空链接得设备 三值
|
|
|
- game_store.setters.clearDeviceToy();
|
|
|
$this.connect_toy = $status;
|
|
|
$this.connect_show = false;
|
|
|
$this.device_bg = false;
|
|
|
|
|
|
$this.$bluetooth.SendOrder("09")
|
|
|
-
|
|
|
+ let deviceId = game_store.getters.getDeviceId();
|
|
|
$this.change_toy_connect_status(0);
|
|
|
//断开蓝牙连接
|
|
|
wx.closeBLEConnection({
|
|
|
- deviceId: $this.device.deviceId,
|
|
|
+ deviceId: deviceId,
|
|
|
success(res) {
|
|
|
Toast.success({
|
|
|
message: "已成功断开",
|
|
|
});
|
|
|
+ game_store.setters.clearDeviceToy();
|
|
|
wx.closeBluetoothAdapter();
|
|
|
},
|
|
|
fail(res) {
|
|
@@ -449,38 +447,32 @@ export default {
|
|
|
//开始蓝牙被发现
|
|
|
startBluetoothDevicesDiscovery() {
|
|
|
wx.startBluetoothDevicesDiscovery({
|
|
|
- services: ["0000FFF0-0000-1000-8000-00805F9B34FB", "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"],
|
|
|
allowDuplicatesKey: true,
|
|
|
success: (res) => {
|
|
|
//2021年10月21日15:07:57 通过sn 返回deviceId
|
|
|
getDeviceBySn($this.code).then((res) => {
|
|
|
let $data = res.data;
|
|
|
- console.log($data)
|
|
|
+ console.log($data.code)
|
|
|
$this.change_device_status(1);
|
|
|
- if ($data.code == 0) {
|
|
|
- $data = $data.data;
|
|
|
- wx.getSystemInfo({
|
|
|
- success(res) {
|
|
|
- // 判断ios 和 安卓
|
|
|
- if (res.platform == "ios") {
|
|
|
- $this.device.deviceId = $data.ios_device_id;
|
|
|
- } else {
|
|
|
- $this.device.deviceId = $data.device_id;
|
|
|
- }
|
|
|
- if ($this.device.deviceId) {
|
|
|
+ $data = $data.data;
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success(res) {
|
|
|
+ // 判断ios 和 安卓
|
|
|
+ if (res.platform == "ios") {
|
|
|
+ $this.onBluetoothDeviceFound();
|
|
|
+ } else {
|
|
|
+ if ($data.device_id) {
|
|
|
console.log("finded")
|
|
|
$this.device_finded = true
|
|
|
- $this.createBLEConnection()
|
|
|
+ $this.createBLEConnection($data.device_id)
|
|
|
} else {
|
|
|
$this.device_finded = false
|
|
|
console.log('unfinded')
|
|
|
$this.onBluetoothDeviceFound();
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- } else {
|
|
|
- $this.onBluetoothDeviceFound();
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
})
|
|
|
|
|
|
},
|
|
@@ -515,8 +507,8 @@ export default {
|
|
|
}
|
|
|
if (device["name"].toUpperCase() == $this.code) {
|
|
|
$this.stopBluetoothDevicesDiscovery();
|
|
|
- $this.device = device;
|
|
|
- $this.createBLEConnection();
|
|
|
+ console.log("搜索设备", device)
|
|
|
+ $this.createBLEConnection(device.deviceId);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
@@ -529,33 +521,33 @@ export default {
|
|
|
wx.stopBluetoothDevicesDiscovery();
|
|
|
},
|
|
|
//连接低功耗蓝牙设备。
|
|
|
- createBLEConnection() {
|
|
|
+ createBLEConnection(deviceId) {
|
|
|
wx.createBLEConnection({
|
|
|
- deviceId: $this.device.deviceId,
|
|
|
+ deviceId: deviceId,
|
|
|
success: (res) => {
|
|
|
console.log("成功连接");
|
|
|
- game_store.setters.setDeviceId($this.device.deviceId);
|
|
|
+ game_store.setters.setDeviceId(deviceId);
|
|
|
|
|
|
//成功连接脑环蓝牙
|
|
|
$this.change_device_status(2);
|
|
|
|
|
|
- let $system = wx.getSystemInfoSync()
|
|
|
- if ($system.platform == 'ios') {
|
|
|
- $this.$bluetooth.getBLEDeviceServices($this.device.deviceId)
|
|
|
- $this.$bluetooth.watchingDevice($this)
|
|
|
- } else {
|
|
|
- $this.$bluetooth.openNotify($this)
|
|
|
- $this.$bluetooth.watch_bluetooth_status($this);
|
|
|
- //录入库
|
|
|
- //读取信息逐个写入
|
|
|
- if (!$this.device_finded) {
|
|
|
- setTimeout(() => {
|
|
|
- $this.$bluetooth.SendOrder("02")
|
|
|
- setDeviceInDb($this, $this.device.deviceId)
|
|
|
- }, 3000)
|
|
|
+ $this.$bluetooth.getBLEDeviceServices(deviceId)
|
|
|
+ let $checkServices = setInterval(() => {
|
|
|
+ let $serviceId = game_store.getters.getServiceId();
|
|
|
+ if ($serviceId) {
|
|
|
+ clearInterval($checkServices)
|
|
|
+ $this.$bluetooth.openNotify($this)
|
|
|
+ $this.$bluetooth.watchingDevice($this)
|
|
|
+ $this.$bluetooth.watch_bluetooth_status($this);
|
|
|
+ //录入库
|
|
|
+ //读取信息逐个写入
|
|
|
+ if (!$this.device_finded) {
|
|
|
+ setTimeout(() => {
|
|
|
+ $this.$bluetooth.SendOrder("02")
|
|
|
+ }, 3000)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }, 1500)
|
|
|
|
|
|
},
|
|
|
fail(err) {
|
|
@@ -624,7 +616,6 @@ export default {
|
|
|
$this.connect_show = false;
|
|
|
$this.device_status = 0;
|
|
|
$this.$bluetooth.watch_bluetooth_status($this);
|
|
|
- $this.device.deviceId = "";
|
|
|
$this.toy_UUID = "";
|
|
|
$this.$forceUpdate();
|
|
|
// 清空链接的设备
|