| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944 |
- <template>
- <view>
- <view style="height: 50px;"></view>
- <view>
- <view class="title">Cocos预览地址:{{LocationGameUrl}}</view>
- <input class="uni-input" :value="LocationGameUrl" @input="onKeyInput" placeholder="输入cocos预览地址" />
- </view>
- <view class="card-view padding-top padding-bottom" v-for="(item,index) in devicesList" :key="index"
- :id="'task_'+index" :class="item.bRatio?'hardware-border':''" :style="{'z-index': threeZIndex}">
- <view class="flex justify-between align-center">
- <view class="flex justify-start align-center">
- <image style="margin-left: 20rpx; width: 200rpx;height: 120rpx;" :src="item.icon" mode="aspectFit">
- </image>
- <view style="width: 350rpx;margin-left: 10rpx;">
- <view style="margin: 20rpx 0rpx; font-weight: bold; font-size: 18px; color: #565656;">
- {{item.cname}}
- </view>
- <view style="font-size: 12px; white-space:pre-wrap;" class="make-text-bPurple">
- {{item.describe}}{{item.bOldDevice?'(旧手柄)':''}}
- </view>
- </view>
- </view>
- <image style="margin-right: 60rpx; width: 60rpx;height: 60rpx;"
- :src="item.bRatio?'/static/devicesOther/radio-b.png':'/static/devicesOther/radio-g.png'"
- mode="aspectFit" @tap="_onRadio(item,$event)"></image>
- </view>
- </view>
- <view v-if="currentItem" style="display: flex;flex-direction: row;">
- <button style="margin: 10rpx;" type="primary" @click="B_OnSetMTU">MTU</button>
- <button style="margin: 10rpx;" type="primary" @click="writeBLEValue('V')">版本</button>
- <button style="margin: 10rpx;" type="primary" @click="writeBLEValue('M')">mac</button>
- </view>
- <view v-if="currentItem" style="display: flex;flex-direction: row;">
- <button style="margin: 10rpx;" type="primary" @click="writeBLEValue('H')">开启高速</button>
- <button style="margin: 10rpx;" type="primary" @click="writeBLEValue('h')">关闭高速</button>
- </view>
- <scroll-view class="text-box" scroll-y="true">
- <scroll-view scroll-x="true">
- <text selectable="true" style="background-color: greenyellow;">{{text}}</text>
- </scroll-view>
- </scroll-view>
- <button type="warn" :disabled="extraLine.length<=0" @click="remove">
- 清除输入框数据
- </button>
- <button style="margin-top: 2px;" type="warn" :disabled="!currentItem" @click="onShowGame">
- 显示游戏
- </button>
- <button style="margin-top: 2px;" type="warn" @click="onEmit">
- 模拟发送
- </button>
- <!-- <button style="margin-top: 2px;" type="warn" @click="onClise">
- close
- </button> -->
- <!-- <view class="content">
- </view> -->
- </view>
- </template>
- <script>
- import config from '@/common/config.js';
- import reqUtil from '@/util/util-js/requstUtil.js';
- import ble from '@/util/util-js/BLE.js';
- import {
- mapState,
- mapMutations
- } from 'vuex';
- export default {
- computed: mapState(['bOpenBluetooth', 'bOpenSuccess', 'bListenAdapterStateChange', 'bListenDeviceFound',
- 'BLEConnectDevice', 'BLEGetServices', 'cIndex', 'bConnection', 'bVerifiedConnection', 'BLEInfoList',
- 'BLEDeviceShowList', 'finallyUseDevice', 'systemInfo', 'guideUnlockState', 'currentModeIndex',
- "bListenerAccArray", 'LocationGameUrl','bGamePlaying'
- ]),
- data() {
- return {
- // 设备列表
- devicesList: [],
- currentItem: null,
- //设置一个旧的连接item
- oldItem: null,
- searchObj: null,
- //设置搜索超时时间
- searchTimeOut: null,
- option: null,
- saveObj: null,
- //搜索提示定时器
- searchMac: null,
- //
- getServicesTimeout: null,
- writeMacTimeout: null,
- //限制关闭连接
- bLimitClose: false,
- //是否需要检测发起的连接蓝牙是否匹配上
- bTestBondConnect: true,
- //是否显示
- bShow: true,
- //切换连接
- bSwitch: false,
- //提示
- circular: false,
- currentHeight: 0,
- threeTipHeight: 0,
- threeZIndex: 0,
- currentIndex: 5,
- //测试
- text: '',
- extraLine: [],
- bShowGame: false,
- }
- },
- onLoad(op) {
- this.add("初始化");
- uni.$on('retryConnectBLESuccess', this.onRetryConnectBLESuccess);
- uni.$on('callbackCloseBLE', this.hardCallbackCloseBLE);
- uni.$on('listenerBLE', this.onListenerBLE);
- uni.$on('updateBLEDeviceData', this.callbackUpdateBLEData);
- this.BLEInfoList.forEach((item, index, selfarr) => {
- if (item.deviceType == 'BLEHandle' && item.usageMode == 'hotman') {
- let item = Object.assign({}, selfarr[index], {
- bOldDevice: false
- });
- this.devicesList.push(item);
- }
- })
- //subview
- /**
- * $on 之后要调用 $off,不然会重复绑定
- */
- this.onGetLocationGameUrl();
-
- uni.$on("log", this.add)
- },
- onUnload() {
- uni.$off('retryConnectBLESuccess', this.onRetryConnectBLESuccess);
- uni.$off('callbackCloseBLE', this.hardCallbackCloseBLE);
- uni.$off('listenerBLE', this.onListenerBLE);
- uni.$off('updateBLEDeviceData', this.callbackUpdateBLEData);
- //清除定时器
- this.onClearTimeout();
- uni.$off("log", this.add)
- },
- onShow() {
- this.bShow = true;
- },
- onReady() {},
- onHide() {
- //如果蓝牙弹出匹配框,会触发onHide。这时候处理蓝牙连接流程检测应等onShow 时候,再检测
- this.bShow = false;
- },
- methods: {
- ...mapMutations(['initAdapter', 'onCreateBLESuccess', 'onGetBLEDeviceServices', 'onOnlyCloseBLEConnection',
- 'onGetRSSITransDistance',
- 'addBLEDevice', 'onWriteBLEConnectionValue', 'deleteBLEDevice', 'B_GetBondedDevices',
- 'B_OpenBLESetting', 'setGuideUnlockState', 'switchLevelList', 'onSetLocationGameUrl',
- 'onGetLocationGameUrl', 'onTestEmit', 'B_CloseBLEConnection', 'B_OnSetMTU'
- ]),
- onEmit() {
- this.onTestEmit();
- },
- /**
- * 显示游戏
- */
- onShowGame() {
- // uni.$emit("showGame");
- // this.bShowGame = true;
- uni.navigateTo({
- url:"../game/game"
- })
- },
- //设备回调事件
- callbackUpdateBLEData(data) {
- //如果在监听状态时候隐藏页面,返回
- // console.log(data)
- // if (!this.bShow) return;
- // this.add(JSON.stringify(data));
- if (this.bGamePlaying) return;
- let str = "";
- for (let i = 0; i < data.length; i++) {
- str +=
- "ax:" + data[i].acc.ax + "\n" +
- "ay:" + data[i].acc.ay + "\n" +
- "az:" + data[i].acc.az + "\n" +
- "gx:" + data[i].gyro.gx + "\n" +
- "gy:" + data[i].gyro.gy + "\n" +
- "gz:" + data[i].gyro.gz + "\n" +
- "ms:" + data[i].ms + "\n" ;
- }
- this.text = str;
- // this.text =
- // "ax:" + data.acc.ax + "\n" +
- // "ay:" + data.acc.ay + "\n" +
- // "az:" + data.acc.az + "\n" +
- // "gx:" + data.gyro.gx + "\n" +
- // "gy:" + data.gyro.gy + "\n" +
- // "gz:" + data.gyro.gz + "\n" +
- // "ms:" + data.ms;
- // if(this.bListenerAccArray)return;
- // if (this.BLEConnectDevice.usageMode == "hotman") {
- // this.gUpdateSandbagAlgorithm({
- // data: data,
- // callback: (res) => {
- // if (res.type == 'hit') {
- // console.log("hotman 打击:" + JSON.stringify(res));
- // }
- // }
- // });
- // } else if (this.BLEConnectDevice.usageMode == "general") {
- // //这个是普通打击模式
- // } else if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
- // this.onConvertDeviceData({
- // data: data,
- // callback: (outData) => {
- // // this.outBLEData = {
- // // acc: outData.convertAcc,
- // // gyro: outData.convertGyro
- // // }
- // // console.log(JSON.stringify(outData),JSON.stringify(data));
- // console.log("hotman 打击:" + JSON.stringify(outData))
- // data.acc = outData.convertAcc;
- // data.gyro = outData.convertGyro;
- // //跳绳蓝牙反馈
- // }
- // });
- // }
- },
- onClearTimeout() {
- // 退出后,清除计时器
- if (this.searchMac) {
- clearTimeout(this.searchMac);
- this.searchMac = null;
- }
- //servicesTimeout
- if (this.getServicesTimeout) {
- clearTimeout(this.getServicesTimeout);
- this.getServicesTimeout = null;
- }
- //写入指令writeMacTimeout
- if (this.writeMacTimeout) {
- clearTimeout(this.writeMacTimeout);
- this.writeMacTimeout = null;
- }
- if (this.searchTimeOut) {
- clearTimeout(this.searchTimeOut);
- this.searchTimeOut = null;
- }
- },
- //监听回调
- onListenerBLE(res) {
- console.log('onListenerBLE:', res, this.saveObj);
- this.add(res.value);
- // if (res.type !== 'mac') return;
- // //如果mac 回调了不用提示
- // if (this.searchMac) {
- // clearTimeout(this.searchMac);
- // this.searchMac = null;
- // }
- // let _self = this;
- // let mac = res.value;
- // // console.log('mac =====', mac);
- // //用返回的mac 判断,如果非法,则断开连接
- // //就判断一下是否
- // //测试
- // // mac="BB:34:24:22:77:88";
- // // mac="较è¾";
- // //判断mac地址是否是合理的格式
- // var tempMacRegExp =
- // /[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}/;
- // if (!tempMacRegExp.test(mac)) {
- // uni.hideToast();
- // uni.showModal({
- // title: '验证信息',
- // content: '获取Mac地址失败,请重新连接。'
- // })
- // //关闭当前连接
- // _self.onOnlyCloseBLEConnection({
- // getSuccess: () => {
- // _self.currentItem = null;
- // _self.saveObj = null;
- // }
- // });
- // return;
- // }
- // _self.saveObj = Object.assign({}, _self.saveObj, {
- // deviceMac: mac,
- // bOldDevice: false
- // });
- // _self.addBLEDevice(_self.saveObj);
- // _self.ConnectionSuccess();
- },
- /**
- * 连接设备成功
- */
- ConnectionSuccess() {
- for (let i = 0; i < this.devicesList.length; i++) {
- let eq = this.devicesList[i];
- if (
- (eq.ename.indexOf("mobilePhoneBandage") > -1 && this.BLEConnectDevice.id == 0) ||
- (eq.ename.indexOf("hotman") > -1 && this.BLEConnectDevice.id == 1) ||
- (eq.ename.indexOf("BLEHandle") > -1 && this.BLEConnectDevice.id == 2) ||
- (eq.ename.indexOf("rope") > -1 && this.BLEConnectDevice.id == 3)) {
- eq.bRatio = true;
- this.currentItem = eq;
- /**
- * 已验证的连接设置true
- */
- // this.$store.state.bVerifiedConnection = true;
- /**
- * 根据名字兼容旧设备
- */
- // let _tempMac = this.saveObj.deviceMac.replace(/:/g, "");
- // let _fourStr = _tempMac.substring(_tempMac.length - 4, _tempMac.length);
- // console.log("格式化去掉冒号后mac:", _tempMac, "==", _fourStr);
- // let _tempInt = ble.hex2int(_fourStr);
- // console.log("格式化去掉冒号后_tempInt:", _tempInt);
- // //这里判断旧设备,因为目前这批新设备,用的也是202012的名字,所以这里处理兼容旧设备就行了
- // //用mac判断区分,一起有100个是旧设备,还有部分非标准的mac,根据后台字段判断
- // //如果后台存在bOldDevice 字段,则根据字段判断是否是旧设备
- // if (this.saveObj.name === "BGBox_202012" &&
- // _tempInt <= 101 && _tempInt >= 0 || this.saveObj.bOldDevice) {
- // this.$store.state.bOldDeviceType = true;
- // eq.bOldDevice = true;
- // console.log("旧设备:", this.$store.state.bOldDeviceType);
- // } else {
- // console.log("旧设备", this.$store.state.bOldDeviceType);
- // eq.bOldDevice = false;
- // }
- uni.hideToast();
- }
- }
- },
- onCheckBondDevice() {
- console.log("onCheckBondDevice", this.bTestBondConnect);
- if (this.bTestBondConnect && this.bShow) {
- /**
- * 假如手机没有匹配,断开连接
- */
- console.log(2, this.finallyUseDevice);
- this.B_GetBondedDevices({
- deviceId: this.finallyUseDevice.deviceId,
- success: (bondedDevice) => {
- uni.hideToast();
- if (bondedDevice == null) {
- // if (plus.os.name == 'Android')
- {
- //此问题 华为手机容易出现
- //android手机已配对的设备 不存在,但是app 又直接连接成功了。提示,并且断开app连接
- //1.关闭当前连接
- this.onOnlyCloseBLEConnection({
- getSuccess: () => {
- this.currentItem.bRatio = false;
- this.currentItem = null;
- this.saveObj = null;
- }
- });
- //2.跳转蓝牙设置
- uni.showModal({
- title: '蓝牙配对失败',
- content: '请跳转后点击配对BGBox_2020,成功后手动跳转回哔蹦重新连接。',
- success: (res) => {
- if (res.confirm) {
- this.B_OpenBLESetting();
- }
- }
- })
- }
- }
- }
- });
- this.bTestBondConnect = false;
- } else {
- uni.hideToast();
- }
- },
- onRetryConnectBLESuccess() {
- this.ConnectionSuccess();
- },
- hardCallbackCloseBLE() {
- if (this.BLEConnectDevice == null && this.currentItem && !this.bSwitch) {
- this.currentItem.bRatio = false;
- this.currentItem = null;
- this.saveObj = null;
- }
- //如果限制不走重连
- if (this.bLimitClose) return;
- console.log(this.currentItem, this.oldItem);
- if (this.oldItem && this.currentItem && this.currentItem.id == this.oldItem.id) {
- // this.$store.state.bConnection = false;
- if (this.currentItem.bRatio) {
- uni.showToast({
- title: '设备断开连接!',
- icon: 'none',
- duration: 2000,
- mask: true
- })
- this.currentItem.bRatio = false;
- this.oldItem = null;
- this.currentItem = null;
- //断开连接
- this.$store.state.bVerifiedConnection = false;
- }
- } else if (this.bConnection && this.BLEConnectDevice) {
- //假如匹配过程中断开连接
- this.$store.state.BLEConnectDevice = null;
- this.$store.state.bConnection = false;
- // uni.hideToast();
- // console.log("//假如匹配过程中断开连接");
- uni.showToast({
- title: '连接失败,尝试重新连接。',
- icon: 'none',
- mask: true,
- duration: 2000
- })
- if (this.getServicesTimeout) {
- clearTimeout(this.getServicesTimeout);
- this.getServicesTimeout = null;
- }
- }
- },
- /**
- * 开始查找设备
- * */
- startBluetoothDeviceDiscovery() {
- //在页面显示的时候判断是都已经初始化完成蓝牙适配器若成功,则开始查找设备
- let _self = this;
- if (_self.bOpenBluetooth) {
- //1.第一步还是先进行设备搜索
- _self.onCanStart();
- } else {
- _self.initAdapter(() => {
- _self.startBluetoothDeviceDiscovery();
- });
- }
- },
- /**
- * 通过检测手机连接的设备进行连接,null 的话进行搜索操作
- */
- onBondedDeviceConnect(data) {
- let _self = this;
- //获取手机本身已连接的硬件,
- //示例
- // {
- // "deviceId": "C5:5C:19:04:00:30",
- // "name": "BGBox_202012",
- // "RSSI": -74,
- // "localName": "BGBox_20201",
- // "advertisServiceUUIDs": ["00001812-0000-1000-8000-00805F9B34FB", "0000FFF0-0000-1000-8000-00805F9B34FB"]
- // }
- console.log("onBoded ***************:", _self.finallyUseDevice);
- _self.B_GetBondedDevices({
- deviceId: _self.finallyUseDevice == null ? null : _self.finallyUseDevice.deviceId,
- success: (bondedDevice) => {
- console.log("bondedDevice:", bondedDevice);
- //获取已和蓝牙连接的设备
- if (bondedDevice != null) {
- //如果用户匹配了对应的设备,直接用对应的设备来连接
- let setDevice = {
- "deviceId": bondedDevice.address,
- "name": bondedDevice.name,
- "RSSI": -74,
- "localName": "",
- "advertisServiceUUIDs": ["00001812-0000-1000-8000-00805F9B34FB",
- "0000FFF0-0000-1000-8000-00805F9B34FB"
- ]
- }
- let obj = Object.assign({}, setDevice, _self.currentItem);
- //finallyUserDevice 就是最后一次使用搜索到的设备信息
- _self.saveObj = Object.assign({}, setDevice, {
- id: _self.currentItem.id
- });
- uni.showToast({
- title: '设备连接中...',
- icon: 'loading',
- duration: 10000,
- mask: true
- })
- console.log("GetBondedDevices:::===", setDevice, _self.currentItem, obj);
- // 先直连,然后判断版本
- _self._onConnectDevice(obj);
- //getBond后发起的连接,不需要检测了
- _self.bTestBondConnect = false;
- } else {
- console.log("没有获取到绑定的设备");
- uni.showToast({
- title: '获取匹配设备失败',
- icon: 'none',
- mask: true
- })
- }
- }
- });
- },
- //开始搜索
- onCanStart() {
- let _self = this;
- uni.showToast({
- title: '设备连接中...',
- icon: 'loading',
- duration: 15000,
- mask: true
- })
- // 1.已经搜索到的,根据蓝牙回调的mac 地址判断合法性。
- uni.startBluetoothDevicesDiscovery({
- allowDuplicatesKey: true,
- success: res => {
- // console.log("startBluetoothDevicesDiscovery:", res);
- _self.bSwitch = false;
- _self.onBluetoothDeviceFound();
- },
- fail: res => {
- console.log("搜索失败!");
- _self.initAdapter(() => {
- _self.startBluetoothDeviceDiscovery();
- });
- }
- });
- // 2.没有搜索到的,一段时间后处理。比如手机已经连接了设备,但是app 里面搜索不到,也没记录使用过的。
- if (_self.searchTimeOut) {
- clearTimeout(_self.searchTimeOut);
- _self.searchTimeOut = null;
- }
- //搜索一段时间后,停止搜索
- if (plus.os.name == 'iOS') {
- _self.searchTimeOut = setTimeout(() => {
- _self.stopBluetoothDevicesDiscovery();
- //搜索失败后,再检查是否和手机配对的设备连接
- _self.onBondedDeviceConnect();
- }, 4000)
- } else {
- _self.searchTimeOut = setTimeout(() => {
- _self.stopBluetoothDevicesDiscovery();
- }, 8000)
- }
- },
- /**
- * 停止搜索蓝牙设备
- */
- stopBluetoothDevicesDiscovery() {
- uni.stopBluetoothDevicesDiscovery({
- success: e => {
- // console.log('停止搜索蓝牙设备:' + e.errMsg);
- },
- fail: e => {
- console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
- }
- });
- },
- /**
- * 发现外围设备
- */
- onBluetoothDeviceFound() {
- let _self = this;
- _self.searchObj = null;
- uni.onBluetoothDeviceFound(res => {
- /**
- * 获取在蓝牙模块生效期间所有已发现的蓝牙设备。包括已经和本机处于连接状态的设备。
- */
- // console.log("onBluetoothDeviceFound:", res);
- res.devices.forEach(device => {
- if (device.name.indexOf('PBox') > -1 || device.name.indexOf('BGBox') > -1 || device
- .name.indexOf('Rope') > -1) {
- //如果搜索的设备名 不是对应当前设备类型,过滤
- // if (device.name.indexOf(_self.currentItem.deviceName) == -1) return;
- if (_self.currentItem.deviceName.indexOf('PBox') == -1 &&
- _self.currentItem.deviceName.indexOf('BGBox') == -1 &&
- _self.currentItem.deviceName.indexOf('Rope') == -1
- ) return;
- //寻找到对应设备时候,其余的返回
- if (_self.searchObj) return;
- _self.searchObj = device;
- if (_self.searchTimeOut) {
- clearTimeout(_self.searchTimeOut);
- _self.searchTimeOut = null;
- }
- //currentItem 是mode 页面选中的item
- let obj = Object.assign({}, device, _self.currentItem);
- _self.saveObj = Object.assign({}, {
- id: _self.currentItem.id
- }, device);
- // console.log(device, "****", obj, _self.saveObj, _self.currentItem)
- // 先直连,然后判断版本
- _self._onConnectDevice(obj);
- _self.stopBluetoothDevicesDiscovery();
- }
- })
- })
- },
- onBack() {
- uni.navigateBack({
- delta: 1
- })
- },
- // 提示点击连接设备
- _onConnectDevice(item) {
- //servicesTimeout
- if (this.getServicesTimeout) {
- clearTimeout(this.getServicesTimeout);
- this.getServicesTimeout = null;
- }
- //写入指令writeMacTimeout
- if (this.writeMacTimeout) {
- clearTimeout(this.writeMacTimeout);
- this.writeMacTimeout = null;
- }
- // //如果已经连接,加上服务不存在,直接获取服务
- // if (this.bConnection && this.BLEGetServices && this.BLEGetServices.length == 0) {
- // console.log("***直接获取服务*******");
- // this.onGetBLEDeviceServices({
- // item: item,
- // success: (res) => {
- // console.log("*****getBLEDeviceServices************");
- // //连接成功了,设置旧的item
- // this.oldItem = this.currentItem;
- // setTimeout(() => {
- // this.saveObj = Object.assign({}, this
- // .saveObj, {
- // deviceMac: '',
- // bOldDevice: false
- // });
- // this.addBLEDevice(this.saveObj);
- // this.ConnectionSuccess();
- // }, 2000)
- // // uni.showToast({
- // // title: '正在验证设备信息...',
- // // icon: 'loading',
- // // duration: 10000,
- // // mask: true
- // // })
- // // // 初始化服务后,获取版本,判断
- // // // 停止蓝牙加速计
- // // this.writeMacTimeout = setTimeout(() => {
- // // //todo 停止蓝牙加速计
- // // // this.onWriteBLEConnectionValue({
- // // // value: "4"
- // // // });
- // // // 发送获取mac
- // // this.onWriteBLEConnectionValue({
- // // value: "M"
- // // });
- // // if (this.searchMac) {
- // // clearTimeout(this.searchMac);
- // // this.searchMac = null;
- // // }
- // // this.searchMac = setTimeout(() => {
- // // uni.hideToast();
- // // uni.showModal({
- // // title: '提示',
- // // content: '检测设备失败。\r\n1.再次尝试连接。\r\n2.或者重启手柄(Reset键位也可)后再尝试连接'
- // // })
- // // this.onOnlyCloseBLEConnection({
- // // getSuccess: () => {
- // // if (this.currentItem)
- // // this.currentItem.bRatio = false;
- // // this.currentItem = null;
- // // }
- // // });
- // // }, 6000)
- // // }, 3000)
- // }
- // });
- // return;
- // }
- //创建一个连接,需要对应close
- this.onCreateBLESuccess({
- item: item,
- getSuccess: () => {
- // console.log("****创建一个连接*******");
- this.getServicesTimeout = setTimeout(() => {
- this.onGetBLEDeviceServices({
- item: item,
- success: (res) => {
- // console.log("******getBLEDeviceServices************", res);
- //连接成功了,设置旧的item
- this.oldItem = this.currentItem;
- setTimeout(() => {
- this.saveObj = Object.assign({}, this
- .saveObj, {
- deviceMac: '',
- bOldDevice: false
- });
- this.addBLEDevice(this.saveObj);
- this.ConnectionSuccess();
- }, 2000)
- // uni.showToast({
- // title: '正在验证设备信息...',
- // icon: 'loading',
- // duration: 10000,
- // mask: true
- // })
- // // 初始化服务后,获取版本,判断
- // // 停止蓝牙加速计
- // this.writeMacTimeout = setTimeout(() => {
- // //todo 停止蓝牙加速计
- // // this.onWriteBLEConnectionValue({
- // // value: "4"
- // // });
- // // 发送获取mac
- // this.onWriteBLEConnectionValue({
- // value: "M"
- // });
- // if (this.searchMac) {
- // clearTimeout(this.searchMac);
- // this.searchMac = null;
- // }
- // this.searchMac = setTimeout(() => {
- // uni.hideToast();
- // uni.showModal({
- // title: '提示',
- // content: '检测设备失败。\r\n1.再次尝试连接。\r\n2.或者重启手柄(Reset键位也可)后再尝试连接'
- // })
- // this.onOnlyCloseBLEConnection({
- // getSuccess: () => {
- // if (this
- // .currentItem
- // )
- // this
- // .currentItem
- // .bRatio =
- // false;
- // this.currentItem =
- // null;
- // }
- // });
- // }, 6000)
- // }, 3000)
- }
- });
- }, 2500);
- }
- })
- },
- _onRadio(item, event) {
- console.log(this.bConnection, this.BLEGetServices);
- if (this.bConnection && this.BLEGetServices && this.BLEGetServices.length == 0) {
- console.log("***直接获取服务*******");
- this.onGetBLEDeviceServices({
- item: item,
- success: (res) => {
- console.log("*****getBLEDeviceServices************");
- //连接成功了,设置旧的item
- this.oldItem = this.currentItem;
- setTimeout(() => {
- this.saveObj = Object.assign({}, this
- .saveObj, {
- deviceMac: '',
- bOldDevice: false
- });
- this.addBLEDevice(this.saveObj);
- this.ConnectionSuccess();
- }, 2000)
- }
- });
- return;
- }
- if (!item.bRatio) {
- //设置默认值
- this.bTestBondConnect = true;
- if (this.BLEConnectDevice) {
- this.onOnlyCloseBLEConnection({
- getSuccess: () => {
- if (this.currentItem)
- this.currentItem.bRatio = false;
- this.currentItem = null;
- this.currentItem = item;
- this.bSwitch = true;
- console.log("this.currentItem1 ==:", this.currentItem, this
- .bOpenBluetooth,
- this.BLEConnectDevice);
- this.startBluetoothDeviceDiscovery();
- }
- });
- return;
- }
- this.currentItem = null;
- this.currentItem = item;
- // console.log("this.currentItem ==2:", this.currentItem, this.bOpenBluetooth, this.BLEConnectDevice);
- this.startBluetoothDeviceDiscovery();
- }
- },
- onClise() {
- this.B_CloseBLEConnection({
- deviceId: "C5:5C:19:04:01:22"
- });
- },
- //跳转进入升级页面,
- onNavUpdateDevice() {
- //需要连接设备后,才能进入升级
- if (!this.currentItem || !this.currentItem.bRatio || !this.BLEConnectDevice) {
- uni.showToast({
- title: '请先连接硬件!',
- icon: 'none'
- })
- return;
- }
- this.bLimitClose = true;
- uni.navigateTo({
- // url: "../devices-update/devices-update?deviceType=" + this.option.deviceType
- url: "../devices-update/devices-update"
- })
- },
- add: function(data) {
- // console.log(data)
- if (this.extraLine.length > 500) {
- this.extraLine = [];
- this.text = this.extraLine.join('\n');
- }
- this.extraLine.push(data);
- this.text = this.extraLine.join('\n');
- },
- remove: function(e) {
- if (this.extraLine.length > 0) {
- // this.extraLine.pop();
- this.extraLine = [];
- this.text = this.extraLine.join('\n');
- }
- },
- writeBLEValue(str) {
- this.onWriteBLEConnectionValue({
- value: str
- })
- },
- onKeyInput: function(event) {
- this.onSetLocationGameUrl(event.target.value);
- }
- }
- }
- </script>
- <style>
- .hardware-border {
- border: 1rpx solid #9898FF;
- box-sizing: border-box;
- }
- .swiper {
- flex: 1;
- background-color: rgba(0, 0, 0, 0.32);
- }
- .swiper-item {
- flex: 1;
- }
- .bluetooth-guide-number {
- border-radius: 18px;
- border-width: 1rpx;
- width: 30px;
- height: 30px;
- text-align: center;
- line-height: 30px;
- color: #000000;
- /* border-color: #FFFFFF; */
- background-color: #FFFFFF;
- margin-right: 13px;
- }
- .text-box {
- margin: 20rpx;
- display: flex;
- width: 95%;
- min-height: 300rpx;
- max-height: 600rpx;
- background-color: #c6c6c6;
- justify-content: center;
- align-items: center;
- text-align: left;
- font-size: 30upx;
- color: #353535;
- line-height: 1.8;
- border: 1rpx solid #555555;
- overflow-y: hidden;
- }
- .content {
- align-content: center;
- height: 300rpx;
- background-color: #F4F5F6;
- }
- .uni-input {
- border: 1rpx solid #000000;
- }
- </style>
|