区分F01PRO
This commit is contained in:
parent
0464e36310
commit
1703ff1a7c
2
app.json
2
app.json
|
|
@ -4,7 +4,7 @@
|
||||||
"pages/PCD01PRO/index",
|
"pages/PCD01PRO/index",
|
||||||
"pages/H01PRO/index",
|
"pages/H01PRO/index",
|
||||||
"pages/PCH0809/index",
|
"pages/PCH0809/index",
|
||||||
"pages/PCF01B/index",
|
"pages/PCF01pro/index",
|
||||||
"pages/PCF01proFRK/index",
|
"pages/PCF01proFRK/index",
|
||||||
"pages/PCF08/index",
|
"pages/PCF08/index",
|
||||||
"pages/L08/index",
|
"pages/L08/index",
|
||||||
|
|
|
||||||
|
|
@ -1,443 +1,442 @@
|
||||||
const util = require("../../utils/util");
|
const util = require("../../utils/util");
|
||||||
const {
|
const {
|
||||||
inArray,
|
inArray,
|
||||||
ab2hex
|
ab2hex
|
||||||
} = util
|
} = util
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
devices: [],
|
devices: [],
|
||||||
connected: false,
|
connected: false,
|
||||||
cmd: '',
|
cmd: '',
|
||||||
name: '',
|
name: '',
|
||||||
weight: "",
|
weight: "",
|
||||||
text: "",
|
text: "",
|
||||||
imp: "",
|
imp: "",
|
||||||
height: '',
|
height: '',
|
||||||
isType: false,
|
isType: false,
|
||||||
sendVal: true,
|
sendVal: true,
|
||||||
pwdModal: false,
|
pwdModal: false,
|
||||||
uuid1: null,
|
uuid1: null,
|
||||||
uuid2: null,
|
uuid2: null,
|
||||||
uuid3: null,
|
uuid3: null,
|
||||||
deviceId: null,
|
deviceId: null,
|
||||||
serviceId: null
|
serviceId: null
|
||||||
},
|
},
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
// let value = "A90026051401020001439A";
|
// let value = "A90026051401020001439A";
|
||||||
// let num = value.substring(18, 19)
|
// let num = value.substring(18, 19)
|
||||||
// let type = value.substring(8, 10)
|
// let type = value.substring(8, 10)
|
||||||
// let imp = parseInt(value.substring(10, 14), 16)
|
// let imp = parseInt(value.substring(10, 14), 16)
|
||||||
// console.log("16进制转化:", value, num, type, imp);
|
// console.log("16进制转化:", value, num, type, imp);
|
||||||
},
|
},
|
||||||
// 初始化蓝牙模块
|
// 初始化蓝牙模块
|
||||||
openBluetoothAdapter() {
|
openBluetoothAdapter() {
|
||||||
wx.openBluetoothAdapter({
|
wx.openBluetoothAdapter({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('openBluetoothAdapter success', res)
|
console.log('openBluetoothAdapter success', res)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '蓝牙连接中',
|
title: '蓝牙连接中',
|
||||||
icon: "none"
|
icon: "none"
|
||||||
})
|
})
|
||||||
this.startBluetoothDevicesDiscovery()
|
this.startBluetoothDevicesDiscovery()
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
if (res.errCode === 10001) {
|
if (res.errCode === 10001) {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '请打开蓝牙',
|
title: '请打开蓝牙',
|
||||||
icon: "none"
|
icon: "none"
|
||||||
})
|
})
|
||||||
// 监听本机蓝牙状态变化的事件
|
// 监听本机蓝牙状态变化的事件
|
||||||
wx.onBluetoothAdapterStateChange((res) => {
|
wx.onBluetoothAdapterStateChange((res) => {
|
||||||
console.log('onBluetoothAdapterStateChange', res)
|
console.log('onBluetoothAdapterStateChange', res)
|
||||||
if (res.available) {
|
if (res.available) {
|
||||||
this.startBluetoothDevicesDiscovery()
|
this.startBluetoothDevicesDiscovery()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 开始搜寻附近的蓝牙外围设备
|
// 开始搜寻附近的蓝牙外围设备
|
||||||
startBluetoothDevicesDiscovery() {
|
startBluetoothDevicesDiscovery() {
|
||||||
if (this._discoveryStarted) {
|
if (this._discoveryStarted) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._discoveryStarted = true
|
this._discoveryStarted = true
|
||||||
wx.startBluetoothDevicesDiscovery({
|
wx.startBluetoothDevicesDiscovery({
|
||||||
allowDuplicatesKey: true,
|
allowDuplicatesKey: true,
|
||||||
interval: 1000, //上报设备的间隔
|
interval: 1000, //上报设备的间隔
|
||||||
services: [
|
services: [
|
||||||
"FFE0",
|
"FFE0",
|
||||||
],
|
],
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('startBluetoothDevicesDiscovery success', res)
|
console.log('startBluetoothDevicesDiscovery success', res)
|
||||||
this.onBluetoothDeviceFound()
|
this.onBluetoothDeviceFound()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 停止搜寻附近的蓝牙外围设备
|
// 停止搜寻附近的蓝牙外围设备
|
||||||
stopBluetoothDevicesDiscovery() {
|
stopBluetoothDevicesDiscovery() {
|
||||||
wx.stopBluetoothDevicesDiscovery()
|
wx.stopBluetoothDevicesDiscovery()
|
||||||
},
|
},
|
||||||
|
|
||||||
// 找到新设备的事件
|
// 找到新设备的事件
|
||||||
onBluetoothDeviceFound() {
|
onBluetoothDeviceFound() {
|
||||||
wx.onBluetoothDeviceFound((res) => {
|
wx.onBluetoothDeviceFound((res) => {
|
||||||
res.devices.forEach(device => {
|
res.devices.forEach(device => {
|
||||||
if (device.name.indexOf('AiLink_') != -1) {
|
if (device.name.indexOf('AiLink_') != -1) {
|
||||||
wx.stopBluetoothDevicesDiscovery() //搜索到名称为“AiLink_”的蓝牙后,停止搜寻附近的蓝牙
|
wx.stopBluetoothDevicesDiscovery() //搜索到名称为“AiLink_”的蓝牙后,停止搜寻附近的蓝牙
|
||||||
const foundDevices = this.data.devices
|
const foundDevices = this.data.devices
|
||||||
const idx = inArray(foundDevices, 'deviceId', device.deviceId)
|
const idx = inArray(foundDevices, 'deviceId', device.deviceId)
|
||||||
const data = {}
|
const data = {}
|
||||||
let buff = device.advertisData.slice(-6)
|
let buff = device.advertisData.slice(-6)
|
||||||
device.mac = new Uint8Array(buff) // 保存广播数据中的mac地址,这是由于iOS不直接返回mac地址
|
device.mac = new Uint8Array(buff) // 保存广播数据中的mac地址,这是由于iOS不直接返回mac地址
|
||||||
let tempMac = Array.from(device.mac)
|
let tempMac = Array.from(device.mac)
|
||||||
tempMac.reverse()
|
tempMac.reverse()
|
||||||
device.macAddr = ab2hex(tempMac, ':').toUpperCase()
|
device.macAddr = ab2hex(tempMac, ':').toUpperCase()
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
data[`devices[${foundDevices.length}]`] = device
|
data[`devices[${foundDevices.length}]`] = device
|
||||||
} else {
|
} else {
|
||||||
data[`devices[${idx}]`] = device
|
data[`devices[${idx}]`] = device
|
||||||
}
|
}
|
||||||
console.log("131", data)
|
console.log("131", data)
|
||||||
this.setData(data)
|
this.setData(data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 连接低功耗蓝牙设备
|
// 连接低功耗蓝牙设备
|
||||||
createBLEConnection(e) {
|
createBLEConnection(e) {
|
||||||
this._connLoading = true
|
this._connLoading = true
|
||||||
wx.showLoading({
|
wx.showLoading({
|
||||||
title: '连接中',
|
title: '连接中',
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this._connLoading) {
|
if (this._connLoading) {
|
||||||
this._connLoading = false
|
this._connLoading = false
|
||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
}
|
}
|
||||||
}, 6000)
|
}, 6000)
|
||||||
const ds = e.currentTarget.dataset
|
const ds = e.currentTarget.dataset
|
||||||
const index = ds.index
|
const index = ds.index
|
||||||
this._device = this.data.devices[index]
|
this._device = this.data.devices[index]
|
||||||
const deviceId = ds.deviceId
|
const deviceId = ds.deviceId
|
||||||
const name = ds.name
|
const name = ds.name
|
||||||
this.mac = ds.mac
|
this.mac = ds.mac
|
||||||
wx.createBLEConnection({
|
wx.createBLEConnection({
|
||||||
deviceId,
|
deviceId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
this.setData({
|
this.setData({
|
||||||
connected: true,
|
connected: true,
|
||||||
name,
|
name,
|
||||||
deviceId,
|
deviceId,
|
||||||
})
|
})
|
||||||
console.log("createBLEConnection:success")
|
console.log("createBLEConnection:success")
|
||||||
this.onBLEConnectionStateChange()
|
this.onBLEConnectionStateChange()
|
||||||
this.getBLEDeviceServices(deviceId)
|
this.getBLEDeviceServices(deviceId)
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
this._connLoading = false
|
this._connLoading = false
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '连接失败',
|
title: '连接失败',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
//监听蓝牙连接状态
|
//监听蓝牙连接状态
|
||||||
onBLEConnectionStateChange() {
|
onBLEConnectionStateChange() {
|
||||||
wx.onBLEConnectionStateChange((res) => {
|
wx.onBLEConnectionStateChange((res) => {
|
||||||
if (!res.connected) {
|
if (!res.connected) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '连接已断开',
|
title: '连接已断开',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
}, 500)
|
}, 500)
|
||||||
this.setData({
|
this.setData({
|
||||||
connected: false,
|
connected: false,
|
||||||
isType: false,
|
isType: false,
|
||||||
devices: [],
|
devices: [],
|
||||||
weight: "",
|
weight: "",
|
||||||
height: "",
|
height: "",
|
||||||
text: "",
|
text: "",
|
||||||
imp: ""
|
imp: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取蓝牙设备的 serviceId
|
// 获取蓝牙设备的 serviceId
|
||||||
getBLEDeviceServices(deviceId) {
|
getBLEDeviceServices(deviceId) {
|
||||||
wx.getBLEDeviceServices({
|
wx.getBLEDeviceServices({
|
||||||
deviceId,
|
deviceId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
for (let i = 0; i < res.services.length; i++) {
|
for (let i = 0; i < res.services.length; i++) {
|
||||||
if (res.services[i].isPrimary && res.services[i].uuid.indexOf('FFE0') > -1) {
|
if (res.services[i].isPrimary && res.services[i].uuid.indexOf('FFE0') > -1) {
|
||||||
this.data.serviceId = res.services[i].uuid
|
this.data.serviceId = res.services[i].uuid
|
||||||
this.data.deviceId = deviceId
|
this.data.deviceId = deviceId
|
||||||
this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
|
this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '获取设备的UUID成功',
|
title: '获取设备的UUID成功',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取蓝牙设备某个服务中所有特征值(characteristic)
|
// 获取蓝牙设备某个服务中所有特征值(characteristic)
|
||||||
/**
|
/**
|
||||||
* read: true读,write: true写,notify: true广播
|
* read: true读,write: true写,notify: true广播
|
||||||
*/
|
*/
|
||||||
getBLEDeviceCharacteristics(deviceId, serviceId) {
|
getBLEDeviceCharacteristics(deviceId, serviceId) {
|
||||||
this._deviceId = deviceId
|
this._deviceId = deviceId
|
||||||
this._serviceId = serviceId
|
this._serviceId = serviceId
|
||||||
this._device.serviceId = serviceId
|
this._device.serviceId = serviceId
|
||||||
let that = this
|
let that = this
|
||||||
wx.getBLEDeviceCharacteristics({
|
wx.getBLEDeviceCharacteristics({
|
||||||
deviceId,
|
deviceId,
|
||||||
serviceId,
|
serviceId,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('getBLEDeviceCharacteristics success', res.characteristics)
|
console.log('getBLEDeviceCharacteristics success', res.characteristics)
|
||||||
for (let i = 0; i < res.characteristics.length; i++) {
|
for (let i = 0; i < res.characteristics.length; i++) {
|
||||||
let item = res.characteristics[i];
|
let item = res.characteristics[i];
|
||||||
if (item.uuid.indexOf('FFE1') != -1) {
|
if (item.uuid.indexOf('FFE1') != -1) {
|
||||||
that.data.uuid1 = item.uuid //主服务 UUID
|
that.data.uuid1 = item.uuid //主服务 UUID
|
||||||
} else if (item.uuid.indexOf('FFE2') != -1) {
|
} else if (item.uuid.indexOf('FFE2') != -1) {
|
||||||
that.data.uuid2 = item.uuid //写入设置
|
that.data.uuid2 = item.uuid //写入设置
|
||||||
} else if (item.uuid.indexOf('FFE3') != -1) {
|
} else if (item.uuid.indexOf('FFE3') != -1) {
|
||||||
that.data.uuid3 = item.uuid //监听数据
|
that.data.uuid3 = item.uuid //监听数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
that.setData({
|
that.setData({
|
||||||
isType: true,
|
isType: true,
|
||||||
})
|
})
|
||||||
wx.notifyBLECharacteristicValueChange({
|
wx.notifyBLECharacteristicValueChange({
|
||||||
deviceId,
|
deviceId,
|
||||||
serviceId,
|
serviceId,
|
||||||
characteristicId: that.data.uuid2,
|
characteristicId: that.data.uuid2,
|
||||||
state: true,
|
state: true,
|
||||||
})
|
})
|
||||||
wx.notifyBLECharacteristicValueChange({
|
wx.notifyBLECharacteristicValueChange({
|
||||||
deviceId,
|
deviceId,
|
||||||
serviceId,
|
serviceId,
|
||||||
characteristicId: that.data.uuid3,
|
characteristicId: that.data.uuid3,
|
||||||
state: true,
|
state: true,
|
||||||
})
|
})
|
||||||
wx.onBLECharacteristicValueChange((res) => {
|
wx.onBLECharacteristicValueChange((res) => {
|
||||||
let value = ab2hex(res.value, "");
|
let value = ab2hex(res.value, "");
|
||||||
console.log("16进制转化:", value);
|
let num = value.substring(18, 19)
|
||||||
let num = value.substring(18, 19)
|
let dw = value.substring(19, 20)
|
||||||
let dw = value.substring(19, 20)
|
let type = value.substring(8, 10)
|
||||||
let type = value.substring(8, 10)
|
let typeInfo = value.substring(10, 12)
|
||||||
let typeInfo = value.substring(10, 12)
|
console.log("16进制转化:", value, type);
|
||||||
console.log("16进制转化:", value);
|
if (type == '10') {
|
||||||
if (type == '10') {
|
let data = parseInt(value.substring(13, 18), 16)
|
||||||
let data = parseInt(value.substring(13, 18), 16)
|
let dw1 = "kg"
|
||||||
let dw1 = "kg"
|
if (dw == "1") {
|
||||||
if (dw == "1") {
|
dw1 = "斤"
|
||||||
dw1 = "斤"
|
console.log("体重单位:斤")
|
||||||
console.log("体重单位:斤")
|
}
|
||||||
}
|
if (dw == "4") {
|
||||||
if (dw == "4") {
|
dw1 = "st:lb"
|
||||||
dw1 = "st:lb"
|
console.log("体重单位:st:lb,计算方法:1 * data + 5")
|
||||||
console.log("体重单位:st:lb,计算方法:1 * data + 5")
|
}
|
||||||
}
|
if (dw == "6") {
|
||||||
if (dw == "6") {
|
dw1 = "lb"
|
||||||
dw1 = "lb"
|
console.log("体重单位:lb")
|
||||||
console.log("体重单位:lb")
|
}
|
||||||
}
|
if (num == "1") {
|
||||||
if (num == "1") {
|
data = parseInt(value.substring(13, 18), 16) / 10
|
||||||
data = parseInt(value.substring(13, 18), 16) / 10
|
console.log("体重小数点后1位")
|
||||||
console.log("体重小数点后1位")
|
}
|
||||||
}
|
if (num == "2") {
|
||||||
if (num == "2") {
|
data = parseInt(value.substring(13, 18), 16) / 100
|
||||||
data = parseInt(value.substring(13, 18), 16) / 100
|
console.log("体重小数点后2位")
|
||||||
console.log("体重小数点后2位")
|
}
|
||||||
}
|
if (num == "3") {
|
||||||
if (num == "3") {
|
data = parseInt(value.substring(13, 18), 16) / 1000
|
||||||
data = parseInt(value.substring(13, 18), 16) / 1000
|
console.log("体重小数点后3位")
|
||||||
console.log("体重小数点后3位")
|
}
|
||||||
}
|
if (typeInfo == "01") {
|
||||||
if (typeInfo == "01") {
|
console.log("实时体重:", data)
|
||||||
console.log("实时体重:", data)
|
that.setData({
|
||||||
that.setData({
|
weight: "实时体重是:" + data + dw1
|
||||||
weight: "实时体重是:" + data + dw1
|
})
|
||||||
})
|
}
|
||||||
}
|
if (typeInfo == "02") {
|
||||||
if (typeInfo == "02") {
|
console.log("稳定体重:", data)
|
||||||
console.log("稳定体重:", data)
|
that.setData({
|
||||||
that.setData({
|
weight: "稳定体重是:" + data + dw1
|
||||||
weight: "稳定体重是:" + data + dw1
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
if (type == "14") { //身高模式
|
||||||
if (type == "14") { //身高模式
|
let height = parseInt(value.substring(10, 14), 16)
|
||||||
let height = parseInt(value.substring(10, 14), 16)
|
that.setData({
|
||||||
that.setData({
|
height: "您的身高是:" + height
|
||||||
height: "您的身高是:" + height
|
})
|
||||||
})
|
console.log("身高模式:", height)
|
||||||
console.log("身高模式:", height)
|
}
|
||||||
}
|
if (type == "11") {
|
||||||
if (type == "11") {
|
console.log("阻抗值:", value)
|
||||||
console.log("阻抗值:", value)
|
if (typeInfo == "03" || typeInfo == "04") {
|
||||||
if (typeInfo == "03" || typeInfo == "04") {
|
let imp = parseInt(value.substring(17, 22), 16)
|
||||||
let imp = parseInt(value.substring(17, 22), 16)
|
that.setData({
|
||||||
that.setData({
|
imp: "阻抗值:" + imp
|
||||||
imp: "阻抗值:" + imp
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
if (value.toUpperCase() == "A90026023000589A") {
|
||||||
if (value.toUpperCase() == "A90026023000589A") {
|
that.setData({
|
||||||
that.setData({
|
text: "测量完成"
|
||||||
text: "测量完成"
|
})
|
||||||
})
|
}
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
},
|
fail(res) {
|
||||||
fail(res) {
|
console.error('getBLEDeviceCharacteristics', res)
|
||||||
console.error('getBLEDeviceCharacteristics', res)
|
}
|
||||||
}
|
})
|
||||||
})
|
},
|
||||||
},
|
handleHeight(e) {
|
||||||
handleHeight(e) {
|
let that = this
|
||||||
let that = this
|
let type = e.currentTarget.dataset.name
|
||||||
let type = e.currentTarget.dataset.name
|
if (type == '1') {
|
||||||
if (type == '1') {
|
let j = Number(26 + 3 + 6 + 1).toString(16)
|
||||||
let j = Number(26 + 3 + 6 + 1).toString(16)
|
let str = "A9002603060100" + j.substr(j.length - 2, 2) + "9A"
|
||||||
let str = "A9002603060100" + j.substr(j.length - 2, 2) + "9A"
|
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
||||||
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
return parseInt(h, 16)
|
||||||
return parseInt(h, 16)
|
}))
|
||||||
}))
|
that.sendData(buf.buffer)
|
||||||
that.sendData(buf.buffer)
|
}
|
||||||
}
|
if (type == '2') {
|
||||||
if (type == '2') {
|
let j = Number(26 + 3 + 6 + 2).toString(16)
|
||||||
let j = Number(26 + 3 + 6 + 2).toString(16)
|
let str = "A9002603060200" + j.substr(j.length - 2, 2) + "9A"
|
||||||
let str = "A9002603060200" + j.substr(j.length - 2, 2) + "9A"
|
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
||||||
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
return parseInt(h, 16)
|
||||||
return parseInt(h, 16)
|
}))
|
||||||
}))
|
that.sendData(buf.buffer)
|
||||||
that.sendData(buf.buffer)
|
}
|
||||||
}
|
if (type == '3') {
|
||||||
if (type == '3') {
|
that.setData({
|
||||||
that.setData({
|
pwdModal: true,
|
||||||
pwdModal: true,
|
})
|
||||||
})
|
}
|
||||||
}
|
},
|
||||||
},
|
confirmPwd() {
|
||||||
confirmPwd() {
|
let that = this
|
||||||
let that = this
|
if (!that.data.pwdInput) {
|
||||||
if (!that.data.pwdInput) {
|
wx.showToast({
|
||||||
wx.showToast({
|
title: '请输入重量',
|
||||||
title: '请输入重量',
|
duration: 2000,
|
||||||
duration: 2000,
|
icon: 'none'
|
||||||
icon: 'none'
|
})
|
||||||
})
|
return
|
||||||
return
|
} else {
|
||||||
} else {
|
let w = Number(that.data.pwdInput.replace(/[&\|\\\*^%$#@\.-]/g, ""))
|
||||||
let w = Number(that.data.pwdInput.replace(/[&\|\\\*^%$#@\.-]/g, ""))
|
let j = Number(26 + 7 + 40 + w + 3 + 2).toString(16) //校验和
|
||||||
let j = Number(26 + 7 + 40 + w + 3 + 2).toString(16) //校验和
|
let atr = w.toString(16) //16进制后的标定数据
|
||||||
let atr = w.toString(16) //16进制后的标定数据
|
let num = 0 //小数位数
|
||||||
let num = 0 //小数位数
|
let str = null
|
||||||
let str = null
|
if (that.data.pwdInput.indexOf('.') != -1) {
|
||||||
if (that.data.pwdInput.indexOf('.') != -1) {
|
num = Number(that.data.pwdInput.toString().split(".")[1].length)
|
||||||
num = Number(that.data.pwdInput.toString().split(".")[1].length)
|
}
|
||||||
}
|
// 根据atr的位数判断下发的体重填充几个0
|
||||||
// 根据atr的位数判断下发的体重填充几个0
|
let n = []
|
||||||
let n = []
|
for (var i = 1; i <= (6 - atr.length); i++) {
|
||||||
for (var i = 1; i <= (6 - atr.length); i++) {
|
n.push(0);
|
||||||
n.push(0);
|
}
|
||||||
}
|
str = "A90026074003" + n.join("") + atr + "0" + num + "00" + j.substr(j.length - 2, 2) + "9A"
|
||||||
str = "A90026074003" + n.join("") + atr + "0" + num + "00" + j.substr(j.length - 2, 2) + "9A"
|
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
||||||
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
return parseInt(h, 16)
|
||||||
return parseInt(h, 16)
|
}))
|
||||||
}))
|
that.sendData(buf.buffer)
|
||||||
that.sendData(buf.buffer)
|
}
|
||||||
}
|
},
|
||||||
},
|
sendData(buffer) {
|
||||||
sendData(buffer) {
|
let that = this
|
||||||
let that = this
|
wx.writeBLECharacteristicValue({
|
||||||
wx.writeBLECharacteristicValue({
|
deviceId: that.data.deviceId,
|
||||||
deviceId: that.data.deviceId,
|
serviceId: that.data.serviceId,
|
||||||
serviceId: that.data.serviceId,
|
characteristicId: that.data.uuid1,
|
||||||
characteristicId: that.data.uuid1,
|
value: buffer,
|
||||||
value: buffer,
|
success: res => {
|
||||||
success: res => {
|
console.log('下发指令', res.errMsg)
|
||||||
console.log('下发指令', res.errMsg)
|
wx.showToast({
|
||||||
wx.showToast({
|
title: '下发指令成功',
|
||||||
title: '下发指令成功',
|
duration: 2000,
|
||||||
duration: 2000,
|
icon: 'none'
|
||||||
icon: 'none'
|
})
|
||||||
})
|
this.setData({
|
||||||
this.setData({
|
pwdModal: false,
|
||||||
pwdModal: false,
|
})
|
||||||
})
|
},
|
||||||
},
|
fail: res => {
|
||||||
fail: res => {
|
wx.showToast({
|
||||||
wx.showToast({
|
title: '下发指令失败',
|
||||||
title: '下发指令失败',
|
duration: 2000,
|
||||||
duration: 2000,
|
icon: 'none'
|
||||||
icon: 'none'
|
})
|
||||||
})
|
this.setData({
|
||||||
this.setData({
|
pwdModal: false,
|
||||||
pwdModal: false,
|
})
|
||||||
})
|
console.log("失败", res);
|
||||||
console.log("失败", res);
|
},
|
||||||
},
|
})
|
||||||
})
|
},
|
||||||
},
|
closeModal() {
|
||||||
closeModal() {
|
this.setData({
|
||||||
this.setData({
|
pwdModal: false,
|
||||||
pwdModal: false,
|
})
|
||||||
})
|
},
|
||||||
},
|
/**
|
||||||
/**
|
* 断开蓝牙模块
|
||||||
* 断开蓝牙模块
|
*/
|
||||||
*/
|
closeBluetoothAdapter() {
|
||||||
closeBluetoothAdapter() {
|
wx.closeBluetoothAdapter()
|
||||||
wx.closeBluetoothAdapter()
|
this._discoveryStarted = false
|
||||||
this._discoveryStarted = false
|
wx.showToast({
|
||||||
wx.showToast({
|
title: '断开蓝牙模块',
|
||||||
title: '断开蓝牙模块',
|
duration: 2000,
|
||||||
duration: 2000,
|
icon: 'none'
|
||||||
icon: 'none'
|
})
|
||||||
})
|
this.setData({
|
||||||
this.setData({
|
devices: [],
|
||||||
devices: [],
|
weight: "",
|
||||||
weight: "",
|
height: "",
|
||||||
height: "",
|
text: "",
|
||||||
text: "",
|
imp: "",
|
||||||
imp: "",
|
isType: false
|
||||||
isType: false
|
})
|
||||||
})
|
},
|
||||||
},
|
// 断开与低功耗蓝牙设备的连接
|
||||||
// 断开与低功耗蓝牙设备的连接
|
closeBLEConnection() {
|
||||||
closeBLEConnection() {
|
wx.closeBLEConnection({
|
||||||
wx.closeBLEConnection({
|
deviceId: this._deviceId
|
||||||
deviceId: this._deviceId
|
})
|
||||||
})
|
wx.showToast({
|
||||||
wx.showToast({
|
title: '断开蓝牙连接',
|
||||||
title: '断开蓝牙连接',
|
duration: 2000,
|
||||||
duration: 2000,
|
icon: 'none'
|
||||||
icon: 'none'
|
})
|
||||||
})
|
this.setData({
|
||||||
this.setData({
|
connected: false,
|
||||||
connected: false,
|
isType: false,
|
||||||
isType: false,
|
devices: [],
|
||||||
devices: [],
|
text: "",
|
||||||
text: "",
|
weight: "",
|
||||||
weight: "",
|
height: "",
|
||||||
height: "",
|
imp: ""
|
||||||
imp: ""
|
})
|
||||||
})
|
},
|
||||||
},
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ Page({
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if (type == 'PCF01B') {
|
if (type == 'PCF01pro') {
|
||||||
// wx.navigateTo({
|
wx.navigateTo({
|
||||||
// url: `/pages/PCF01B/index`
|
url: `/pages/PCF01pro/index`
|
||||||
// })
|
})
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
if (type == 'PCF01proFRK') {
|
if (type == 'PCF01proFRK') {
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: `/pages/PCF01proFRK/index`
|
url: `/pages/PCF01proFRK/index`
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
<view class="item" bindtap="editclick" data-name="FB03">B03/B02/B07</view>
|
<view class="item" bindtap="editclick" data-name="FB03">B03/B02/B07</view>
|
||||||
<view class="item" bindtap="editclick" data-name="PCL10">PCL10/PCL11</view>
|
<view class="item" bindtap="editclick" data-name="PCL10">PCL10/PCL11</view>
|
||||||
<view class="item" bindtap="editclick" data-name="PCF01proFRK">PCF01pro(旧)</view>
|
<view class="item" bindtap="editclick" data-name="PCF01proFRK">PCF01pro(旧)</view>
|
||||||
<view class="item" bindtap="editclick" data-name="PCF01B">PCF01pro(新)</view>
|
<view class="item" bindtap="editclick" data-name="G01">G01</view>
|
||||||
<view class="item" bindtap="editclick" data-name="G01">G01</view>
|
<!-- <view class="item" bindtap="editclick" data-name="PCF01pro">PCF01pro(新)</view>-->
|
||||||
<!-- <view class="item" bindtap="editclick" data-name="PCL11">PCL11</view> -->
|
<!-- <view class="item" bindtap="editclick" data-name="PCL11">PCL11</view> -->
|
||||||
<!-- <view class="item" bindtap="editclick" data-name="h018">h018</view> -->
|
<!-- <view class="item" bindtap="editclick" data-name="h018">h018</view> -->
|
||||||
<!-- <view class="item" bindtap="editclick" data-name="PCF01B">PCF01B</view> -->
|
<!-- <view class="item" bindtap="editclick" data-name="PCF01B">PCF01B</view> -->
|
||||||
|
|
|
||||||
|
|
@ -1,56 +1,56 @@
|
||||||
{
|
{
|
||||||
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"include": []
|
"include": []
|
||||||
|
},
|
||||||
|
"setting": {
|
||||||
|
"urlCheck": true,
|
||||||
|
"es6": false,
|
||||||
|
"enhance": true,
|
||||||
|
"postcss": true,
|
||||||
|
"preloadBackgroundData": false,
|
||||||
|
"minified": true,
|
||||||
|
"newFeature": false,
|
||||||
|
"coverView": true,
|
||||||
|
"nodeModules": false,
|
||||||
|
"autoAudits": false,
|
||||||
|
"showShadowRootInWxmlPanel": true,
|
||||||
|
"scopeDataCheck": false,
|
||||||
|
"uglifyFileName": false,
|
||||||
|
"checkInvalidKey": true,
|
||||||
|
"checkSiteMap": true,
|
||||||
|
"uploadWithSourceMap": true,
|
||||||
|
"compileHotReLoad": false,
|
||||||
|
"lazyloadPlaceholderEnable": false,
|
||||||
|
"useMultiFrameRuntime": true,
|
||||||
|
"useApiHook": true,
|
||||||
|
"useApiHostProcess": true,
|
||||||
|
"babelSetting": {
|
||||||
|
"ignore": [],
|
||||||
|
"disablePlugins": [],
|
||||||
|
"outputPath": ""
|
||||||
},
|
},
|
||||||
"setting": {
|
"useIsolateContext": true,
|
||||||
"urlCheck": true,
|
"userConfirmedBundleSwitch": false,
|
||||||
"es6": false,
|
"packNpmManually": false,
|
||||||
"enhance": true,
|
"packNpmRelationList": [],
|
||||||
"postcss": true,
|
"minifyWXSS": true,
|
||||||
"preloadBackgroundData": false,
|
"disableUseStrict": false,
|
||||||
"minified": true,
|
"minifyWXML": true,
|
||||||
"newFeature": false,
|
"showES6CompileOption": false,
|
||||||
"coverView": true,
|
"useCompilerPlugins": false,
|
||||||
"nodeModules": false,
|
"ignoreUploadUnusedFiles": true
|
||||||
"autoAudits": false,
|
},
|
||||||
"showShadowRootInWxmlPanel": true,
|
"compileType": "miniprogram",
|
||||||
"scopeDataCheck": false,
|
"libVersion": "2.16.0",
|
||||||
"uglifyFileName": false,
|
"projectname": "bluetooth_demo",
|
||||||
"checkInvalidKey": true,
|
"simulatorType": "wechat",
|
||||||
"checkSiteMap": true,
|
"simulatorPluginLibVersion": {},
|
||||||
"uploadWithSourceMap": true,
|
"appid": "wxcea3504a31518eb6",
|
||||||
"compileHotReLoad": false,
|
"editorSetting": {
|
||||||
"lazyloadPlaceholderEnable": false,
|
"tabIndent": "insertSpaces",
|
||||||
"useMultiFrameRuntime": false,
|
"tabSize": 2
|
||||||
"useApiHook": false,
|
},
|
||||||
"useApiHostProcess": false,
|
"condition": {}
|
||||||
"babelSetting": {
|
|
||||||
"ignore": [],
|
|
||||||
"disablePlugins": [],
|
|
||||||
"outputPath": ""
|
|
||||||
},
|
|
||||||
"useIsolateContext": false,
|
|
||||||
"userConfirmedBundleSwitch": false,
|
|
||||||
"packNpmManually": false,
|
|
||||||
"packNpmRelationList": [],
|
|
||||||
"minifyWXSS": true,
|
|
||||||
"disableUseStrict": false,
|
|
||||||
"minifyWXML": true,
|
|
||||||
"showES6CompileOption": false,
|
|
||||||
"useCompilerPlugins": false,
|
|
||||||
"ignoreUploadUnusedFiles": true
|
|
||||||
},
|
|
||||||
"compileType": "miniprogram",
|
|
||||||
"libVersion": "2.16.0",
|
|
||||||
"projectname": "bluetooth_demo",
|
|
||||||
"simulatorType": "wechat",
|
|
||||||
"simulatorPluginLibVersion": {},
|
|
||||||
"appid": "wxcea3504a31518eb6",
|
|
||||||
"editorSetting": {
|
|
||||||
"tabIndent": "insertSpaces",
|
|
||||||
"tabSize": 2
|
|
||||||
},
|
|
||||||
"condition": {}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue