|
@@ -290,149 +290,9 @@ export default {
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
let hexStr = $this.ab2hex(characteristic.value)
|
|
|
-
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0000') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '未找到教具',
|
|
|
- icon: 'none',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- console.log("无连接设备")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0001') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到水柱音箱',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
- console.log("水柱音箱")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0002') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到喷雾恐龙(大)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("喷雾恐龙(大)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0003') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到喷雾恐龙(小)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("喷雾恐龙(小)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0004') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到轨道车',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
+ let $flag = bluetooth.connect_toy(hexStr)
|
|
|
+ if ($flag) {
|
|
|
bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("轨道车")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0005') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到碰碰车',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("碰碰车")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0006') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到小车(大)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("小车(大)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0007') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到小车(中)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("小车(中)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0008') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到小车(小)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("小车(小)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a0009') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到飞行器(大)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("飞行器(大)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a000a') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到飞行器(小)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("飞行器(小)")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd0a000b') {
|
|
|
- wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '已连接到水母灯)',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- $this.connect_toy = 2
|
|
|
-
|
|
|
- console.log("水母灯")
|
|
|
- }
|
|
|
- if (hexStr.substring(0, 10) == 'aadd070000') {
|
|
|
- bluetooth.sendOpen($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -453,6 +313,70 @@ export default {
|
|
|
$this._deviceId = game_store.getters.getDeviceId
|
|
|
$this.toy_index = game_store.getters.getToyIndex
|
|
|
$this.getBLEDeviceServices($this._deviceId)
|
|
|
+
|
|
|
+ // 模拟蓝牙输入值
|
|
|
+ //55 55 20 01 00 02 1b 03 33 04 18 00 15 d7 00 75 37 00 0d da 00 0d 9b 00 10 c2 00 0a f9 00 01 fb 00 04 5a 39
|
|
|
+ let hex = "5555200100021b033304180015d7007537000dda000d9b0010c2000af90001fb00045a39"
|
|
|
+ //当s1为 00时 数据有效
|
|
|
+ let $s1 = hex.substr(8, 2)
|
|
|
+
|
|
|
+ //专注度数据
|
|
|
+ let $att = parseInt("0x" + hex.substr(12, 2))
|
|
|
+ console.log('att', $att)
|
|
|
+ //放松度数据
|
|
|
+ let $med = parseInt("0x" + hex.substr(16, 2))
|
|
|
+ console.log('$med', $med)
|
|
|
+
|
|
|
+ //Delta数据
|
|
|
+ let $delta_1 = hex.substr(hex.indexOf('0418') + 4, 2)
|
|
|
+ let $delta_2 = hex.substr(hex.indexOf('0418') + 6, 2)
|
|
|
+ let $delta_3 = hex.substr(hex.indexOf('0418') + 8, 2)
|
|
|
+ let $delta = "0x" + $delta_1 << 16 | "0x" + $delta_2 << 8 | "0x" + $delta_3
|
|
|
+ console.log('Delta', parseInt("0x" +$delta))
|
|
|
+
|
|
|
+ //Theta数据
|
|
|
+ let $theta_1 = hex.substr(hex.indexOf('0418') + 10, 2)
|
|
|
+ let $theta_2 = hex.substr(hex.indexOf('0418') + 12, 2)
|
|
|
+ let $theta_3 = hex.substr(hex.indexOf('0418') + 14, 2)
|
|
|
+ let $theta = "0x" + $theta_1 << 16 | "0x" + $theta_2 << 8 | "0x" + $theta_3
|
|
|
+ console.log('Theta', parseInt("0x" +$theta))
|
|
|
+
|
|
|
+
|
|
|
+ //low_Alpha
|
|
|
+ let $low_alpha_1 = hex.substr(hex.indexOf('0418') + 16, 2)
|
|
|
+ let $low_alpha_2 = hex.substr(hex.indexOf('0418') + 18, 2)
|
|
|
+ let $low_alpha_3 = hex.substr(hex.indexOf('0418') + 20, 2)
|
|
|
+ let $low_alpha = "0x" + $low_alpha_1 << 16 | "0x" + $low_alpha_2 << 8 | "0x" + $low_alpha_3
|
|
|
+ console.log('low_alpha', $low_alpha)
|
|
|
+
|
|
|
+ //high_Alpha
|
|
|
+ let $high_alpha_1 = hex.substr(hex.indexOf('0418') + 22, 2)
|
|
|
+ let $high_alpha_2 = hex.substr(hex.indexOf('0418') + 24, 2)
|
|
|
+ let $high_alpha_3 = hex.substr(hex.indexOf('0418') + 26, 2)
|
|
|
+ let $high_alpha = "0x" + $high_alpha_1 << 16 | "0x" + $high_alpha_2 << 8 | "0x" + $high_alpha_3
|
|
|
+ console.log('high_alpha', $high_alpha)
|
|
|
+
|
|
|
+ let $alpha = ($high_alpha << 8) | $low_alpha
|
|
|
+ console.log('Alpha', parseInt("0x" +$alpha))
|
|
|
+
|
|
|
+ //low_beta
|
|
|
+ let $low_beta_1 = hex.substr(hex.indexOf('0418') + 28, 2)
|
|
|
+ let $low_beta_2 = hex.substr(hex.indexOf('0418') + 30, 2)
|
|
|
+ let $low_beta_3 = hex.substr(hex.indexOf('0418') + 32, 2)
|
|
|
+ let $low_beta = "0x" + $low_beta_1 << 16 | "0x" + $low_beta_2 << 8 | "0x" + $low_beta_3
|
|
|
+ console.log('$low_beta', $low_beta)
|
|
|
+
|
|
|
+ //high_beta
|
|
|
+ let $high_beta_1 = hex.substr(hex.indexOf('0418') + 34, 2)
|
|
|
+ let $high_beta_2 = hex.substr(hex.indexOf('0418') + 36, 2)
|
|
|
+ let $high_beta_3 = hex.substr(hex.indexOf('0418') + 38, 2)
|
|
|
+ let $high_beta = "0x" + $low_beta_1 << 16 | "0x" + $low_beta_2 << 8 | "0x" + $low_beta_3
|
|
|
+ console.log('$high_beta', $high_beta)
|
|
|
+
|
|
|
+ //Beta数据
|
|
|
+ let $beta = ($high_beta << 8) | $low_beta
|
|
|
+ console.log('Beta', parseInt("0x" +$beta))
|
|
|
+
|
|
|
},
|
|
|
created() {
|
|
|
$this = this;
|