gadgetbridge: 0.18: Added reporting of step count and HRM (new Gadgetbridges can now log this)
parent
322880510e
commit
9a3b203429
|
|
@ -139,7 +139,7 @@
|
||||||
{ "id": "gbridge",
|
{ "id": "gbridge",
|
||||||
"name": "Gadgetbridge",
|
"name": "Gadgetbridge",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"version":"0.17",
|
"version":"0.18",
|
||||||
"description": "The default notification handler for Gadgetbridge notifications from Android",
|
"description": "The default notification handler for Gadgetbridge notifications from Android",
|
||||||
"tags": "tool,system,android,widget",
|
"tags": "tool,system,android,widget",
|
||||||
"type":"widget",
|
"type":"widget",
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,4 @@
|
||||||
0.16: Handle dismissing notifications on the phone
|
0.16: Handle dismissing notifications on the phone
|
||||||
Nicer display of alarm clock notifications
|
Nicer display of alarm clock notifications
|
||||||
0.17: Modified music notification for updated 'notify' library
|
0.17: Modified music notification for updated 'notify' library
|
||||||
|
0.18: Added reporting of step count and HRM (new Gadgetbridges can now log this)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@
|
||||||
onchange: setIcon
|
onchange: setIcon
|
||||||
},
|
},
|
||||||
"Find Phone" : function() { E.showMenu(findPhone); },
|
"Find Phone" : function() { E.showMenu(findPhone); },
|
||||||
|
"Record HRM" : {
|
||||||
|
value: settings().hrm,
|
||||||
|
format: v => v?"Yes":"No",
|
||||||
|
onchange: v => updateSetting('hrm', v)
|
||||||
|
},
|
||||||
"< Back" : back,
|
"< Back" : back,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
(() => {
|
(() => {
|
||||||
|
// Music handling
|
||||||
const state = {
|
const state = {
|
||||||
music: "stop",
|
music: "stop",
|
||||||
|
|
||||||
|
|
@ -10,13 +11,17 @@
|
||||||
|
|
||||||
scrollPos: 0
|
scrollPos: 0
|
||||||
};
|
};
|
||||||
|
// activity reporting
|
||||||
|
var currentSteps = 0, lastSentSteps=0;
|
||||||
|
var activityInterval;
|
||||||
|
var hrmTimeout;
|
||||||
|
|
||||||
function settings() {
|
function settings() {
|
||||||
let settings = require('Storage').readJSON("gbridge.json", true) || {};
|
let settings = require('Storage').readJSON("gbridge.json", true) || {};
|
||||||
if (!("showIcon" in settings)) {
|
if (!("showIcon" in settings)) {
|
||||||
settings.showIcon = true;
|
settings.showIcon = true;
|
||||||
}
|
}
|
||||||
return settings
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gbSend(message) {
|
function gbSend(message) {
|
||||||
|
|
@ -144,6 +149,36 @@
|
||||||
},2000);
|
},2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleActivityEvent(event) {
|
||||||
|
// TODO: `t:"act", hrm:bool, stp:bool, int:int` - Enable realtime step counting, realtime heart rate. 'int' is the report interval in seconds
|
||||||
|
// add live view,
|
||||||
|
var s = settings();
|
||||||
|
if (s.activityInterval===undefined ||
|
||||||
|
s.activityInterval<30)
|
||||||
|
s.activityInterval = 30*60; // 3 minutes default
|
||||||
|
if (event.int) {
|
||||||
|
if (event.int<30) event.int = 30; // min 30 secs
|
||||||
|
s.activityInterval = event.int;
|
||||||
|
require('Storage').write("gbridge.json", s);
|
||||||
|
}
|
||||||
|
var interval = s.activityInterval;
|
||||||
|
if (activityInterval)
|
||||||
|
clearInterval(activityInterval);
|
||||||
|
activityInterval = undefined;
|
||||||
|
Bangle.setHRMPower(1);
|
||||||
|
if (event.hrm || event.stp) {
|
||||||
|
// if realtime reporting, leave HRM on and use that to trigger events
|
||||||
|
hrmTimeout = undefined;
|
||||||
|
} else {
|
||||||
|
// else trigger it manually every so often
|
||||||
|
hrmTimeout = 5;
|
||||||
|
activityInterval = setInterval(function() {
|
||||||
|
hrmTimeout = 5;
|
||||||
|
Bangle.setHRMPower(1);
|
||||||
|
}, interval*1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var _GB = global.GB;
|
var _GB = global.GB;
|
||||||
global.GB = (event) => {
|
global.GB = (event) => {
|
||||||
switch (event.t) {
|
switch (event.t) {
|
||||||
|
|
@ -163,6 +198,9 @@
|
||||||
case "find":
|
case "find":
|
||||||
handleFindEvent(event);
|
handleFindEvent(event);
|
||||||
break;
|
break;
|
||||||
|
case "act":
|
||||||
|
handleActivityEvent(event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(_GB)setTimeout(_GB,0,event);
|
if(_GB)setTimeout(_GB,0,event);
|
||||||
};
|
};
|
||||||
|
|
@ -201,14 +239,50 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WIDGETS["gbridgew"] = {area: "tl", width: 24, draw: draw, reload: reload};
|
|
||||||
reload();
|
|
||||||
|
|
||||||
function sendBattery() {
|
function sendBattery() {
|
||||||
gbSend({ t: "status", bat: E.getBattery() });
|
gbSend({ t: "status", bat: E.getBattery() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turn on HRM and get a reading
|
||||||
|
function getHRM(callback) {
|
||||||
|
if (settings().hrm) {
|
||||||
|
Bangle.setHRMPower(1);
|
||||||
|
var timeout = 5;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
callback(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a summary of activity to Gadgetbridge
|
||||||
|
function sendActivity(hrm) {
|
||||||
|
var steps = currentSteps - lastSentSteps;
|
||||||
|
lastSentSteps = 0;
|
||||||
|
gbSend({ t: "act", stp: steps, hrm:hrm });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Battery monitor
|
||||||
NRF.on("connect", () => setTimeout(sendBattery, 2000));
|
NRF.on("connect", () => setTimeout(sendBattery, 2000));
|
||||||
setInterval(sendBattery, 10*60*1000);
|
setInterval(sendBattery, 10*60*1000);
|
||||||
sendBattery();
|
sendBattery();
|
||||||
|
// Activity monitor
|
||||||
|
Bangle.on("step", s => {
|
||||||
|
if (!lastSentSteps)
|
||||||
|
lastSentSteps = s-1;
|
||||||
|
currentSteps = s;
|
||||||
|
});
|
||||||
|
Bangle.on('HRM',function(hrm) {
|
||||||
|
var ok = hrm.confidence>80;
|
||||||
|
if (hrmTimeout!==undefined) hrmTimeout--;
|
||||||
|
if (ok || hrmTimeout<=0) {
|
||||||
|
if (hrmTimeout!==undefined)
|
||||||
|
Bangle.setHRMPower(0);
|
||||||
|
sendActivity(hrm.confidence>20 ? hrm.bpm : -1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handleActivityEvent({}); // kicks off activity reporting
|
||||||
|
|
||||||
|
// Finally add widget
|
||||||
|
WIDGETS["gbridgew"] = {area: "tl", width: 24, draw: draw, reload: reload};
|
||||||
|
reload();
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue