1
0
Fork 0

Merge branch 'espruino:master' into master

master
Andrew Gregory 2021-11-02 12:48:13 +08:00 committed by GitHub
commit 73f9a831ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -49,10 +49,10 @@
{
"id": "health",
"name": "Health Tracking",
"version": "0.04",
"version": "0.05",
"description": "Logs health data and provides an app to view it (BETA - requires firmware 2v11)",
"icon": "app.png",
"tags": "tool,system",
"tags": "tool,system,health",
"supports": ["BANGLEJS","BANGLEJS2"],
"readme": "README.md",
"storage": [

View File

@ -3,3 +3,4 @@
0.03: Settings to turn HRM on
0.04: Add HRM graph view
Don't restart HRM when changing apps if we've already got a good BPM value
0.05: Fix daily summary calculation

View File

@ -55,28 +55,29 @@ Bangle.on("health", health => {
}
var recordPos = DB_HEADER_LEN+(rec*DB_RECORD_LEN);
require("Storage").write(fn, getRecordData(health), recordPos, DB_FILE_LEN);
if (rec%DB_RECORDS_PER_DAY != DB_RECORDS_PER_DAY-1) return;
if (rec%DB_RECORDS_PER_DAY != DB_RECORDS_PER_DAY-2) return;
// we're at the end of the day. Read in all of the data for the day and sum it up
var sumPos = recordPos + DB_RECORD_LEN; // record after the current one is the sum
if (f.substr(sumPos, DB_RECORD_LEN)!="\xFF\xFF\xFF\xFF") {
print("HEALTH ERR: Daily summary already written!");
return;
}
health = { steps:0, bpm:0, movement:0, records:0};
health = { steps:0, bpm:0, movement:0, movCnt:0, bpmCnt:0};
var records = DB_RECORDS_PER_HR*24;
for (var i=0;i<records;i++) {
var dt = f.substr(recordPos, DB_RECORD_LEN);
if (dt!="\xFF\xFF\xFF\xFF") {
health.records++;
health.steps += (dt.charCodeAt(1)<<8)+dt.charCodeAt(1);
health.bpm += dt.charCodeAt(2);
health.steps += (dt.charCodeAt(0)<<8)+dt.charCodeAt(1);
health.movement += dt.charCodeAt(2);
health.movCnt++;
var bpm = dt.charCodeAt(2);
health.bpm += bpm;
if (bpm) health.bpmCnt++;
}
recordPos -= DB_RECORD_LEN;
}
if (health.records) {
health.bpm /= health.records;
health.movement /= health.records;
}
if (health.bpmCnt)
health.bpm /= health.bpmCnt;
if (health.movCnt)
require("Storage").write(fn, getRecordData(health), sumPos, DB_FILE_LEN);
});