Update app.js

master
Andy Smy 2025-05-12 23:52:55 +01:00 committed by GitHub
parent 3e66382d2b
commit 2c745e5fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 10 deletions

View File

@ -30,7 +30,7 @@ var battery = 0;
var heartRate = '';
var heartRateEventSeconds = 0;
var HRM = false;
var lastSteps = stepCountOffset;
var lastSteps = STEP_COUNT_OFFSET;
function toggleHRM() {
if(HRM) {
@ -44,6 +44,7 @@ function toggleHRM() {
}
function getBattery() {
// calculate last 10 moving average %
batteryPercents.push(E.getBattery());
if(batteryPercents.length > 10) batteryPercents.shift();
return Math.round(batteryPercents.reduce((avg,e,i,arr)=>avg+e/arr.length,0));
@ -55,17 +56,13 @@ function updateHeartRate(h) {
heartRate = h.bpm || 0;
if(heartRate >= HEART_RATE_LIMIT) {
heartRateEventSeconds++;
if(heartRateEventSeconds==10) {
var timeSig = new Date();
addLog(timeSig, over, counter, "Heart Rate", ">" + HEART_RATE_LIMIT);
if(heartRateEventSeconds==10)
addLog((new Date()), over, counter, "Heart Rate", ">" + HEART_RATE_LIMIT);
}
}
if(heartRateEventSeconds > 10) {
if(heartRate < HEART_RATE_LIMIT) {
if(heartRateEventSeconds > 10
&& heartRate < HEART_RATE_LIMIT)
heartRateEventSeconds = -10;
}
}
}
// write events to storage (csv, persistent)
// and memory (can be truncated while running)