mirror of https://github.com/espruino/BangleApps
parent
d9e080e7b8
commit
1e0b07b563
|
@ -104,19 +104,11 @@ function handleStepGoalNotification() {
|
|||
const now = new Date(Date.now()).toISOString().split('T')[0]; // yyyy-mm-dd
|
||||
if (!settings.stepGoalNotificationDate || settings.stepGoalNotificationDate < now) { // notification not yet shown today?
|
||||
Bangle.buzz(200, 0.5);
|
||||
if (process.env.BOARD == "BANGLEJS2") {
|
||||
require("notify").show({
|
||||
title : /*LANG*/ settings.stepGoal + " steps",
|
||||
body : /*LANG*/ "Step goal reached!",
|
||||
src : "health",
|
||||
icon : atob(
|
||||
"MDCBAAAAAAAAAAAAAAAAAAA/+D/4AAB//H/8AAB//H/8AAB//v/4AAA8H/B4AAA+H/D4AAAeD+DwAAAfD+HwAAAPB8HgAAAPh8PgAAAHg8PAAAAHw8PAAAADw+eAAAAD4eeAAAAB4f+AAAAB8P8AAAAA//8AAAAA//4AAAAA//8AAAAB//+AAAAD+B/AAAAH4AfgAAAPgAHwAAAPAADwAAAfAAD4AAAeAAB4AAA+AAB8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA+AAB4AAAeAAB4AAAfAAD4AAAPAADwAAAPgAHwAAAH4AfgAAAD+B/AAAAB//+AAAAA//8AAAAAP/wAAAAAD+AAAAAAAAAAAAAAAAAAAA==")
|
||||
title : /*LANG*/"8000 steps",
|
||||
body : /*LANG*/ "You reached your step goal!",
|
||||
icon : atob("DAyBABmD6BaBMAsA8BCBCBCBCA8AAA==")
|
||||
});
|
||||
} else {
|
||||
E.showPrompt(/*LANG*/ "You reached your daily goal of " + settings.stepGoal + " steps!",
|
||||
{title : /*LANG*/ "Step goal reached!", buttons : {"Ok" : 1}}).then(function(v) { load(); });
|
||||
}
|
||||
|
||||
settings.stepGoalNotificationDate = now;
|
||||
require("Storage").writeJSON("health.json", settings);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
function m(){var a=require("Storage").readJSON("health.json",1)||{},e=Bangle.getHealthStatus("day").steps;if(a.stepGoalNotification&&0<a.stepGoal&&e>=a.stepGoal&&(e=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDate<e)){Bangle.buzz(200,.5);if("BANGLEJS2"==process.env.BOARD){var b=atob("MDCBAAAAAAAAAAAAAAAAAAA/+D/4AAB//H/8AAB//H/8AAB//v/4AAA8H/B4AAA+H/D4AAAeD+DwAAAfD+HwAAAPB8HgAAAPh8PgAAAHg8PAAAAHw8PAAAADw+eAAAAD4eeAAAAB4f+AAAAB8P8AAAAA//8AAAAA//4AAAAA//8AAAAB//+AAAAD+B/AAAAH4AfgAAAPgAHwAAAPAADwAAAfAAD4AAAeAAB4AAA+AAB8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA8AAA+AAB4AAAeAAB4AAAfAAD4AAAPAADwAAAPgAHwAAAH4AfgAAAD+B/AAAAB//+AAAAA//8AAAAAP/wAAAAAD+AAAAAAAAAAAAAAAAAAAA=="),
|
||||
c=Graphics.createArrayBuffer(g.getWidth(),g.getHeight(),1,{msb:!0});c.drawImage(b,10,10);c.setFont("Vector:18").setFontAlign(0,0,0);c.drawString(a.stepGoal+" steps",g.getWidth()/2+24,34);c.drawString("Step goal reached!",g.getWidth()/2,g.getHeight()/2);Bangle.setLCDOverlay(c,0,0);setWatch(function(){Bangle.setLCDOverlay()},BTN)}else E.showPrompt("You reached your daily goal of "+a.stepGoal+" steps!",{title:"Step goal reached!",buttons:{Ok:1}}).then(function(h){load()});a.stepGoalNotificationDate=
|
||||
e;require("Storage").writeJSON("health.json",a)}}(function(){var a=0|(require("Storage").readJSON("health.json",1)||{}).hrm;if(1==a||2==a){var e=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){return Bangle.setHRMPower(0,"health")},6E4*a);if(1==a)for(var b=1;2>=b;b++)setTimeout(function(){Bangle.setHRMPower(1,"health");setTimeout(function(){Bangle.setHRMPower(0,"health")},2E5*b+6E4)},2E5*b)};Bangle.on("health",e);Bangle.on("HRM",function(b){80<b.confidence&&Bangle.setHRMPower(0,"health")});
|
||||
Bangle.getHealthStatus().bpmConfidence||e()}else Bangle.setHRMPower(0!=a,"health")})();Bangle.on("health",function(a){function e(d){return String.fromCharCode(d.steps>>8,d.steps&255,d.bpm,Math.min(d.movement/8,255))}var b=new Date(Date.now()-59E4);a&&0<a.steps&&m();var c=function(d){return 145*(d.getDate()-1)+6*d.getHours()+(0|6*d.getMinutes()/60)}(b);b=function(d){return"health-"+d.getFullYear()+"-"+(d.getMonth()+1)+".raw"}(b);var h=require("Storage").read(b);if(h){var f=h.substr(8+4*c,4);if("\u00ff\u00ff\u00ff\u00ff"!=
|
||||
f){print("HEALTH ERR: Already written!");return}}else require("Storage").write(b,"HEALTH1\x00",0,17988);var k=8+4*c;require("Storage").write(b,e(a),k,17988);if(143==c%145)if(c=k+4,"\u00ff\u00ff\u00ff\u00ff"!=h.substr(c,4))print("HEALTH ERR: Daily summary already written!");else{a={steps:0,bpm:0,movement:0,movCnt:0,bpmCnt:0};for(var l=0;144>l;l++)f=h.substr(k,4),"\u00ff\u00ff\u00ff\u00ff"!=f&&(a.steps+=(f.charCodeAt(0)<<8)+f.charCodeAt(1),a.movement+=f.charCodeAt(2),a.movCnt++,f=f.charCodeAt(2),a.bpm+=
|
||||
f,f&&a.bpmCnt++),k-=4;a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt);require("Storage").write(b,e(a),c,17988)}})
|
||||
function l(){var a=require("Storage").readJSON("health.json",1)||{},d=Bangle.getHealthStatus("day").steps;a.stepGoalNotification&&0<a.stepGoal&&d>=a.stepGoal&&(d=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDate<d)&&(Bangle.buzz(200,.5),require("notify").show({title:"8000 steps",body:"You reached your step goal!",icon:atob("DAyBABmD6BaBMAsA8BCBCBCBCA8AAA==")}),a.stepGoalNotificationDate=d,require("Storage").writeJSON("health.json",
|
||||
a))}(function(){var a=0|(require("Storage").readJSON("health.json",1)||{}).hrm;if(1==a||2==a){var d=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){return Bangle.setHRMPower(0,"health")},6E4*a);if(1==a)for(var b=1;2>=b;b++)setTimeout(function(){Bangle.setHRMPower(1,"health");setTimeout(function(){Bangle.setHRMPower(0,"health")},2E5*b+6E4)},2E5*b)};Bangle.on("health",d);Bangle.on("HRM",function(b){80<b.confidence&&Bangle.setHRMPower(0,"health")});Bangle.getHealthStatus().bpmConfidence||
|
||||
d()}else Bangle.setHRMPower(0!=a,"health")})();Bangle.on("health",function(a){function d(c){return String.fromCharCode(c.steps>>8,c.steps&255,c.bpm,Math.min(c.movement/8,255))}var b=new Date(Date.now()-59E4);a&&0<a.steps&&l();var f=function(c){return 145*(c.getDate()-1)+6*c.getHours()+(0|6*c.getMinutes()/60)}(b);b=function(c){return"health-"+c.getFullYear()+"-"+(c.getMonth()+1)+".raw"}(b);var g=require("Storage").read(b);if(g){var e=g.substr(8+4*f,4);if("\u00ff\u00ff\u00ff\u00ff"!=e){print("HEALTH ERR: Already written!");
|
||||
return}}else require("Storage").write(b,"HEALTH1\x00",0,17988);var h=8+4*f;require("Storage").write(b,d(a),h,17988);if(143==f%145)if(f=h+4,"\u00ff\u00ff\u00ff\u00ff"!=g.substr(f,4))print("HEALTH ERR: Daily summary already written!");else{a={steps:0,bpm:0,movement:0,movCnt:0,bpmCnt:0};for(var k=0;144>k;k++)e=g.substr(h,4),"\u00ff\u00ff\u00ff\u00ff"!=e&&(a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1),a.movement+=e.charCodeAt(2),a.movCnt++,e=e.charCodeAt(2),a.bpm+=e,e&&a.bpmCnt++),h-=4;a.bpmCnt&&(a.bpm/=
|
||||
a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt);require("Storage").write(b,d(a),f,17988)}})
|
|
@ -16,5 +16,6 @@
|
|||
{"name":"health","url":"lib.min.js"},
|
||||
{"name":"health.settings.js","url":"settings.js"}
|
||||
],
|
||||
"data": [{"name":"health.json"}]
|
||||
"data": [{"name":"health.json"}],
|
||||
"dependencies": {"notify":"type"},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue