|
@@ -28,7 +28,7 @@ var logTime = "";
|
|
|
|
|
|
var current_hex = "";
|
|
|
|
|
|
-var is_new = game_store.getters.getIsNew();
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -49,9 +49,9 @@ var charateristics = [
|
|
|
|
|
|
function getServicesAndCharateristc() {
|
|
|
|
|
|
-
|
|
|
- let $deviceId = game_store.getters.getDeviceId();
|
|
|
- let $serviceId = game_store.getters.getServiceId();
|
|
|
+
|
|
|
+ let $deviceId = ble_store.getters.getDeviceId();
|
|
|
+ let $serviceId = ble_store.getters.getServiceId();
|
|
|
let $index = services.indexOf($serviceId.toUpperCase())
|
|
|
|
|
|
return {
|
|
@@ -136,27 +136,31 @@ export default {
|
|
|
that.SendOrder('09');
|
|
|
|
|
|
that.clearLocalDatas();
|
|
|
+
|
|
|
+ FlagOpenControl = false;
|
|
|
+
|
|
|
+ that.clearLocalDatas()
|
|
|
},1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- if (!is_new) {
|
|
|
- control_close = false;
|
|
|
- control_close_intv = setInterval(() => {
|
|
|
- if (!control_close) {
|
|
|
-
|
|
|
- that.sendConnectOneToMore('00')
|
|
|
- } else {
|
|
|
-
|
|
|
- FlagOpenControl = false;
|
|
|
- clearInterval(control_close_intv)
|
|
|
-
|
|
|
- that.clearLocalDatas()
|
|
|
- }
|
|
|
- }, 2000)
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
|
|
|
* todo:发送一对多连接
|
|
@@ -177,7 +181,7 @@ export default {
|
|
|
*/
|
|
|
sendToyPower() {
|
|
|
let that = this;
|
|
|
- if (is_new) {
|
|
|
+
|
|
|
let $connect_false_count = 0;
|
|
|
let toy_intv = setInterval(() => {
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
@@ -189,9 +193,9 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}, 5000)
|
|
|
- } 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) {
|
|
|
-
|
|
|
- $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
|
|
|
- });
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
openNotify($this) {
|
|
|
let that = this;
|
|
@@ -454,7 +457,7 @@ export default {
|
|
|
*/
|
|
|
notifyDatas($this) {
|
|
|
const that = this;
|
|
|
- let DeviceId = game_store.getters.getDeviceId();
|
|
|
+ let DeviceId = ble_store.getters.getDeviceId();
|
|
|
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
|
|
@@ -512,9 +515,9 @@ export default {
|
|
|
if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
|
|
|
|
if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
|
- if (is_new) {
|
|
|
+
|
|
|
$this.connect_toy = 3;
|
|
|
- }
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
|
|
@@ -524,18 +527,18 @@ export default {
|
|
|
console.log("教具", $toy_id)
|
|
|
|
|
|
if (new RegExp("00").test($hex_index) == true) {
|
|
|
- if (is_new) {
|
|
|
+
|
|
|
that.sendConnectOneToOne($toy_id)
|
|
|
$this.current_hex = `03 00 ${$toy_id} 01 0A`
|
|
|
console.log("一对多")
|
|
|
- } 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) {
|
|
|
console.log("一对一")
|