|
@@ -79,7 +79,7 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
// 发送连接玩具指令
|
|
|
- sendConnect($hex, deviceId, serviceId, Cid) {
|
|
|
+ sendConnect($hex, deviceId, serviceId, Cid, Toast) {
|
|
|
//获取最后两个字节
|
|
|
const that = this
|
|
|
// 玩具对应指令数组
|
|
@@ -109,9 +109,18 @@ export default {
|
|
|
value: buffer,
|
|
|
success: function (res) {
|
|
|
console.log('发送连接玩具指令成功')
|
|
|
- wx.showLoading({
|
|
|
- title: '正在创建连接',
|
|
|
- })
|
|
|
+ // wx.showLoading({
|
|
|
+ // title: '正在创建连接',
|
|
|
+ // })
|
|
|
+
|
|
|
+ let $game_status = game_store.getters.getGameStatus;
|
|
|
+ if ($game_status == 1) {
|
|
|
+ Toast.loading({
|
|
|
+ duration: 0,
|
|
|
+ message: "正在创建连接",
|
|
|
+ forbidClick: true
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
console.log('发送连接玩具指令失败')
|
|
@@ -197,7 +206,9 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
// 通过字节码获取玩具
|
|
|
- connect_toy(hexStr, deviceId, serviceId, Cid) {
|
|
|
+ connect_toy(hexStr, deviceId, serviceId, Cid, Toast) {
|
|
|
+ console.log('开始连接玩具')
|
|
|
+ let $flag = ""
|
|
|
let $toys = [
|
|
|
{
|
|
|
id: 1,
|
|
@@ -208,13 +219,13 @@ export default {
|
|
|
{
|
|
|
id: 1,
|
|
|
hex: 'aadd0a0001',
|
|
|
- msg: "已连接到水柱音箱",
|
|
|
+ msg: "已连接到智脑水舞",
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
hex: 'aadd0a0002',
|
|
|
- msg: "已连接到喷雾恐龙(大)",
|
|
|
+ msg: "已连接到智脑恐龙",
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
@@ -226,19 +237,19 @@ export default {
|
|
|
{
|
|
|
id: 4,
|
|
|
hex: 'aadd0a0004',
|
|
|
- msg: "已连接到轨道车",
|
|
|
+ msg: "已连接到智脑赛车",
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
|
id: 5,
|
|
|
hex: 'aadd0a0005',
|
|
|
- msg: "已连接到碰碰车",
|
|
|
+ msg: "已连接到智脑碰碰车",
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
|
id: 6,
|
|
|
hex: 'aadd0a0006',
|
|
|
- msg: "已连接到小车(大)",
|
|
|
+ msg: "已连接到智脑SUV赛车",
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
@@ -256,7 +267,7 @@ export default {
|
|
|
{
|
|
|
id: 9,
|
|
|
hex: 'aadd0a0009',
|
|
|
- msg: '已连接到飞行器(大)',
|
|
|
+ msg: '已连接到智脑无人机',
|
|
|
flag: true
|
|
|
},
|
|
|
{
|
|
@@ -281,31 +292,24 @@ export default {
|
|
|
|
|
|
$toys.forEach(($val, $index) => {
|
|
|
if (hexStr.substring(0, 10) == $val['hex']) {
|
|
|
+ Toast.clear()
|
|
|
if ($val['flag']) {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: $val['msg'],
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- console.log($val['msg'])
|
|
|
- this.sendControl(deviceId, serviceId, Cid)
|
|
|
+ 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 {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: $val['msg'],
|
|
|
- icon: 'nones',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
+ Toast.fail($val['msg'])
|
|
|
}
|
|
|
}
|
|
|
- return $val['flag']
|
|
|
+ $flag = $val['flag']
|
|
|
}
|
|
|
-
|
|
|
})
|
|
|
+ return $flag
|
|
|
},
|
|
|
|
|
|
// 获取大包数据 进行绘制图表
|
|
@@ -452,6 +456,42 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ //监听玩具得状态
|
|
|
+ watching_toy($this, deviceId, serviceId, Cid, Toast) {
|
|
|
+ Toast.clear()
|
|
|
+ Toast.loading({
|
|
|
+ duration: 0,
|
|
|
+ forbidClick: false,
|
|
|
+ message: "检测连接中"
|
|
|
+ })
|
|
|
+ let that = this
|
|
|
+ let $count = 0
|
|
|
+ //关闭核销选项窗口
|
|
|
+ // $this.pay_window = false
|
|
|
+ wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
+ console.log("收到" + that.ab2hex(characteristic.value));
|
|
|
+ let hexStr = that.ab2hex(characteristic.value)
|
|
|
+ //连接玩具
|
|
|
+ let $flag = that.connect_toy(hexStr, deviceId, serviceId, Cid, Toast)
|
|
|
+ //连接不上设备
|
|
|
+ if ($flag) {
|
|
|
+ Toast.clear()
|
|
|
+ //连接成功 打开核销窗口
|
|
|
+ // $this.pay_window = true
|
|
|
+ $this.change_toy_connect_status(2)
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ } else {
|
|
|
+ $count++
|
|
|
+ if ($count == 10) {
|
|
|
+ Toast.clear()
|
|
|
+ $this.change_toy_connect_status(3)
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 取消监听低功耗蓝牙设备
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
// 获取当前连接得玩具
|
|
|
getConnectedToy(deviceId, serviceId, Cid) {
|
|
@@ -486,5 +526,16 @@ export default {
|
|
|
console.log(err)
|
|
|
}
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
+ // ArrayBuffer转16进度字符串示例
|
|
|
+ ab2hex(buffer) {
|
|
|
+ var hexArr = Array.prototype.map.call(
|
|
|
+ new Uint8Array(buffer),
|
|
|
+ function (bit) {
|
|
|
+ return ('00' + bit.toString(16)).slice(-2)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return hexArr.join('');
|
|
|
+ },
|
|
|
+
|
|
|
}
|