@yolanda-qn/handheld-height-protocols
v1.0.0
Published
手持身高测量仪
Downloads
3
Readme
手持身高测量仪
关联资源
- 轻牛小程序蓝牙库:https://www.npmjs.com/package/@yolanda-qn/qn-mp-plugin
- 轻牛蓝牙类型库:https://www.npmjs.com/package/@yolanda-qn/qn-ble-types
- demo地址:https://gitee.com/yolandaqingniu/qn_mp_plugin_demo
使用
具体用法查看 pages/handheld-height 目录下的代码
npm install @yolanda-qn/qn-mp-plugin
npm install @yolanda-qn/handheld-height-protocolsimport { QNMPPlugin } from '@yolanda-qn/qn-mp-plugin';
import { HandheldHeightProtocol } from '@yolanda-qn/handheld-height-protocols';
// 初始化蓝牙
this.bleApi = new QNMPPlugin({
useSdk: false, // 体脂秤才需要。这里需要关闭
logger: logger(), // 非必须,日志功能,最好有,方便排查问题,可以替换为客户自己的
protocols: [HandheldHeightProtocol],
});设备事件回调
// 获取设备信息
const onGetDeviceInfo = (device) => {
console.log('获取设备信息', device);
this.setData({ deviceInfo: device.info });
}
// 获取测量结果
const onGetHandHeightData = (handHeightData) => {
console.log('获取测量身高结果', handHeightData);
const { height, heightUnit } = handHeightData;
this.setData({ height, heightUnit });
}
// 获取同步时间结果
const onSyncTimeResult = (state) => {
console.log('同步时间结果', state);
}
// 获取存储数据
const onGetStoredDatas = (historyData) => {
console.warn('获取存储数据', historyData);
this.setData({ historyData });
}
// 设置当前用户结果
const onSetUerResult = ({ setIndexState, setUnitState, userIndex }) => {
if (!setUnitState) {
wx.showToast({ title: '设置单位失败,请确认设备是否支持该单位', icon: 'none' });
}
if (!setIndexState) {
wx.showToast({ title: '设置用户位失败', icon: 'none' });
}
if (setIndexState) this.setData({ userIndex });
}
// 在创建连接时传入
const deviceEventListener = { onGetDeviceInfo, onGetHandHeightData, onSyncTimeResult, onGetStoredDatas, onSetUerResult };
this.bleApi.createBleConnection(device, deviceEventListener);device.info
|字段名|类型|说明| |:--:|:--:|:--:| |userIndex|number|用户位| |bleVersion|number|蓝牙版本| |fwVersion|number|固件版本| |historyCount|number[]|用户历史数据 [用户1, 用户2, 用户3]| |isSupportCm|boolean|设备是否支持 cm 单位| |isSupportFtIn|boolean|设备是否支持 ft:in 单位| |isSupportIn|boolean|设备是否支持 in 单位| |isSupportFt|boolean|设备是否支持 ft 单位|
historyData
| 字段名 | 类型 | 说明 | | :-------: | :----: | :----------: | | height | number | 历史测量数据 | | timestamp | number | 测量时间戳 | | userIndex | number | 用户位 |
handHeightData
| 字段名 | 类型 | 说明 | | :--------: | :----------------: | :----------------------------------------------------: | | userIndex | number | 用户位 | | height | number | 身高测量结果 | | heightUnit | number | 测量单位 | | state | number:01、02、03 | 测量状态:01(成功)| 02(超时)| 03(超出测量范围) |
QNBleHeightUnit
// 身高测量仪单位
export enum QNBleHeightUnit {
CM = 'cm',
FT = 'ft',
IN = 'in',
FTIN = 'ft:in',
}npm install @yolanda-qn/qn-ble-types