Bläddra i källkod

删除多余代码

master
elinkthings 4 år sedan
förälder
incheckning
27a7b88775
2 ändrade filer med 4 tillägg och 131 borttagningar
  1. 4
    95
      wifi_ble_demo/pages/index/index.js
  2. 0
    36
      wifi_ble_demo/pages/index/index.wxml

+ 4
- 95
wifi_ble_demo/pages/index/index.js Visa fil

@@ -55,7 +55,7 @@ Page({
title: '请打开蓝牙',
icon: "none"
})
wx.onBluetoothAdapterStateChange(function (res) {
wx.onBluetoothAdapterStateChange( (res)=> {
console.log('onBluetoothAdapterStateChange', res)
if (res.available) {
this.startBluetoothDevicesDiscovery()
@@ -88,7 +88,6 @@ Page({
allowDuplicatesKey: true,
services: [
"FFE0",
// "F0A0", // BM30广播模块需加上,如使用连接模块可忽略
],
success: (res) => {
console.log('startBluetoothDevicesDiscovery success', res)
@@ -113,22 +112,13 @@ Page({
const data = {}
// console.log(device)
// console.log(ab2hex(device.advertisData))
// 此处判断是否BM30广播模块,如使用连接模块请删除此 if ,只保留 else 内容
if (device.advertisServiceUUIDs[0].indexOf("F0A0") !== -1) {
let parseDataRes = plugin.parseBroadcastData(device.advertisData)
console.log(parseDataRes)
if (parseDataRes.status == 1) {
let analyzeData = plugin.analyzeBroadcastScaleData(parseDataRes)
console.log(analyzeData)
device.analyzeDataText = analyzeData.text
}
} else {
let buff = device.advertisData.slice(-6)
device.mac = new Uint8Array(buff) // 保存广播数据中的mac地址,这是由于iOS不直接返回mac地址
let tempMac = Array.from(device.mac)
tempMac.reverse()
device.macAddr = ab2hex(tempMac, ':').toUpperCase()
}
if (idx === -1) {
data[`devices[${foundDevices.length}]`] = device
} else {
@@ -244,31 +234,6 @@ Page({
success: (res) => {
console.log('getBLEDeviceCharacteristics success', res.characteristics)

// 这部分功能在插件的 initPlugin 中已实现,如需用到其中的 uuid 也可取消注释
// for (let i = 0; i < res.characteristics.length; i++) {
// let item = res.characteristics[i]
// if (item.uuid.indexOf('0000FFE1') != -1) {
// this.uuid1 = item.uuid //下发数据
// } else if (item.uuid.indexOf('0000FFE2') != -1) {
// this.uuid2 = item.uuid //监听数据
// } else if (item.uuid.indexOf('0000FFE3') != -1) {
// this.uuid3 = item.uuid //写入设置
// }
// }
// // 打开监听
// wx.notifyBLECharacteristicValueChange({
// deviceId,
// serviceId,
// characteristicId: this.uuid2,
// state: true,
// })
// wx.notifyBLECharacteristicValueChange({
// deviceId,
// serviceId,
// characteristicId: this.uuid3,
// state: true,
// })

// 初始化插件
plugin.initPlugin(res.characteristics, this._device)

@@ -287,63 +252,7 @@ Page({
this.toConnectWifi()
},500)
} else if (bleData.status == 1) {
let payload = bleData.data //对应协议中的payload数据,可以自行解析该数据
// console.log(ab2hex(payload, ' '))
// console.log(ab2hex(bleData.completeData, ' '))

// 以体脂秤数据解析为例
switch (payload[0]) {
/*
* 例如: A7 00 0E 05 01 00 01 F4 10 19 7A---------50.0kg
* 其中 01 00 01 F4 10 为 payload
* 具体指令请根据协议解析
*/
case 0x01:
case 0x02:
let weightValue = (payload[1] << 16) | (payload[2] << 8) | payload[3]
let decPoint = (payload[4] & 0xf0) >> 4
let unit = payload[4] & 0x0f
// console.log("体重数值:" + weightValue)
// console.log("小数点:" + decPoint)
// console.log("单位:" + unit)
if (unit == 1) { // 单位为斤
this._weight = weightValue / 2
} else {
// ... 其他单位
}
this._weight = weightValue / (decPoint * 10) // 除去小数点位数
break;
// ...
/*
* 例如: A7 00 0E 03 07 02 30 4A 7A---------阻抗测量成功,阻抗 560Ω
* 其中 07 02 30 为 payload
* 具体指令请根据协议解析
*/
case 0x07:
this._adc = (payload[1] << 8) | payload[2]
break;
case 0x0A:
//测量完成
let bodyData = plugin.getBodyData(1, 20, 170, this._weight, this._adc) // 体脂秤数据解析
console.log("解析后的体脂数据: ", bodyData)
console.log(util.getWeightDisplay(170, this._weight))
break;
}

const idx = inArray(this.data.chs, 'uuid', characteristic.characteristicId)
const data = {}
if (idx === -1) {
data[`chs[${this.data.chs.length}]`] = {
uuid: characteristic.characteristicId,
value: ab2hex(bleData.completeData, ' ')
}
} else {
data[`chs[${idx}]`] = {
uuid: characteristic.characteristicId,
value: ab2hex(bleData.completeData, ' ')
}
}
this.setData(data)
console.log('A7-----^')
} else if (bleData.status == 2) {
console.log('A6-----^')
}

+ 0
- 36
wifi_ble_demo/pages/index/index.wxml Visa fil

@@ -34,41 +34,5 @@ module.exports.len = function(arr) {
</view>
</scroll-view>
<view class="connected_info" wx:if="{{connected}}">
<view>
<text>已连接到 {{name}}</text>
<view class="operation">
<!-- <button wx:if="{{canWrite}}" size="mini" bindtap="writeBLECharacteristicValue">写数据</button> -->
<button size="mini" bindtap="showWriteInputView" style="line-height:54rpx; font-size:28rpx;padding:0 20rpx;margin-right:10rpx" wx:if="{{0}}">写入指令</button>
<button size="mini" bindtap="toConnectWifi" style="line-height:54rpx; font-size:28rpx;padding:0 20rpx;margin-right:10rpx">连接wifi</button>
<button size="mini" bindtap="closeBLEConnection" style="line-height:54rpx; font-size:28rpx;padding:0 20rpx;">断开连接</button>
</view>
</view>
<view wx:for="{{chs}}" wx:key="index" style="font-size: 26rpx; margin-top: 20rpx;">
<view>特性值: {{item.value}}</view>
</view>
</view>
<view class="writeInputView" wx:if="{{showWriteInput}}">
<view class="writeInput">
<input type="text" model:value="{{cmd}}"></input>
</view>
<view class="hint">请输入16进制数,Byte之间用空格或英文逗号分隔</view>
<view class="btns">
<button bindtap="submitCmd" style="line-height:70rpx; font-size:30rpx;padding:0 50rpx;margin-right:30rpx;">发送</button>
<button bindtap="hideWriteInputView" style="line-height:70rpx; font-size:30rpx;padding:0 50rpx;">取消</button>
</view>
<view class="history">
<view class="history_title">历史记录:</view>
<scroll-view class="history_wrap" scroll-y="true">
<view class="history_item" wx:for="{{historyList}}" wx:key="index">
<view class="history_cmd">{{item.cmd}}</view>
<view class="history_btns">
<button size="mini" bindtap="history_send" data-index="{{index}}" style="line-height:54rpx; font-size:24rpx;padding:0 30rpx;">发送</button>
<button size="mini" bindtap="history_delete" data-index="{{index}}" style="line-height:54rpx; font-size:24rpx;padding:0 30rpx;margin-left:20rpx">删除</button>
</view>
</view>
</scroll-view>
</view>
</view>
</view>

Laddar…
Avbryt
Spara