|
|
@@ -254,8 +254,24 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.init();
|
|
|
- this.getBodyInfo();
|
|
|
+ // 演示模式
|
|
|
+ if (this.runMode == 'mock') {
|
|
|
+ // 加载演示模式的身体数据
|
|
|
+ this.username = '演示人员';
|
|
|
+ this.sex = 1;//1 male 2female
|
|
|
+ this.height = 132;
|
|
|
+ this.age = 7;
|
|
|
+ this.weight = 26;
|
|
|
+ this.peaceHeart = 65;
|
|
|
+ this.heartMax = 203.1;
|
|
|
+ this.heartRate = 170;
|
|
|
+ this.calcCalorie(this.heartRate);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 真实模式
|
|
|
+ this.init();
|
|
|
+ this.getBodyInfo();
|
|
|
+ }
|
|
|
|
|
|
// 获取上课状态
|
|
|
clearInterval(this.timerisClass);
|
|
|
@@ -336,7 +352,8 @@ export default {
|
|
|
},
|
|
|
allPlusReady() {
|
|
|
let that = this;
|
|
|
- // that.setWakelock();
|
|
|
+ // 屏幕常亮
|
|
|
+ that.setWakelock();
|
|
|
plus.bluetooth.onBLECharacteristicValueChange(function(e) {
|
|
|
if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
|
|
|
// 获取电量
|
|
|
@@ -557,11 +574,15 @@ export default {
|
|
|
// 获取服务的特征值
|
|
|
var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
|
|
|
var Batteryuuid = "0000180F-0000-1000-8000-00805F9B34FB";//Battery
|
|
|
- that.getBatteryCharacteristics(w.deviceId, Batteryuuid);
|
|
|
+
|
|
|
+ let HeartRateChaaracterUuid = '00002A37-0000-1000-8000-00805F9B34FB';
|
|
|
+ let BatteryChaaracterUuid = '00002A19-0000-1000-8000-00805F9B34FB';
|
|
|
+ // that.getBatteryCharacteristics(w.deviceId, Batteryuuid);
|
|
|
+ that.getCharacteristics(w.deviceId, Batteryuuid, BatteryChaaracterUuid);
|
|
|
clearTimeout(that.timer); //清除延迟执行
|
|
|
that.timer = setTimeout(() => { //设置延迟执行
|
|
|
// 获取心跳服务
|
|
|
- that.getCharacteristics(w.deviceId, HEARTuuid);
|
|
|
+ that.getCharacteristics(w.deviceId, HEARTuuid, HeartRateChaaracterUuid);
|
|
|
}, 3000);
|
|
|
},
|
|
|
fail: function(e) {
|
|
|
@@ -579,10 +600,10 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
// 获取服务的特征值
|
|
|
- getCharacteristics(deviceId, serviceId) {
|
|
|
+ getCharacteristics(deviceId, serviceId, serveUuid) {
|
|
|
let that = this;
|
|
|
- let chaaracterUuid = '00002A37-0000-1000-8000-00805F9B34FB';
|
|
|
let characteristicId = null;
|
|
|
+ let chaaracterUuid = serveUuid;
|
|
|
plus.bluetooth.getBLEDeviceCharacteristics({
|
|
|
deviceId: deviceId,
|
|
|
serviceId: serviceId,
|
|
|
@@ -613,35 +634,35 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
// 获取服务的特征值
|
|
|
- getBatteryCharacteristics(deviceId, serviceId) {
|
|
|
- let that = this;
|
|
|
- let chaaracterUuid = '00002A19-0000-1000-8000-00805F9B34FB';
|
|
|
- let characteristicId = null;
|
|
|
- that.readValue(deviceId, serviceId, chaaracterUuid);
|
|
|
- plus.bluetooth.getBLEDeviceCharacteristics({
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- success: function(e) {
|
|
|
- var characteristics = e.characteristics;
|
|
|
- that.Toast('获取心率带服务成功! ' + characteristics.length, 'success');
|
|
|
- plus.bluetooth.notifyBLECharacteristicValueChange({ //监听数据变化
|
|
|
- deviceId: deviceId,
|
|
|
- serviceId: serviceId,
|
|
|
- characteristicId: chaaracterUuid,
|
|
|
- success: function(e) {
|
|
|
- console.log('notifyBLECharacteristicValueChange' + JSON.stringify(e));
|
|
|
- },
|
|
|
- fail: function(e) {
|
|
|
- that.Toast('notifyBLECharacteristicValueChange失败! ' + JSON.stringify(e));
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- fail: function(e) {
|
|
|
- console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
|
- that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
+ // getBatteryCharacteristics(deviceId, serviceId) {
|
|
|
+ // let that = this;
|
|
|
+ // let chaaracterUuid = '00002A19-0000-1000-8000-00805F9B34FB';
|
|
|
+ // let characteristicId = null;
|
|
|
+ // that.readValue(deviceId, serviceId, chaaracterUuid);
|
|
|
+ // plus.bluetooth.getBLEDeviceCharacteristics({
|
|
|
+ // deviceId: deviceId,
|
|
|
+ // serviceId: serviceId,
|
|
|
+ // success: function(e) {
|
|
|
+ // var characteristics = e.characteristics;
|
|
|
+ // that.Toast('获取心率带服务成功! ' + characteristics.length, 'success');
|
|
|
+ // plus.bluetooth.notifyBLECharacteristicValueChange({ //监听数据变化
|
|
|
+ // deviceId: deviceId,
|
|
|
+ // serviceId: serviceId,
|
|
|
+ // characteristicId: chaaracterUuid,
|
|
|
+ // success: function(e) {
|
|
|
+ // console.log('notifyBLECharacteristicValueChange' + JSON.stringify(e));
|
|
|
+ // },
|
|
|
+ // fail: function(e) {
|
|
|
+ // that.Toast('notifyBLECharacteristicValueChange失败! ' + JSON.stringify(e));
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // fail: function(e) {
|
|
|
+ // console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
|
+ // that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // },
|
|
|
readValue(deviceId, serviceId, characteristicId) {
|
|
|
let that = this;
|
|
|
plus.bluetooth.readBLECharacteristicValue({
|
|
|
@@ -731,19 +752,17 @@ export default {
|
|
|
actLevel = actLevel > 100 ? 100 : actLevel < 0 ? 0 : actLevel;
|
|
|
this.activeLevel = parseInt(actLevel);
|
|
|
},
|
|
|
- // 持续时间
|
|
|
+ // 持续时间 单位为秒
|
|
|
calcHoldTime(curTime) {
|
|
|
let that = this;
|
|
|
- let res = 0;
|
|
|
+ let res = '';
|
|
|
if (this.begin) {
|
|
|
- res = parseInt(curTime.getTime() - this.begin.getTime()) / 1;
|
|
|
- // 上次上报时间
|
|
|
- // console.log('res' + res);
|
|
|
+ res = (curTime.getTime() - this.begin.getTime()) / (1000*60);
|
|
|
} else {
|
|
|
- res = 0;
|
|
|
+ res = 0.00;
|
|
|
}
|
|
|
that.begin = new Date();
|
|
|
- return parseInt(res)
|
|
|
+ return res
|
|
|
},
|
|
|
// 计算卡路里
|
|
|
calcCalorie(heartRate) {
|
|
|
@@ -758,13 +777,23 @@ export default {
|
|
|
|
|
|
let calorieNoVo2 = 0;
|
|
|
let curTime = that.calcHoldTime(new Date());
|
|
|
+ if (this.runMode == 'mock') {
|
|
|
+ // curTime = 2 / 60;
|
|
|
+ // curTime = 2;
|
|
|
+ curTime = 0.01666;//生产数据大概是每次1秒左右
|
|
|
+
|
|
|
+ }
|
|
|
// 男
|
|
|
if (that.sex == 1) {
|
|
|
- calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60000 * curTime;
|
|
|
+ // calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60000 * curTime;
|
|
|
+ calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) * curTime;
|
|
|
} else {
|
|
|
- calorieNoVo2 = ((-20.4022 + (0.4472 * heartRate) - (0.1263 * that.weight) + (0.074 * that.age)) / 4.184) / 60000 * curTime;
|
|
|
+ // calorieNoVo2 = ((-20.4022 + (0.4472 * heartRate) - (0.1263 * that.weight) + (0.074 * that.age)) / 4.184) / 60000 * curTime;
|
|
|
+ calorieNoVo2 = ((-20.4022 + (0.4472 * heartRate) - (0.1263 * that.weight) + (0.074 * that.age)) / 4.184) * curTime;
|
|
|
}
|
|
|
// 记录增量卡路里
|
|
|
+ console.log('Calories:' + calorieNoVo2);
|
|
|
+
|
|
|
that.addCalories = calorieNoVo2;
|
|
|
that.cal = that.cal + calorieNoVo2;
|
|
|
// console.log('heartRate:' + heartRate);
|
|
|
@@ -776,10 +805,11 @@ export default {
|
|
|
},
|
|
|
// 计算CK
|
|
|
calcCk(cal) {
|
|
|
+ // console.log('ck:' + cal / this.weight);
|
|
|
this.ck = parseFloat(cal / this.weight).toFixed(2);
|
|
|
},
|
|
|
// 计算运动卡路里
|
|
|
- calcSportCal(calorieNoVo2,curTime) {
|
|
|
+ calcSportCal(calorieNoVo2, curTime) {
|
|
|
let that = this;
|
|
|
let bmrMSjDaily = 0;
|
|
|
// 男
|
|
|
@@ -789,18 +819,28 @@ export default {
|
|
|
// 女
|
|
|
bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) - 161
|
|
|
}
|
|
|
- // 不为负值
|
|
|
- if (bmrMSjDaily < 0) {
|
|
|
- bmrMSjDaily = 0;
|
|
|
+
|
|
|
+ // console.log('bmrMSjDaily' + bmrMSjDaily);
|
|
|
+ // 不为负值,负值无计算意义
|
|
|
+ if (bmrMSjDaily <= 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 时长差值为0,计算无意义
|
|
|
+ if (curTime == 0) {
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
|
|
|
// let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
|
|
|
- let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / curTime);
|
|
|
+ let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * (curTime) );
|
|
|
+ console.log('calorieNoVo2Pure:' + calorieNoVo2Pure);
|
|
|
|
|
|
// 记录增量运动卡路里
|
|
|
that.addPureCalories = calorieNoVo2Pure;
|
|
|
- this.sportCal = this.sportCal + calorieNoVo2Pure;
|
|
|
+ if(calorieNoVo2Pure < 0){
|
|
|
+ calorieNoVo2Pure = 0;
|
|
|
+ }
|
|
|
+ this.sportCal = this.sportCal + parseFloat(calorieNoVo2Pure);
|
|
|
},
|
|
|
// 绘制心电图
|
|
|
DrawHeartLine(heartLine, dataLabels) {
|